1

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?

Marc Tarin
  • 3,109
  • 17
  • 49

1 Answers1

1

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.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Lowering the precedence of the handler mapping solved it! That being said, I wish I could add even more points to your solution because the hint about the requestMappingSpec also proves very useful. – Marc Tarin Feb 25 '23 at 08:57
  • Seems like I talk too fast: the swagger url is now accessible, but I get a 404 error for all url paths that are handled by the integration Http inbound. – Marc Tarin Mar 02 '23 at 13:58
  • Yeah... The it is probably bad idea to catch all the paths in one controller. Consider to have it under something like `proxy/**` and rebuild target URL respectively. – Artem Bilan Mar 02 '23 at 14:02