0

我有一个简单的 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&amp;throwExceptionOnFailure=false"/>
     </when>
      <when>
       <simple>${in.header.CamelHttpPath} contains 'blah2'</simple>
       <to uri="http://localhost:10002/api?bridgeEndpoint=true&amp;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。

在此先感谢您的帮助!

4

1 回答 1

1

我想我们已经在以后的 Camel 版本中修复了这个问题,因为它会像 Camel 2.10.4 等一样发布。我记得在那个空间修复上工作。 https://issues.apache.org/jira/browse/CAMEL-5504

由于不再支持 Camel 2.8.x,您需要自己修补问题。或者升级到包含 Camel 2.10.3 的 ServiceMix 4.5.0。

于 2013-02-16T08:13:42.923 回答