From f5228728e0e63993eab91e11c97c3c43586b9e61 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Sun, 12 Dec 2010 19:58:28 -0500 Subject: [PATCH] INT-1679 the HttpStatus enum instance from the reply is now copied to the MessageHeaders of a reply when there is a response body --- .../integration/http/HttpHeaders.java | 2 ++ .../outbound/HttpRequestExecutingMessageHandler.java | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/HttpHeaders.java b/spring-integration-http/src/main/java/org/springframework/integration/http/HttpHeaders.java index 90d7f8f151..efd084b53a 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/HttpHeaders.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/HttpHeaders.java @@ -30,4 +30,6 @@ public abstract class HttpHeaders { public static final String USER_PRINCIPAL = PREFIX + "userPrincipal"; + public static final String STATUS_CODE = PREFIX + "statusCode"; + } diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java b/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java index 2113870a36..7e57479cfc 100755 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java @@ -38,6 +38,7 @@ import org.springframework.expression.spel.support.StandardTypeConverter; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.http.client.ClientHttpRequestFactory; @@ -60,7 +61,13 @@ import org.springframework.web.client.RestTemplate; /** * A {@link MessageHandler} implementation that executes HTTP requests by delegating - * to a {@link RestTemplate} instance. + * to a {@link RestTemplate} instance. If the 'expectReply' flag is set to true (the default) + * then a reply Message will be generated from the HTTP response. If that response contains + * a body, it will be used as the reply Message's payload. Otherwise the reply Message's + * payload will contain the response status as an instance of the {@link HttpStatus} enum. + * When there is a response body, the {@link HttpStatus} enum instance will instead be + * copied to the MessageHeaders of the reply. In both cases, the response headers will + * be mapped to the reply Message's headers by this handler's {@link HeaderMapper} instance. * * @author Mark Fisher * @author Oleg Zhurakousky @@ -229,7 +236,8 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe Object responseBody = httpResponse.getBody(); MessageBuilder replyBuilder = (responseBody instanceof Message) ? MessageBuilder.fromMessage((Message) responseBody) : MessageBuilder.withPayload(responseBody); - return replyBuilder.copyHeaders(headers).build(); + replyBuilder.setHeader(org.springframework.integration.http.HttpHeaders.STATUS_CODE, httpResponse.getStatusCode()); + return replyBuilder.copyHeaders(headers).build(); } else { return MessageBuilder.withPayload(httpResponse.getStatusCode()).copyHeaders(headers).build();