i am quite new here. I am developing a java program as rest client by using jersy. My code is running fine in Eclipse. but when i create an executable jar that shows the following error :
com.sun.jersey.api.client.ClientHandlerException: A message body reader for Java class java.lang.String, and Java type class java.lang.String, and MIME media type application/json was not found
My exact code is :
String url = ConfigMessages.getString("url")+"ArWorkSchedular/Data";
try{
TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager(){
public X509Certificate[] getAcceptedIssuers(){return null;}
public void checkClientTrusted(X509Certificate[] certs, String authType){}
public void checkServerTrusted(X509Certificate[] certs, String authType){}
}};
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String arg0, SSLSession arg1) {
// TODO Auto-generated method stub
return true;
}
});
} catch (Exception e) {
;
}
Client client = Client.create();
WebResource webResource = client.resource(url);
ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON).header("username", "UNAME").header("password", "PASS").post(ClientResponse.class);
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus());
}
String output = response.getEntity(String.class);
I think Error occurred at the line to Parse the response to String. String output = response.getEntity(String.class);
All helps will be appreciable