Search code examples
spring-integrationspringdoc-openapi-uispring-integration-http

Ignore specific path in Http.inboundGateway


I'm working on a Spring boot 2.7.7 + Spring integration application that works as a webservice proxy: any URL fed to the webservice is converted to the URL of one of many third-party services following some business rules.

The accepted URLs cannot be listed explicitly. Fortunately, although the inboundGateway documentation doesn't mention it explicitly, one can actually use an Ant path pattern as parameter:

@Bean
public IntegrationFlow proxyFlow() {
   ...

   return IntegrationFlows.from(Http.inboundGateway("/**")

                          ... handle/transform and so on

                          .get();
}

The proxy itself is working as intended, but I need to add a Swagger UI using OpenAPI. Once added to the project, it provides the OAS documentation under http://<host>:<port>/<context-path>/v3/api-docs and the swagger ui under http://<host>:<port>/<context-path>/swagger-ui.html.

Unfortunately, the /swagger-ui.html URL is not reachable since it is caught by the Http inbound gateway, while, surprisingly, the /v3/api-docs isn't (it is reachable).

Is there a way to tell the inbound gateway to ignore this specific URL path while consuming all the other paths?


Solution

  • I'm not sure how that Swagger is configured for Spring, but let's see if we can make this Spring Integration stuff a bit lower in the stack. Add this bean into your configuration:

        @Bean(HttpContextUtils.HANDLER_MAPPING_BEAN_NAME)
        static IntegrationRequestMappingHandlerMapping integrationRequestMappingHandlerMapping() {
            IntegrationRequestMappingHandlerMapping handlerMapping = new IntegrationRequestMappingHandlerMapping();
            handlerMapping.setOrder(Ordered.LOWEST_PRECEDENCE);
            return handlerMapping;
        }
    

    Essentially, we have to override an default 0 for order applied in the framework.

    You may also try to use some other options of the requestMapping(Consumer<RequestMappingSpec> mapping) to try to narrow mapping rules. If some headers or params are available for your proxy requests or that Swagger UI.