我有一个简单的 Camel Route,它处理传入的 Http 请求,然后根据资源路径路由到其他 Http 消费者。一切正常,但我在路径中使用空格时遇到了 java.net.URISyntaxException: Illegal character in path 。其他特殊字符似乎工作正常。
我正在构建一个 RESTful API,目前正在使用浏览器来测试我的 API。
这是我的路线的 Spring DSL:
<route id="API">
<from uri="jetty:http://0.0.0.0/api?matchOnUriPrefix=true"/>
<bean ref="basicAuthBean"/>
<choice>
<when>
<simple>${in.header.CamelHttpPath} contains 'blah1'</simple>
<to uri="http://localhost:10001/api?bridgeEndpoint=true&throwExceptionOnFailure=false"/>
</when>
<when>
<simple>${in.header.CamelHttpPath} contains 'blah2'</simple>
<to uri="http://localhost:10002/api?bridgeEndpoint=true&throwExceptionOnFailure=false"/>
</when>
</choice>
</route>
我在 Camel Context 上启用了跟踪,发现 CamelHttpPath 已经用空格替换了转义字符“%20”。我还看到有没有逃脱特殊字符的 CamelHttpUri。
作为我的 Spring DSL 中的一个 hack,我在选择元素之前添加了以下内容:
<setHeader headerName="CamelHttpPath">
<simple>${in.header.CamelHttpUri}</simple>
</setHeader>
这解决了我的问题,但我很确定有更好的方法来做到这一点。我错过了设置某些属性还是我的路由 DSL 不准确?
另外,CamelHttpPath 和 CamelHttpUri 有什么区别?
我还应该提到我在 Apache ServiceMix 4.4.2 中使用 Camel 上下文,使用的 Camel 版本是 2.8.5。
在此先感谢您的帮助!