2014-01-14 10 views
0

게시물 요청을 보내기 위해 RestTemplate을 사용하고 있습니다. 이런 식으로 뭔가 :java.net.SocketException : RestTemplate이 잘못된 인수

restTemplate.postForObject(url, fetchImageDataRequest, SimpleImageHolder[].class); 

나는 그런 restTemplate을 만들 때 :

restTemplate = new RestTemplate(); 
MappingJacksonHttpMessageConverter converter = new MappingJacksonHttpMessageConverter(); 
restTemplate.getMessageConverters().add(converter); 

모든 것이 잘 작동합니다. 나는이 같은 spring.xml에서 생성 정의 RestTemplate 사용할 때 :

<bean id="reHttpConnectionManager" class="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager"> 
    <property name="params"> 
    <bean class="org.apache.commons.httpclient.params.HttpConnectionManagerParams"> 
     <property name="soTimeout"     value="30000"/> 
     <property name="connectionTimeout"   value="30000"/> 
     <property name="maxTotalConnections"   value="300"/> 
     <property name="defaultMaxConnectionsPerHost" value="50"/> 
    </bean> 
    </property> 
</bean> 

<bean id="reRequestFactory" class="org.springframework.http.client.CommonsClientHttpRequestFactory"> 
    <property name="readTimeout" value="3000" /> 
    <constructor-arg> 
    <bean id="httpClient" class="org.apache.commons.httpclient.HttpClient"> 
     <constructor-arg> 
     <bean class="org.apache.commons.httpclient.params.HttpClientParams" /> 
     </constructor-arg> 
     <property name="httpConnectionManager" ref="reHttpConnectionManager" /> 
     <property name="state"> 
     <bean class="org.apache.commons.httpclient.HttpState" /> 
     </property> 
    </bean> 
    </constructor-arg> 
</bean> 

<bean id="restTemplate" class="org.springframework.web.client.RestTemplate"> 
    <constructor-arg ref="reRequestFactory" /> 
</bean> 

을 나는 java.net.SocketException: Invalid argument 예외를 얻을. 이 문제를 파악하려고합니다.

전체의 stacke 추적 :

org.springframework.web.client.ResourceAccessException: I/O error: Invalid argument; nested exception is java.net.SocketException: Invalid argument 
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:453) 
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401) 
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:279) 
+0

전체 스택 추적을 게시하십시오. –

+0

@SotiriosDelimanolis - 추가되었습니다. 감사! – Avi

답변

0

내가 문제가했지만, 난 그냥 빈 httpClient의 생성자에서 HttpParams 콩을 제거하고 완전히 HttpState을 제거하고 지금은 어떤 작품 찾을 수 없습니다. 새 XML은 다음과 같습니다.

<bean id="reHttpConnectionManager" class="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager"> 
    <property name="params"> 
    <bean class="org.apache.commons.httpclient.params.HttpConnectionManagerParams"> 
     <property name="soTimeout"     value="30000"/> 
     <property name="connectionTimeout"   value="30000"/> 
     <property name="maxTotalConnections"   value="300"/> 
     <property name="defaultMaxConnectionsPerHost" value="50"/> 
    </bean> 
    </property> 
</bean> 

<bean id="reRequestFactory" class="org.springframework.http.client.CommonsClientHttpRequestFactory"> 
    <property name="readTimeout" value="3000" /> 
    <constructor-arg> 
    <bean id="httpClient" class="org.apache.commons.httpclient.HttpClient"> 
     <property name="httpConnectionManager" ref="reHttpConnectionManager" /> 
    </bean> 
    </constructor-arg> 
</bean> 

<bean id="restTemplate" class="org.springframework.web.client.RestTemplate"> 
    <constructor-arg ref="reRequestFactory" /> 
</bean>