在weblogic容器中使用Spring RestTemplate的EOF异常

时间:2017-07-19 22:12:19

标签: spring spring-boot resttemplate

我的服务中出现以下EOF错误。 它是一个在weblogic服务器中部署为war的spring boot应用程序。

org.springframework.web.client.ResourceAccessException: I/O error on PUT request for "http://*****/update: Response had end of stream after 0 bytes; nested exception is java.io.EOFException: Response had end of stream after 0 bytes
 at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:633)
 at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:580)
 at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:498)
 at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
 at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
 at org.springframework.aop.interceptor.AsyncExecutionInterceptor$1.call(AsyncExecutionInterceptor.java:115)
 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
 at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.EOFException: Response had end of stream after 0 bytes
 at weblogic.net.http.MessageHeader.isHTTP(MessageHeader.java:312)
 at weblogic.net.http.MessageHeader.parseHeader(MessageHeader.java:232)
 at weblogic.net.http.HttpClient.parseHTTP(HttpClient.java:554)
 at weblogic.net.http.HttpURLConnection.getInputStream(HttpURLConnection.java:688)
 at weblogic.net.http.SOAPHttpURLConnection.getInputStream(SOAPHttpURLConnection.java:41)
 at weblogic.net.http.HttpURLConnection.getResponseCode(HttpURLConnection.java:1545)
 at org.springframework.http.client.SimpleClientHttpResponse.getRawStatusCode(SimpleClientHttpResponse.java:52)
 at org.springframework.http.client.AbstractClientHttpResponse.getStatusCode(AbstractClientHttpResponse.java:33)
 at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:655)
 at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:620)
 ... 10 more

blo g描述了我所看到的。但我使用的是RestTemplate,它应该是默认的HttpClientFactory,而不是weblogic。有人可以解释为什么以及我应该做什么修复?

由于

1 个答案:

答案 0 :(得分:1)

我发布了答案,因为在遇到同样的问题时,它会帮助其他人。

通过在restTemplate上显式设置HttpClientFactory,我能够摆脱这个错误。我认为默认情况下RestTemplate使用HttpClient。我无法弄清楚为什么我需要设置它。但这有助于解决。

@Bean
public RestTemplate restTemplate(){
    HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
    RestTemplate template = new RestTemplate(factory);
    template.setErrorHandler(new RestResponseHandler());
    return template;
    }

在我之前

   @Bean
    public RestTemplate restTemplate(){
    return new RestTemplate();
    }