英文:
Ignore specific path in Http.inboundGateway
问题
我正在开发一个使用Spring Boot 2.7.7和Spring集成的应用程序,它作为一个webservice代理工作:将任何URL提供给webservice,根据一些业务规则将其转换为许多第三方服务之一的URL。
接受的URL不能明确列出。幸运的是,尽管inboundGateway文档没有明确提到,但实际上可以将Ant路径模式用作参数:
@Bean
public IntegrationFlow proxyFlow() {
...
return IntegrationFlows.from(Http.inboundGateway("/**")
... 处理/转换等等
.get();
}
代理本身正常工作,但我需要添加一个使用OpenAPI的Swagger UI。一旦添加到项目中,它会在http://<host>:<port>/<context-path>/v3/api-docs
下提供OAS文档,并在http://<host>:<port>/<context-path>/swagger-ui.html
下提供Swagger UI。
不幸的是,/swagger-ui.html
URL 无法访问,因为它被Http入站网关捕获,而令人惊讶的是/v3/api-docs
则没有被捕获(它是可以访问的)。
是否有一种方法可以告诉入站网关忽略此特定URL路径,同时接受所有其他路径?
英文:
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?
答案1
得分: 1
我不确定Swagger是如何配置在Spring中的,但让我们看看是否可以将这个Spring集成的内容降低到堆栈中。将这个bean添加到您的配置中:
@Bean(HttpContextUtils.HANDLER_MAPPING_BEAN_NAME)
static IntegrationRequestMappingHandlerMapping integrationRequestMappingHandlerMapping() {
IntegrationRequestMappingHandlerMapping handlerMapping = new IntegrationRequestMappingHandlerMapping();
handlerMapping.setOrder(Ordered.LOWEST_PRECEDENCE);
return handlerMapping;
}
基本上,我们需要覆盖在框架中应用的默认0
的order
。
您还可以尝试使用requestMapping(Consumer<RequestMappingSpec> mapping)
的一些其他选项,以尝试缩小映射规则。如果您的代理请求中有一些标头或参数可用,或者Swagger UI中有一些可用。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论