title: Basic Authentication with RestTemplate on outbound gateway
body: <p>Been pulling what little hair I have left trying to get this to work. </p>
  
  <p><strong><em>Problem 1</em></strong>: </p>
  
  <p>I am performing a JSON POST to a Spring controller. I pass in the <code>Authentication</code> header as a parameter to the <code>int:gateway</code>. An <code>int-http:outbound-gateway</code> then gets invoked. I can see the header and also the handshake with the remote application, but I am getting a <code>400 Bad Request</code> from the <code>org.apache.http.impl.client.DefaultHttpClient</code>. I am able to authenticate and execute the request directly (i.e. without SI) using a separate client.</p>
  
  <p>I used components mentioned in <a href="https://stackoverflow.com/a/19655352/1990536">this</a> solution unsuccessfully. Where am I going wrong with this?</p>
  
  <p>What I do not like is the reference to <code>DefaultHttpClient</code> which appears to be deprecated as mentioned in other posts. Not sure what the alternative is here. Somewhere I saw mention of using <code>OkHttp</code> client, but I am not sure how to wire that up with SI.</p>
  
  <p><strong><em>Problem 2</em></strong>: </p>
  
  <p>The service below returns a <code>ResponseEntity&lt;?&gt;</code> because I am unable to convert it to the domain specific type (CustSyncResponseVO). Should I expect this behavior when using RestTemplate with SI or is there a transformation I can perform on the <code>outbound-gateway</code> response?</p>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p><strong>Environment</strong></p>
  
  <ul>
  <li>Java 1.7</li>
  <li>Spring Boot 1.3.1.RELEASE</li>
  <li><p>HTTP Core v4.3.2 and HTTP Client v4.3.5</p>
  
  <pre><code>    &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
      &lt;artifactId&gt;httpclient&lt;/artifactId&gt;
  </code></pre></li>
  </ul>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>@RequestMapping(value = "/customerSync", method = RequestMethod.POST)
  public @ResponseBody CustSyncResponseVO syncCustomer(@RequestBody CustSyncRequestVO customerSyncRequest, 
          @RequestHeader(value = "Authorization") String authorization ) {
      CustSyncResponseVO customerSyncResponse = null;
  
      customerSyncResponse = customerService.deliver(customerSyncRequest, authorization);
  
      return customerSyncResponse;
  }
  </code></pre>
  
  <p><strong>Service</strong></p>
  
  <pre><code>package com.uscs.crm.service;
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.http.ResponseEntity;
  import org.springframework.messaging.handler.annotation.Header;
  import org.springframework.stereotype.Service;
  
  import com.uscs.crm.integration.CustomerGateway;
  import com.uscs.crm.model.CustLinkRequestVO;
  import com.uscs.crm.model.CustSyncRequestVO;
  import com.uscs.crm.model.CustSyncResponseVO;
  
  @Service
  public class CustomerServiceImpl implements CustomerService {
  
      private static Logger logger = LoggerFactory.getLogger(CustomerServiceImpl.class);
  
      @Autowired
      private CustomerGateway customerGateway;
  
      @Override
      public CustSyncResponseVO deliver(CustSyncRequestVO custSyncRequest, @Header(value="Authorization") String authorization) {
          CustSyncResponseVO custSyncResponse = null;     
          //custSyncResponse = customerGateway.deliver(custSyncRequest);
          ResponseEntity&lt;?&gt; responseEntity = null;
          try {
               responseEntity = customerGateway.deliver(custSyncRequest, authorization);
          } catch (Exception e) {
              logger.error("Unable to sync customer request to eWM" , e);
          } 
  
          return custSyncResponse;
      }
  
  
      @Override
      public CustSyncResponseVO link(CustLinkRequestVO linkRequest) {
          throw new UnsupportedOperationException("To be implemented");
      }
  
  }
  </code></pre>
  
  <p><strong>Gateway</strong></p>
  
  <pre><code>package com.uscs.crm.integration;
  
  import org.springframework.http.ResponseEntity;
  import org.springframework.messaging.handler.annotation.Header;
  
  import com.uscs.crm.model.CustSyncRequestVO;
  
  public interface CustomerGateway {
      public static final String HTTP_AUTHORIZATION = "Authorization"; 
  
      public ResponseEntity&lt;?&gt; deliver(CustSyncRequestVO customer, @Header(HTTP_AUTHORIZATION) String authorization);
  
  }
  </code></pre>
  
  <p><strong>Config</strong></p>
  
  <pre><code>&lt;context:component-scan base-package="com.uscs.**"/&gt; 
  
  &lt;!-- Authorization scope for accessing restful service.  Since we want this template to be used for everything, we are setting up it with defaults --&gt; 
  &lt;bean id="authScope" class="org.apache.http.auth.AuthScope"&gt;
      &lt;constructor-arg name="host"&gt;&lt;null /&gt;&lt;/constructor-arg&gt;
      &lt;constructor-arg&gt;&lt;value&gt;-1&lt;/value&gt; &lt;/constructor-arg&gt;
      &lt;constructor-arg&gt;&lt;null /&gt;&lt;/constructor-arg&gt;
      &lt;constructor-arg&gt;&lt;null /&gt;&lt;/constructor-arg&gt;
  &lt;/bean&gt;
  
  &lt;bean id="httpComponentsMessageSender" class="org.springframework.ws.transport.http.HttpComponentsMessageSender"&gt;
      &lt;property name="credentials"&gt;
          &lt;bean class="org.apache.http.auth.UsernamePasswordCredentials"&gt;
              &lt;constructor-arg name="userName"&gt;&lt;value&gt;xxxxxx&lt;/value&gt;&lt;/constructor-arg&gt;
              &lt;constructor-arg name="password"&gt;&lt;value&gt;xxxxxx&lt;/value&gt;&lt;/constructor-arg&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
      &lt;property name="authScope" ref="authScope"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="clientHttpRequestFactory" class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory"&gt;
      &lt;property name="httpClient" value="#{httpComponentsMessageSender.httpClient}"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="restTemplate" name="restTemplate" class="org.springframework.web.client.RestTemplate" autowire-candidate="true"&gt;
        &lt;constructor-arg ref="clientHttpRequestFactory" /&gt;
    &lt;property name="messageConverters"&gt; 
        &lt;list&gt; 
            &lt;bean  class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/&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;
  
  &lt;int:channel id="syncCustomers"/&gt;
  &lt;int:channel id="replySyncCustomers"/&gt;
  
  &lt;int:gateway id="customerGateway" service-interface="com.uscs.crm.integration.CustomerGateway" 
          default-request-channel="syncCustomers" default-reply-channel="replySyncCustomers" /&gt;
  
  &lt;int:object-to-json-transformer input-channel="syncCustomers" output-channel="outboundRequestChannel" content-type="application/json" /&gt;    
  
  &lt;int-http:outbound-gateway request-channel="outboundRequestChannel" reply-channel="replySyncCustomers"
                url="http://voorhees148.uscold.com:9595/web/customerSync/createCustomer"
                http-method="POST"
                rest-template="restTemplate"
                expected-response-type="com.uscs.crm.model.CustSyncResponseVO" 
                mapped-request-headers="Authorization, HTTP_REQUEST_HEADERS"/&gt;
  </code></pre>
  
  <p><strong>Logging from SI</strong></p>
  
  <pre><code>10:07:03.981 [http-nio-8080-exec-1] DEBUG o.a.h.i.conn.DefaultClientConnection - Sending request: POST /web/customerSync/createCustomer HTTP/1.1
  10:07:03.981 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &gt;&gt; "POST /web/customerSync/createCustomer HTTP/1.1[\r][\n]"
  10:07:03.981 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &gt;&gt; "Accept: application/json, application/*+json[\r][\n]"
  10:07:03.981 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &gt;&gt; "Authorization: Basic aHFyc2luZ2g6UGFzc3dvcmQxMjM=[\r][\n]"
  10:07:03.981 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &gt;&gt; "Content-Type: application/json[\r][\n]"
  10:07:03.981 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &gt;&gt; "Content-Length: 431[\r][\n]"
  10:07:03.981 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &gt;&gt; "Host: voorhees148.uscold.com:9595[\r][\n]"
  10:07:03.981 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &gt;&gt; "Connection: Keep-Alive[\r][\n]"
  10:07:03.981 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &gt;&gt; "User-Agent: Apache-HttpClient/4.3.5 (java 1.5)[\r][\n]"
  10:07:03.981 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &gt;&gt; "[\r][\n]"
  10:07:03.981 [http-nio-8080-exec-1] DEBUG org.apache.http.headers - &gt;&gt; POST /web/customerSync/createCustomer HTTP/1.1
  10:07:03.981 [http-nio-8080-exec-1] DEBUG org.apache.http.headers - &gt;&gt; Accept: application/json, application/*+json
  10:07:03.981 [http-nio-8080-exec-1] DEBUG org.apache.http.headers - &gt;&gt; Authorization: Basic aHFyc2luZ2g6UGFzc3dvcmQxMjM=
  10:07:03.981 [http-nio-8080-exec-1] DEBUG org.apache.http.headers - &gt;&gt; Content-Type: application/json
  10:07:03.981 [http-nio-8080-exec-1] DEBUG org.apache.http.headers - &gt;&gt; Content-Length: 431
  10:07:03.981 [http-nio-8080-exec-1] DEBUG org.apache.http.headers - &gt;&gt; Host: voorhees148.uscold.com:9595
  10:07:03.981 [http-nio-8080-exec-1] DEBUG org.apache.http.headers - &gt;&gt; Connection: Keep-Alive
  10:07:03.981 [http-nio-8080-exec-1] DEBUG org.apache.http.headers - &gt;&gt; User-Agent: Apache-HttpClient/4.3.5 (java 1.5)
  10:07:03.981 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &gt;&gt; ""{\"legacyNo\":\"867530\",\"customerType\":\"24\",\"customerName\":\"Test Customer\",\"addr1\":\"123 Main Street\",\"addr2\":\"\",\"addr3\":\"\",\"city\":\"Podunk\",\"state\":\"MI\",\"zip\":\"48158\",\"country\":\"US\",\"phoneNumber\":\"8563334444\",\"contactName\":\"Jeb A. Dyah\",\"contactType\":\"123\",\"contactPhone\":\"8561112222\",\"contactFax\":\"8567778888\",\"contactEmail\":\"jeb@podunk.com\",\"actionCode\":\"CREATE\"}""
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &lt;&lt; "HTTP/1.1 400 Bad Request[\r][\n]"
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &lt;&lt; "X-Powered-By: Servlet/3.0[\r][\n]"
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &lt;&lt; "Content-Type: text/html;charset=ISO-8859-1[\r][\n]"
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &lt;&lt; "$WSEP: [\r][\n]"
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &lt;&lt; "Content-Language: en-US[\r][\n]"
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &lt;&lt; "Set-Cookie: JSESSIONID=0000yf8BRdBUc8w-OZldE5UDJSt:cd3aeb2b-d5ea-4ef6-8a84-9b912f76478c; Path=/; HttpOnly[\r][\n]"
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &lt;&lt; "Transfer-Encoding: chunked[\r][\n]"
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &lt;&lt; "Connection: Close[\r][\n]"
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &lt;&lt; "Date: Sun, 20 Dec 2015 15:07:06 GMT[\r][\n]"
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &lt;&lt; "Expires: Thu, 01 Dec 1994 16:00:00 GMT[\r][\n]"
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &lt;&lt; "Cache-Control: no-cache="set-cookie, set-cookie2"[\r][\n]"
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &lt;&lt; "[\r][\n]"
  10:07:06.576 [http-nio-8080-exec-1] DEBUG o.a.h.i.conn.DefaultClientConnection - Receiving response: HTTP/1.1 400 Bad Request
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.headers - &lt;&lt; HTTP/1.1 400 Bad Request
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.headers - &lt;&lt; X-Powered-By: Servlet/3.0
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.headers - &lt;&lt; Content-Type: text/html;charset=ISO-8859-1
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.headers - &lt;&lt; $WSEP: 
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.headers - &lt;&lt; Content-Language: en-US
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.headers - &lt;&lt; Set-Cookie: JSESSIONID=0000yf8BRdBUc8w-OZldE5UDJSt:cd3aeb2b-d5ea-4ef6-8a84-9b912f76478c; Path=/; HttpOnly
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.headers - &lt;&lt; Transfer-Encoding: chunked
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.headers - &lt;&lt; Connection: Close
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.headers - &lt;&lt; Date: Sun, 20 Dec 2015 15:07:06 GMT
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.headers - &lt;&lt; Expires: Thu, 01 Dec 1994 16:00:00 GMT
  10:07:06.576 [http-nio-8080-exec-1] DEBUG org.apache.http.headers - &lt;&lt; Cache-Control: no-cache="set-cookie, set-cookie2"
  10:07:06.577 [http-nio-8080-exec-1] DEBUG o.a.h.c.p.ResponseProcessCookies - Cookie accepted [JSESSIONID="0000yf8BRdBUc8w-OZldE5UDJSt:cd3aeb2b-d5ea-4ef6-8a84-9b912f76478c", version:0, domain:voorhees148.uscold.com, path:/, expiry:null]
  10:07:06.577 [http-nio-8080-exec-1] DEBUG o.s.web.client.RestTemplate - POST request for "http://voorhees148.uscold.com:9595/web/customerSync/createCustomer" resulted in 400 (Bad Request); invoking error handler
  10:07:06.608 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &lt;&lt; "2b[\r][\n]"
  10:07:06.608 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &lt;&lt; "Error 400: SRVE0295E: Error reported: 400[\r][\n]"
  10:07:06.608 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &lt;&lt; "[\r][\n]"
  10:07:06.608 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &lt;&lt; "0[\r][\n]"
  10:07:06.608 [http-nio-8080-exec-1] DEBUG org.apache.http.wire -  &lt;&lt; "[\r][\n]"
  10:07:06.608 [http-nio-8080-exec-1] DEBUG o.a.h.i.conn.DefaultClientConnection - Connection 0.0.0.0:45624&lt;-&gt;192.168.56.1:9595 closed
  10:07:06.608 [http-nio-8080-exec-1] DEBUG o.a.h.i.c.PoolingClientConnectionManager - Connection released: [id: 0][route: {}-&gt;http://voorhees148.uscold.com:9595][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
  10:07:06.608 [http-nio-8080-exec-1] DEBUG o.s.i.g.GatewayProxyFactoryBean$MethodInvocationGateway - failure occurred in gateway sendAndReceive: HTTP request execution failed for URI [http://voorhees148.uscold.com:9595/web/customerSync/createCustomer]; nested exception is org.springframework.web.client.HttpClientErrorException: 400 Bad Request
  10:07:47.894 [http-nio-8080-exec-1] ERROR c.u.crm.service.CustomerServiceImpl - Unable to sync customer request to eWM
  org.springframework.web.client.HttpClientErrorException: 400 Bad Request
      at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:641) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:597) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:572) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:493) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler.handleRequestMessage(HttpRequestExecutingMessageHandler.java:382) ~[spring-integration-http-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:99) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115) ~[spring-messaging-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45) ~[spring-messaging-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105) ~[spring-messaging-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:231) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:154) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:102) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:105) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115) ~[spring-messaging-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:150) ~[spring-messaging-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:45) ~[spring-messaging-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.messaging.core.AbstractMessagingTemplate.sendAndReceive(AbstractMessagingTemplate.java:42) ~[spring-messaging-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:97) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:38) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.messaging.core.AbstractMessagingTemplate.convertSendAndReceive(AbstractMessagingTemplate.java:79) ~[spring-messaging-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.messaging.core.AbstractMessagingTemplate.convertSendAndReceive(AbstractMessagingTemplate.java:70) ~[spring-messaging-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:412) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceive(MessagingGatewaySupport.java:386) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:422) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke(GatewayProxyFactoryBean.java:382) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke(GatewayProxyFactoryBean.java:373) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at com.sun.proxy.$Proxy54.deliver(Unknown Source) ~[na:na]
      at com.uscs.crm.service.CustomerServiceImpl.deliver(CustomerServiceImpl.java:29) ~[classes/:na]
      at com.uscs.crm.controller.HelloController.syncCustomer(HelloController.java:35) [classes/:na]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_67]
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_67]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_67]
      at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_67]
      at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222) [spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) [spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) [spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814) [spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737) [spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) [spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) [spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) [spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969) [spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871) [spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845) [spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-embed-websocket-8.0.30.jar:8.0.30]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) [spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87) [spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) [spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) [spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.7.0_67]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.7.0_67]
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.30.jar:8.0.30]
      at java.lang.Thread.run(Unknown Source) [na:1.7.0_67]
  10:07:51.692 [http-nio-8080-exec-1] DEBUG o.s.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
  10:07:51.693 [http-nio-8080-exec-1] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request
  10:07:51.693 [http-nio-8080-exec-1] DEBUG o.s.b.c.w.OrderedRequestContextFilter - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@5f525ba5
  </code></pre>
  
  <p><strong>EDIT1</strong>:</p>
  
  <p>It appears that the remote application logs indicate a problem with unmarshalling the request to the expected type:</p>
  
  <pre><code>nested exception is org.codehaus.jackson.map.JsonMappingException: Can not instantiate value of type [simple type, class com.uscs.ewms.mdm.vo.customer.synchronizer.CustomerCreateSyncSubRequestVO] from JSON String; no single-String constructor/factory method (AbstractHandlerExceptionResolver.java:132)
  </code></pre>
  
  <p><strong>Controller and Request Type in Remote Application</strong></p>
  
  <pre><code>@RequestMapping(value = "/createCustomer", method = RequestMethod.POST, consumes = CONTENTTYPE_APPLICATION_JSON, produces = CONTENTTYPE_APPLICATION_JSON)
  public @ResponseBody
  CustomerSyncResponseVO createCustomer(HttpServletRequest request, @RequestBody CustomerCreateSyncSubRequestVO customerCreateSyncRequestVO, Principal principal) {
  
  ...
  
  }
  
  public class CustomerCreateSyncSubRequestVO {
  
  @JsonProperty("legacyNo")
  private String legacyNo;
  
  ...
  
  }
  </code></pre>
  
  <p>There is no default constructor in the remote <code>CustomerCreateSyncSubRequestVO</code>, but this unmarshalls from JSON with no problem when I send an HTTP POST directly to the remote application without SI in the middle. I feel that the double quoted JSON "string" that is sent through the <code>outbound-gateway</code> is causing the problem since the <code>400 Bad Request</code> implies invalid JSON. My request object from the SI gateway does have a default constructor without any other annotation:</p>
  
  <pre><code>package com.uscs.crm.model;
  
  public class CustSyncRequestVO {
  
      private String legacyNo;
  ...
      public CustSyncRequestVO() {
  
      }
  }
  </code></pre>