title: Spring Integration with Spring Data Rest: empty payload in response from outbound-gateway
body: <p>I'm calling a <strong>Spring Data Rest</strong> URL using <strong>Spring Integration</strong> with an <code>&lt;int-http:outbound-gateway&gt;</code>.</p>
  
  <p>My invocation is a simple <strong>HTTP GET</strong> towards a known resource URL (in my case, "examples").</p>
  
  <p>This is the configuration of the <code>&lt;int-http:outbound-gateway&gt;</code>:</p>
  
  <pre><code>&lt;int-http:outbound-gateway id="internalGW" request-channel="dataRestChannel"
      encode-uri="true" url-expression="payload" 
      http-method="GET" extract-request-payload="true"
      header-mapper="headerMapper"&gt; 
  &lt;/int-http:outbound-gateway&gt;
  </code></pre>
  
  <p>In the logs I can see this message:</p>
  
  <blockquote>
    <p>The 'extractPayload' attribute has no relevance for the current
    request since the HTTP Method is 'GET', and no request body will be
    sent for that method.</p>
  </blockquote>
  
  <p>I suppose that is refered to the <code>http-method="GET" extract-request-payload="true"</code> configuration, but I don't know if this warning is relevant for the question.</p>
  
  <p>This is the invocation of that outbound channel with a message that contains the REST url to be invoked:</p>
  
  <pre><code>public Object invokeUrl(String url){
      MessagingChannel messagingChannel = (MessagingChannel)ApplicationContextResolver.getApplicationContext().getBean("requestChannelBean");
      MessageChannel dataRestChannel = messagingChannel.getDataRestChannel();
      MessagingTemplate messagingTemplate = new MessagingTemplate();
      Message&lt;?&gt; requestMessage = MessageBuilder.withPayload(url).build();
      Message&lt;?&gt; response = messagingTemplate.sendAndReceive(dataRestChannel, requestMessage);
      return response.getPayload();
  }
  </code></pre>
  
  <p>The invocation is fine, I have an HTTP status code 200; this is the response.getPayload():</p>
  
  <pre><code>&lt;200 OK,
  {
      Server=[Apache-Coyote/1.1],
      Cache-Control=[no-cache,no-store,max-age=0,must-revalidate],
      Pragma=[no-cache],
      Expires=[0],
      X-XSS-Protection=[1; mode=block],
      X-Frame-Options=[DENY,DENY],
      X-Content-Type-Options=[nosniff,nosniff],
      Transfer-Encoding=[chunked],
      Date=[Fri,22 Jul 2016 13:03:22 GMT],
      Content-Type=[application/hal+json],
      Content-Length=[0]
  }&gt;
  </code></pre>
  
  <p>However, I don't understand why the "payload body" is empty, as you can see in the Content-Length header.</p>
  
  <pre><code>response    GenericMessage&lt;T&gt;  (id=219) 
      headers MessageHeaders  (id=221)    
      payload ResponseEntity&lt;T&gt;  (id=222) 
          body    null    
          headers HttpHeaders  (id=224)   
          statusCode  HttpStatus  (id=159)    
  </code></pre>
  
  <p>If I go directly to that URL with a GET on the browser, this is the response that I receive:</p>
  
  <pre><code>{
      "_embedded": {
          "examples": []
      },
      "_links": {
          "self": {
              "href": "http://localhost:8080/restapp/api/examples"
          },
          "profile": {
              "href": "http://localhost:8080/restapp/api/profile/examples"
          }
      }
  }
  </code></pre>
  
  <p><strong>I would expected this as the response payload, not an empty payload</strong>.</p>
  
  <p>It seems that the ResponseEntity.body that I receive is empty.</p>
  
  <p>Is there any way to get the same JSON result of the HTTP get with the outbound-gateway?</p>
  
  <p>Thanks in advance.  </p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>As from Gary suggestion, I have monitored the traffic.</p>
  
  <p>Here there are the details of the requests:</p>
  
  <p>Spring Integration Request:</p>
  
  <pre><code>GET http://localhost:8080/restapp/api/examples HTTP/1.1
  Host: localhost:8080
  Connection: keep-alive
  Cache-Control: max-age=0
  Upgrade-Insecure-Requests: 1
  User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
  Accept-Encoding: gzip, deflate, sdch
  Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4
  </code></pre>
  
  <p>Browser Request:</p>
  
  <pre><code>GET http://localhost:8080/restapp/api/examples HTTP/1.1
  Host: localhost:8080
  Connection: keep-alive
  Cache-Control: max-age=0
  Upgrade-Insecure-Requests: 1
  User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
  Accept-Encoding: gzip, deflate, sdch
  Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4
  Cookie: JSESSIONID=C966FB7DB6B172D530D7C1F4DC57C6B8
  </code></pre>
  
  <p>The requests seems to be the same, except for one header (the Cookie JSESSIONID, there is absent in Integration context).</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>Maybe I have found the reason of the empty payload on the response.</p>
  
  <p>The <code>"extractData"</code> method of <code>org.springframework.web.client.RestTemplate</code> has the object instance <em><code>this.delegate</code></em> setted to a <strong>null value</strong>.</p>
  
  <p>So, in return there is a <code>ResponseEntity</code> object <strong>without the body</strong>.</p>
  
  <pre><code>@Override
  public ResponseEntity&lt;T&gt; extractData(ClientHttpResponse response) throws IOException {
      if (this.delegate != null) {  // this.delegate is null
          T body = this.delegate.extractData(response);
          return new ResponseEntity&lt;T&gt;(body, response.getHeaders(), response.getStatusCode());
      }
      else {
          return new ResponseEntity&lt;T&gt;(response.getHeaders(), response.getStatusCode()); // &lt;- it's executed this one
      }
  }
  </code></pre>
  
  <p>It would be interesting to discover why this.delegate is setted to null.</p>