INT-4350: Handle ResponseEntity in HTTP Inbounds

JIRA: https://jira.spring.io/browse/INT-4350

Spring MVC and Spring WebFlux handles `ResponseEntity` via appropriate
`ReturnValue` handlers.
This way all the headers and status code are fully up to end-user.
The body is handled by the appropriate converter/writer as before

* Add `ResponseEntity` handling to the `HttpRequestHandlingMessagingGateway`
and `WebFluxInboundEndpoint`.
The logic mostly compy/pasted from the `ResponseEntityResultHandler`
This commit is contained in:
Artem Bilan
2017-09-26 18:30:36 -04:00
committed by Gary Russell
parent 008a740fb0
commit 6d96914c1f
5 changed files with 95 additions and 11 deletions

View File

@@ -27,6 +27,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.channel.FluxMessageChannel;
import org.springframework.integration.config.EnableIntegration;
@@ -83,6 +84,17 @@ public class WebFluxInboundEndpointTests {
.jsonPath("$[2].name").isEqualTo("John");
}
@Test
public void testServerInternalErrorRequest() {
this.webTestClient
.get()
.uri("/error")
.accept(MediaType.TEXT_PLAIN)
.exchange()
.expectStatus()
.is5xxServerError();
}
@Configuration
@EnableWebFlux
@EnableIntegration
@@ -128,6 +140,22 @@ public class WebFluxInboundEndpointTests {
return Flux.just(new Person("Jane"), new Person("Jason"), new Person("John"));
}
@Bean
public WebFluxInboundEndpoint errorInboundEndpoint() {
WebFluxInboundEndpoint endpoint = new WebFluxInboundEndpoint();
RequestMapping requestMapping = new RequestMapping();
requestMapping.setPathPatterns("/error");
endpoint.setRequestMapping(requestMapping);
endpoint.setRequestChannelName("errorServiceChannel");
return endpoint;
}
@ServiceActivator(inputChannel = "errorServiceChannel")
public ResponseEntity<String> processHttpRequest() {
return new ResponseEntity<>("<500 Internal Server Error,{}>", HttpStatus.INTERNAL_SERVER_ERROR);
}
}