title: Spring RestTemplate slow response time
body: <p>While trying to POST object using RestTemplate on Spring 3.2 I got average response time 8 seconds</p>
  
  <p>using curl </p>
  
  <pre><code>time curl -X POST -H "Content-Type: application/xml" -T request.xml https://x.y.com:20000/rest
  </code></pre>
  
  <p>I'm getting approximately 4 sec average time. I can't understand why.</p>
  
  <p>My configuration:</p>
  
  <pre><code>&lt;bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"&gt;
          &lt;property name="classesToBeBound"&gt;
              &lt;list&gt;
                  &lt;value&gt;x.y.z.Request&lt;/value&gt;
                  &lt;value&gt;x.y.z.Response&lt;/value&gt;
                  &lt;value&gt;x.y.z.AnotherRequest&lt;/value&gt;
                  &lt;value&gt;x.y.z.AnotherResponse&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
  
  &lt;bean id="restTemplate" class="org.springframework.web.client.RestTemplate"
          scope="prototype"&gt;
          &lt;constructor-arg&gt;
              &lt;bean
                  class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory"&gt;
                  &lt;property name="readTimeout" value="${application.urlReadTimeout}" /&gt;
                  &lt;property name="connectTimeout" value="${application.urlConnectionTimeout}" /&gt;
              &lt;/bean&gt;
          &lt;/constructor-arg&gt;
  
          &lt;property name="messageConverters"&gt;
              &lt;list&gt;
                  &lt;bean
                      class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"&gt;
                      &lt;property name="marshaller" ref="jaxb2Marshaller" /&gt;
                      &lt;property name="unmarshaller" ref="jaxb2Marshaller" /&gt;
                  &lt;/bean&gt;
                  &lt;bean class="org.springframework.http.converter.FormHttpMessageConverter" /&gt;
                  &lt;bean
                      class="org.springframework.http.converter.StringHttpMessageConverter" /&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>Then I simple autowire it: </p>
  
  <pre><code>    @Autowired
      RestTemplate restTemplate;
  
  public Response getXml(Request request){
  
      Response response = restTemplate.postForObject(httpUrl,request, Response.class);
  }
  </code></pre>
  
  <p>P.S: as an alternative I tried to parse Request/Response object using JaxB and an send it using <code>org.apache.http.client.HttpClient</code> the average time is around 7 seconds, which is far from being good.</p>