2017-07-19 1757 views
0

我在我們的服務中收到以下EOF錯誤。 這是一個在weblogic服務器中部署爲war的spring引導應用程序。在weblogic容器中使用Spring RestTemplate的EOF異常

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。有人可以解釋爲什麼,我應該怎麼做?

謝謝

回答

0

我發佈的答案,因爲它會幫助其他面臨同樣問題時。

通過在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(); 
    } 
相關問題