我在这里很新。我正在使用jersy开发一个java程序作为rest客户端。我的代码在Eclipse中运行良好。但是当我创建一个显示以下错误的可执行jar:
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
我的确切代码是:
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);
我认为在解析对String的响应的行发生了错误。 String output = response.getEntity(String.class);
所有帮助都会很明显