【问题标题】:Apache Camel - Spring rest endpoint referenceApache Camel - Spring 休息端点参考
【发布时间】:2017-06-15 06:45:05
【问题描述】:

我有一个使用骆驼休息组件的应用程序。原来我使用camel版本v2.17.0,调用时每个rest端点都返回http返回码200。

有一天,当我将应用程序的骆驼版本更新到 v2.18.0(没有任何其他更改)时,所有 rest 端点在调用时都返回 http 返回代码 404。同样的情况也发生在 v2.18.4 和 v2.19.0 上。

我怀疑通过 Spring 的 rest 端点路径引用是否发生了变化。有谁知道如何纠正我的设置?我正在使用的解决方法是将硬编码字符串移回 Spring,这不符合我的意图。

Rest Service 的 Spring 设置

<endpoint id="httpAppRouteBuildRemainPath" uri="#{commonUtilService.getEpUtil().getHTTPAppJsonBuildRemainPath()}" />
<endpoint id="httpSysRouteBuildRemainPath" uri="#{commonUtilService.getEpUtil().getHTTPSysJsonBuildRemainPath()}" />
<endpoint id="httpJsonBuildManagementRouteEndPoint" uri="#{commonUtilService.getEpUtil().getHTTPJsonBuildManagementRouteEndpointPath()}" />

<rest path="#commonUtilService.getEpUtil().getHTTPJsonManagementRestPath()">
        <put uri="ref:httpAppRouteBuildRemainPath" id="appHttpRouteReceiver">
                <to uri="ref:httpJsonBuildManagementRouteEndPoint"/>
        </put>
        <put uri="ref:httpSysRouteBuildRemainPath" id="sysHttpRouteReceiver">
                <to uri="ref:httpJsonBuildManagementRouteEndPoint"/>
        </put>
</rest>

Java 设置

public String getHTTPJsonManagementRestPath() {
        return "/worker/json";
}

public String getHTTPAppJsonBuildRemainPath() {
        return "/app/build";
}

public String getHTTPSysJsonBuildRemainPath() {
        return "/sys/build";
} 

测试结果

骆驼版v2.17.0下

2017 年 6 月 7 日上午 11:10:16 org.restlet.engine.log.LogFilter afterHandle

信息:2017-06-07 11:10:16 0:0:0:0:0:0:0:1 - - 9395 PUT /worker/json/app/build - 200 40 124 35 http://localhost:9395 - -

骆驼版v2.18.0下

2017 年 6 月 7 日上午 11:11:33 org.restlet.routing.Template getRegexPattern

警告:不允许使用空模式变量:null 2017 年 6 月 7 日上午 11:11:33 org.restlet.routing.Template getRegexPattern

警告:不允许使用空模式变量:null 2017 年 6 月 7 日上午 11:11:33 org.restlet.routing.Template getRegexPattern

警告:不允许使用空模式变量:null 2017 年 6 月 7 日上午 11:11:33 org.restlet.routing.Template getRegexPattern

警告:不允许使用空模式变量:null 2017 年 6 月 7 日上午 11:11:33 org.restlet.engine.log.LogFilter afterHandle

信息:2017-06-07 11:11:33 0:0:0:0:0:0:0:1 - - 9395 PUT /worker/json/app/build - 404 439 124 12 http://localhost:9395 - -


更新

我将弹簧设置更改为

<rest path="/worker/json">
    <put uri="/app/build" id="appHttpRouteReceiver">
        <to uri="ref:httpJsonBuildManagementRouteEndPoint"/>
    </put>
    <put uri="ref:httpSysRouteBuildRemainPath" id="sysHttpRouteReceiver">
        <to uri="ref:httpJsonBuildManagementRouteEndPoint"/>
    </put>
</rest>

测试结果

骆驼版v2.18.0下

2017 年 6 月 26 日上午 10:12:50 org.restlet.engine.log.LogFilter afterHandle

INFO: 2017-06-26 10:12:50 0:0:0:0:0:0:0:1 - - 9395 PUT /worker/json/ref:httpSysRouteBuildRemainPath - 200 61 46 39 http://localhost:9395 - -

2017 年 6 月 26 日上午 10:14:54 org.restlet.engine.log.LogFilter afterHandle

信息:2017-06-26 10:14:54 0:0:0:0:0:0:0:1 - - 9395 PUT /worker/json/app/build - 200 61 40 18 http://localhost:9395 Jakarta Commons-HttpClient/3.1 -

2017 年 6 月 26 日上午 10:18:53 org.restlet.engine.log.LogFilter afterHandle

信息:2017-06-26 10:18:53 0:0:0:0:0:0:0:1 - - 9395 PUT /worker/json/sys/build - 404 439 40 6 http://localhost:9395 Jakarta Commons-HttpClient/3.1 -

【问题讨论】:

  • 你有 2 x put 最终会得到相同的路径,你应该使用不同的路径或只有 1 个 put
  • @ClausIbsen 看起来其余端点使用 ref:httpSysRouteBuildRemainPath 作为路径而不是查找端点引用。有什么方法可以从 Java 端设置值吗?
  • 使用{{xxx}} 作为属性占位符:camel.apache.org/using-propertyplaceholder.html
  • @ClausIbsen 谢谢,但属性占位符不符合我的目的。当我将原始设置为第二个将 uri 设置为 &lt;post uri="#{commonUtilService.getEpUtil().getAdminHTTPSysJsonBuildRemainPath()}" id="admin_sysHttpSysJson_receiver"&gt; 时它可以工作,但当我将其提取为端点引用时它不起作用

标签: java spring rest apache-camel


【解决方案1】:

我记录了一张票来调查这个:https://issues.apache.org/jira/browse/CAMEL-11414

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-08
    • 1970-01-01
    • 1970-01-01
    • 2015-01-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多