2

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

Marvel John
  • 193
  • 1
  • 3
  • 14
  • 1
    1) `catch (Exception e) { ; } == Bad news bears`. Emtpy catch blocks are never a good idea. 2) Are all the jars that you see in Eclipse, as dependencies, added to the classpath when you are running the jar? – Paul Samsotha Nov 17 '14 at 14:29
  • @peeskillet , thanks for your help. i have written the code e.printStackTrace() in catch block. but i missed that code when i copy it. i done what you said, but still the same error occur. Please help me again if you have any better option than that. – Marvel John Nov 17 '14 at 14:44
  • 1
    You are missing message body readers. If it worked in Eclipses, then the required jars that you had in Eclispe, you do not have on the classpath when running your jar. – Paul Samsotha Nov 17 '14 at 14:53

0 Answers0