2016-07-22 3 views
3

내가 <int-http:outbound-gateway>봄 통합를 사용하여 봄 데이터 나머지 URL을 호출하고있어에서 응답 빈 페이로드.봄 통합 : 아웃 바운드 게이트웨이

내 호출은 알려진 리소스 URL (내 경우 "예제")에 대한 간단한 HTTP GET입니다.

<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"> 
</int-http:outbound-gateway> 

나는이 메시지를 볼 수있는 로그 : :이 'extractPayload'속성은 HTTP 이후 현재 요청에 대해 관련이 없으며,

<int-http:outbound-gateway>의 구성입니다 메소드가 'GET'이고 요청 본문이 해당 메소드에 대해 이 전송됩니다.

이 설정은 http-method="GET" extract-request-payload="true" 구성으로 간주되지만이 경고가 해당 질문과 관련이 있는지 여부는 알 수 없습니다.

가 호출 할 수있는 REST URL을 포함하는 메시지와 아웃 바운드 채널의 호출입니다 :

public Object invokeUrl(String url){ 
    MessagingChannel messagingChannel = (MessagingChannel)ApplicationContextResolver.getApplicationContext().getBean("requestChannelBean"); 
    MessageChannel dataRestChannel = messagingChannel.getDataRestChannel(); 
    MessagingTemplate messagingTemplate = new MessagingTemplate(); 
    Message<?> requestMessage = MessageBuilder.withPayload(url).build(); 
    Message<?> response = messagingTemplate.sendAndReceive(dataRestChannel, requestMessage); 
    return response.getPayload(); 
} 

이 호출은 괜찮습니다, 내가 HTTP 상태 코드 (200)을 가지고, 은 "페이로드의 몸이"비어있는 이유는 콘텐츠 길이 헤더에서 볼 수 그러나

<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] 
}> 

, 나는 이해하지 않는다 : 이것은 response.getPayload()입니다.

{ 
    "_embedded": { 
     "examples": [] 
    }, 
    "_links": { 
     "self": { 
      "href": "http://localhost:8080/restapp/api/examples" 
     }, 
     "profile": { 
      "href": "http://localhost:8080/restapp/api/profile/examples" 
     } 
    } 
} 

내가 응답 페이로드가 아닌 빈 페이로드로이 예상 것 :

response GenericMessage<T> (id=219) 
    headers MessageHeaders (id=221)  
    payload ResponseEntity<T> (id=222) 
     body null  
     headers HttpHeaders (id=224) 
     statusCode HttpStatus (id=159)  

내가 브라우저에서 GET으로 해당 URL로 직접 이동하는 경우이 내가받을 수 있다는 반응이다.

내가받는 ResponseEntity.body가 비어있는 것 같습니다.

아웃 바운드 게이트웨이에서 HTTP get과 동일한 JSON 결과를 얻는 방법이 있습니까?

미리 감사드립니다.

UPDATE는

게리의 제안에서로서, 나는 트래픽을 모니터링했다.하나의 헤더를 제외하고,

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 

요청이 동일한 것으로 보인다

봄 통합 요청 :

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 

브라우저 요청

다음은 요청의 세부 사항이 있습니다 (쿠키 JSESSIONID, 통합 컨텍스트에서 부재).

업데이트 2

은 어쩌면 내가 응답의 빈 페이로드의 이유를 발견했다.

org.springframework.web.client.RestTemplate"extractData" 방법은 널값에 걸렸고 객체 인스턴스 this.delegate있다.

따라서, ResponseEntity 개체 본체가없는 경우입니다.

@Override 
public ResponseEntity<T> extractData(ClientHttpResponse response) throws IOException { 
    if (this.delegate != null) { // this.delegate is null 
     T body = this.delegate.extractData(response); 
     return new ResponseEntity<T>(body, response.getHeaders(), response.getStatusCode()); 
    } 
    else { 
     return new ResponseEntity<T>(response.getHeaders(), response.getStatusCode()); // <- it's executed this one 
    } 
} 

this.delegate가 null로 설정된 이유를 발견하는 것은 흥미로운 일입니다.

+0

요청에 다소 다른 점이있을 수 있습니다. TCP 모니터를 사용하여 두 개의 요청/응답을 비교하는 것이 좋습니다 (이클립스에 내장 된 모니터가 있거나 wireshark 등을 사용하는 것이 좋습니다). 그 점을 이해할 수 없다면 네트워크 추적을 사용하여 질문을 편집하십시오. –

+0

제안에 감사드립니다. Gary. 요청의 세부 사항으로 질문을 편집했습니다. –

+0

서버 앱과 같은 사운드가 세션 (로그인?)을 필요로 할 수 있습니다. 서버 측에서 디버깅해야합니다. –

답변

3

expected-response-type="java.lang.String"을 게이트웨이에 추가해야합니다.

+0

효과가있었습니다! 감사! –

관련 문제