Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 不允许使用Apache Camel REST DSL 405方法_Spring_Rest_Apache Camel - Fatal编程技术网

Spring 不允许使用Apache Camel REST DSL 405方法

Spring 不允许使用Apache Camel REST DSL 405方法,spring,rest,apache-camel,Spring,Rest,Apache Camel,我目前正在使用ApacheCamel(使用Camel-spring)开发一个REST应用程序,并获得一些令人困惑的行为。我在RESTDSL中定义了一组端点,其中一些只是到另一台服务器的代理请求,另一些则传递到我为数据聚合定义的路由。DSL如下所示: <rest> <!-- Specific DSL requests --> <get uri="/v1/aggregate/data" consumes="application/json" produces="

我目前正在使用ApacheCamel(使用Camel-spring)开发一个REST应用程序,并获得一些令人困惑的行为。我在RESTDSL中定义了一组端点,其中一些只是到另一台服务器的代理请求,另一些则传递到我为数据聚合定义的路由。DSL如下所示:

<rest>
  <!-- Specific DSL requests -->
  <get uri="/v1/aggregate/data" consumes="application/json" produces="application/json">
    <to uri="direct:dataEnrichment" />
  </get>
  <get uri="/v1/customer/{custId}/devices" consumes="application/json" produces="application/json">
    <to uri="direct:getCustomerDevices" />
  </get>
  <get uri="/v1/login/{custId}" consumes="application/json" produces="application/json">
    <to uri="direct:getCustomer" />
  </get>
  <get uri="/v1/status" consumes="application/json" produces="application/json">
    <to uri="direct:statusInfo" />
  </get>

  <!-- Proxy requests -->
  <post uri="/v1?matchOnUriPrefix=true&amp;chunked=false">
    <to uri="direct:proxyOut" />
  </post>
  <get uri="/v1?matchOnUriPrefix=true&amp;chunked=false">
    <to uri="direct:proxyOut" />
  </get>
  <put uri="/v1?matchOnUriPrefix=true&amp;chunked=false">
    <to uri="direct:proxyOut" />
  </put>
  <delete uri="/v1?matchOnUriPrefix=true&amp;chunked=false">
    <to uri="direct:proxyOut" />
  </delete>
</rest>

其思想是,任何没有完全匹配URI的请求都会被代理到另一个系统(不是ApacheCamel)。这使我不用为其他系统上的每个RESTAPI编写定义(有很多)

所有这些都工作得很好,直到我在URI中添加了两个带有{custId}的请求。这些请求工作得很好,但每次我尝试一个应该被代理的URI时,我得到405方法是不允许的

编辑: 我还应该提到,我正在使用Jetty作为REST组件。Camel是独立运行的,使用org.apache.Camel.spring.Main启动它。我在这个阶段与邮递员联系,405的回应似乎来自Jetty/Camel

REST配置如下所示(安全处理程序正在使用Jetty BasicAuthenticator):


代理请求全部发送到direct:proxyOut路由,如下所示:

<route id="proxyOutbound">
  <description>A simple outbound route to proxy REST requests.</description>
  <from uri="direct:proxyOut" />
  <removeHeaders pattern="Authorization" />
  <to
    uri="http://{{remoteAddress}}/data/json?bridgeEndpoint=true&amp;throwExceptionOnFailure=false" />
</route>

到代理REST请求的简单出站路由。
其目的是在URI中/v1之后的所有内容都在代理请求中传递。我已经使用Wireshark进行了检查,请求未被代理。如果我删除路径中带有{custId}的路由,一切都会正常工作


我是做错了什么,还是这是camel/camel spring中的一个bug?

不清楚是谁返回405,是您调用的代理后端,还是根本不调用该后端

但是,当您通过Camel代理HTTP时,可能需要删除一些可能会干扰的
CamelHttp*

因此,尝试添加

 <removeHeaders pattern="CamelHttp*" />

骆驼虫,其详细信息可在此处找到:


类似的错误仍然存在,我在这里提交了一个:


我已经设法解决了我的问题,请参阅bugtracker中的我的评论

在任何人能够提供帮助之前为您的问题添加更多详细信息我也应该提到,我正在使用Jetty作为其余组件。Camel是独立运行的,使用org.apache.Camel.spring.Main启动它。您是否觉得缺少任何其他信息?谢谢。是的,当然,有很多细节,你从哪里得到405,你用什么打电话,那些代理路线你用什么直接打电话,等等。我在上面添加了一些更多的信息。如果还有什么事,请告诉我。嗨,克劳斯,谢谢你回复我。我试过了,但没什么不同。405响应来自camel,因为请求没有通过代理路由(我做了Wireshark跟踪以确保)。如果我删除路径中包含{custId}的两个“get”请求,其余的请求,包括代理请求,都可以正常工作。它归结为HttpServletResolvetConsumerStrategy.resolve(第30-52行,2.20.0版)。之所以如此,是因为定义了通配符URI。它匹配URI,但不做任何事情来匹配请求类型。我有多个端点具有相同的URI,但请求类型不同。我发送GET请求,但它总是首先匹配PUT候选项并返回该请求。当稍后在CamelContinuationServlet.doService(第111-125行)中对此进行检查时,候选类型和请求类型不匹配,返回405。你会说这是一个bug吗?
 <removeHeaders pattern="CamelHttp*" />