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:
committed by
Gary Russell
parent
07c32ae93b
commit
ee501c801f
@@ -38,6 +38,7 @@ import org.springframework.integration.channel.DirectChannel;
|
||||
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.outbound.HttpRequestExecutingMessageHandler;
|
||||
import org.springframework.integration.security.channel.ChannelSecurityInterceptor;
|
||||
import org.springframework.integration.security.channel.SecuredChannel;
|
||||
@@ -80,6 +81,9 @@ public class HttpDslTests {
|
||||
@Autowired
|
||||
private HttpRequestExecutingMessageHandler serviceInternalGatewayHandler;
|
||||
|
||||
@Autowired
|
||||
private IntegrationFlowContext integrationFlowContext;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Before
|
||||
@@ -114,6 +118,37 @@ public class HttpDslTests {
|
||||
.isForbidden());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDynamicHttpEndpoint() throws Exception {
|
||||
IntegrationFlow flow =
|
||||
IntegrationFlows.from(Http.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.mockMvc.perform(
|
||||
get("/dynamic")
|
||||
.with(httpBasic("admin", "admin"))
|
||||
.param("name", "BAR"))
|
||||
.andExpect(
|
||||
content()
|
||||
.string("bar"));
|
||||
|
||||
flowRegistration.destroy();
|
||||
|
||||
this.mockMvc.perform(
|
||||
get("/dynamic")
|
||||
.with(httpBasic("admin", "admin"))
|
||||
.param("name", "BAZ"))
|
||||
.andExpect(
|
||||
status()
|
||||
.isNotFound());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@EnableIntegration
|
||||
|
||||
Reference in New Issue
Block a user