Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timeout configuration for spring webservices with RestTemplate

I would like to configure a timeout on the client side for spring webservices using RestTemplate. I tried the following configuration :

<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<constructor-arg>
    <bean class="org.springframework.http.client.CommonsClientHttpRequestFactory">
    <property name="readTimeout" value="10000" />
    </bean>
</constructor-arg>
    <property name="messageConverters">
    <list>
    <ref bean="stringHttpMessageConverter" />
    <ref bean="marshallingHttpMessageConverter" />
    </list>
    </property>
</bean>

But I have a NoClassDefFoundError when I start my tomcat :

06 févr. 2012 10:43:43,113 [ERROR,ContextLoader] Context initialization failed
java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpMethodBase

However I have included commons-httpclient in my pom.xml :

    <dependency>
        <groupId>commons-httpclient</groupId>
        <artifactId>commons-httpclient</artifactId>
        <version>3.1</version>
    </dependency

Any idea of how I could do/fix that?

Thanks in advance !

like image 974
jsebfranck Avatar asked Dec 12 '22 05:12

jsebfranck


1 Answers

Snicolas answer almost worked for me, only had to change the cast Class:

RestTemplate restTemplate = new RestTemplate();    
((SimpleClientHttpRequestFactory)restTemplate.getRequestFactory()).setReadTimeout(1000*30);

Also you can set the connect timeOut:

((SimpleClientHttpRequestFactory)restTemplate.getRequestFactory()).setConnectTimeout(1000*30);
like image 167
Eduardo Mayer Avatar answered Jan 14 '23 13:01

Eduardo Mayer