如何在camel路由中使用上下文路径?

q7solyqu  于 2021-07-08  发布在  Java
关注(0)|答案(1)|浏览(331)

我是 Camel 队的新手。我正在做一个项目,在 Spring 开机使用 Camel 路线。我注意到,当我去swaggerui查看post调用的正确功能时,路由的contextpath不起作用:

public void configure() {

        restConfiguration().component("servlet").contextPath("service/");

        rest("/ocs")
            .post("/homologation")
                .id(camelRoutesIdConfig.getHomologationRequestRouteId())
                .consumes("application/json")
                .produces("application/json")
                .param()
                    .name("IntegrationRequestDto")
                    .type(RestParamType.body)
                    .required(true)
                    .description("attivazione nuovo contratto sul portale")
                .endParam()
                .to("direct:homologation")

}

如果在application.yml中指定如下上下文路径,则不会出现此问题:

camel:
  rest:
    component: servlet
    binding-mode: json
    enable-cors: true
    data-format-property:
      prettyPrint: false
     component:
    servlet:
      mapping:
        context-path: /service/*

在一种情况下,当我使用call post时,它可以工作,而在routes中使用contextpath时,它无法识别命令并发出命令

{
  "timestamp": "2020-11-22T17:44:26.701+0000",
  "status": 404,
  "error": "Not Found",
  "message": "Not Found",
  "path": "/service/ocs/homologation"
}

为什么会有这个问题?为什么我还要在application.yml中指定,而不是在routes中只使用一次?谢谢大家的回答

ca1c2owp

ca1c2owp1#

它这样工作是对的。restconfiguration中的contextpath配置用于纯xmlapi文档。要激活通话中的contextpath,请获取、发布、放置。。。您需要在application.properties中指定它。apachecamel关于使用servlet的文档可能会对您有所帮助

相关问题