Friday, 13 February 2015

Date Calculation : Java to get date before or after some days from today

Calendar cNow = Calendar.getInstance();
Date dNow = cNow.getTime();          
cNow.add(Calendar.DATE, Day);           
Date beforeDate = cNow.getTime();           
SimpleDateFormat format = 
         new SimpleDateFormat("MMM dd, yyyy hh:mm:ss a");
           
String dateNow = format.format(dNow);          
String dayBefore = format.format(beforeDate);          

System.out.println(dateNow);         
System.out.println(dayBefore);

________________________________________________
Day is a integer value either in + or - base on requirement

- Day will give you past date

+ Day will give you future date   

Thursday, 12 February 2015

Call Rest service from JAVA Core, Post method

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;

public class SubscriberService {

       public void sendPost() throws Exception {

              try {
                      DefaultHttpClient httpClient = new DefaultHttpClient();
                      HttpPost postRequest = new HttpPost("api url");

                      StringEntity input = new StringEntity(
                                    "{"
                                    + "\"object\":\"value\""
                                    + "}");
                      input.setContentType("application/json");
                      postRequest.setEntity(input);
                      HttpResponse response = httpClient.execute(postRequest);
                      BufferedReader br = new BufferedReader(new InputStreamReader(
                                    (response.getEntity().getContent())));

                      String output;
                      System.out.println("Output from Server .... \n");
                      while ((output = br.readLine()) != null) {
                             System.out.println(output);
                      }
                      httpClient.getConnectionManager().shutdown();
              } catch (MalformedURLException e) {
                      e.printStackTrace();
              } catch (IOException e) {
                      e.printStackTrace();
              }
       }

}

Wednesday, 4 February 2015

Could not load file or assembly or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

I was able to fix this error by 

  1. finding the assembly DLL in Windows Explorer, 
  2. right clicking,
  3. choosing Properties
  4. pressing the "unblock" button. 

Now Try To Publish it will work