http组件在WAS中给出错误:NoSuchFieldError:INSTANCE

时间:2016-08-26 10:54:13

标签: java spring websphere

我正在使用springrest模板发布我的xml请求并获得响应我检查了tomcat它运行得很好但是在部署之后它会显示以下异常。

   java.lang.NoSuchFieldError: INSTANCE

at java.lang.J9VMInternals.initialize(J9VMInternals.java:175)
Caused by: java.lang.NoSuchFieldError: org/apache/http/conn/ssl/AllowAllHostnameVerifier.INSTANCE
Caused by: java.lang.NoClassDefFoundError: org.apache.http.conn.ssl.SSLConnectionSocketFactory (initialization failure)

我搜索到它是jar不兼容的。但是没有相同的jar有不同版本我检查了我的代码它在这里给我错误

HttpClientBuilder clientBuilder=HttpClientBuilder.create();
         HttpClient httpClient=clientBuilder.setProxy(myProxy).setDefaultCredentialsProvider(credentialsProvider).disableCookieManagement().build();
         HttpComponentsClientHttpRequestFactory httpComponentFactory=new HttpComponentsClientHttpRequestFactory();

我正在使用httpcomponent版本4.4。请帮帮我

1 个答案:

答案 0 :(得分:0)

我没有得到正确的解决方案。以前我们使用的是httpComponents 4.4版。它正在创建问题中提到的问题。之后我们使用了httpComponents 3.1版。但它与resttemplate不兼容。所以我们也删除它。最后我们用httpClient 3.1版本编写了我们的代码

                            AuthScope  auth=new AuthScope(testAuthData.getHost(),Integer.parseInt(testAuthData.getPort()));



                            ReportData report=new ReportData();

                            report.setEndPoint(input.getEndPoint());
                            report.setRequest(xml);

                                                             Credentials defaultProxyCreds = new UsernamePasswordCredentials(
                                                            testAuthData.getUsername(), testAuthData.getPassword());

                            HttpClient httpClient =  new HttpClient();

                            httpClient.getHostConfiguration().setProxy(testAuthData.getHost(),Integer.parseInt(testAuthData.getPort()));
                            httpClient.getState().setProxyCredentials(auth,
                                                            defaultProxyCreds);








                            PostMethod post = new PostMethod(input.getEndPoint());

                                               post.addRequestHeader("header1", "header1Value");
                                                                                      post.setRequestEntity(new StringRequestEntity(xml, "application/xml", null));
                            int responseCode = httpClient.executeMethod(post);
                            //httpClient.ex
            byte[] resp=post.getResponseBody();

            String s = new String(resp);
            System.out.println("response:"+s);
            report.setResponse(s);
   System.out.println("responseCode:"+responseCode);
 Header header=  post.getResponseHeader("header1");