INT-4436: Register HTTP endpoints at runtime

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

* Fix `IntegrationRequestMappingHandlerMapping` and
`IntegrationRequestMappingHandlerMapping` to implement a
`DestructionAwareBeanPostProcessor` to allow to register and
destroy HTTP endpoints at runtime, e.g. via `IntegrationFlowContext`
with the dynamic `IntegrationFlow`s
This commit is contained in:
Artem Bilan
2018-06-22 15:54:09 -04:00
committed by Gary Russell
parent 07c32ae93b
commit ee501c801f
4 changed files with 130 additions and 5 deletions

View File

@@ -51,6 +51,7 @@ import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.integration.dsl.context.IntegrationFlowContext;
import org.springframework.integration.http.HttpHeaders;
import org.springframework.integration.http.dsl.Http;
import org.springframework.integration.support.MessageBuilder;
@@ -109,6 +110,9 @@ public class WebFluxDslTests {
@Autowired
private WebApplicationContext wac;
@Autowired
private IntegrationFlowContext integrationFlowContext;
@Autowired
@Qualifier("webFluxWithReplyPayloadToFlux.handler")
private WebFluxRequestExecutingMessageHandler webFluxWithReplyPayloadToFlux;
@@ -246,6 +250,33 @@ public class WebFluxDslTests {
.verifyComplete();
}
@Test
public void testDynamicHttpEndpoint() throws Exception {
IntegrationFlow flow =
IntegrationFlows.from(WebFlux.inboundGateway("/dynamic")
.requestMapping(r -> r.params("name"))
.payloadExpression("#requestParams.name[0]"))
.<String, String>transform(String::toLowerCase)
.get();
IntegrationFlowContext.IntegrationFlowRegistration flowRegistration =
this.integrationFlowContext.registration(flow).register();
this.webTestClient.get().uri("/dynamic?name=BAR")
.attributes(basicAuthenticationCredentials("guest", "guest"))
.exchange()
.expectBody(String.class)
.isEqualTo("bar");
flowRegistration.destroy();
this.webTestClient.get().uri("/dynamic?name=BAZ")
.attributes(basicAuthenticationCredentials("guest", "guest"))
.exchange()
.expectStatus()
.isNotFound();
}
@Configuration
@EnableWebFlux
@EnableWebSecurity