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

标签 spring rest apache-camel

我目前正在使用 Apache Camel(使用 camel-spring)开发 REST 应用程序,并出现一些令人困惑的行为。我在 REST DSL 中定义了一组端点,其中一些只是对另一台服务器的代理请求,而另一些则传递到我为数据聚合定义的路由。 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 的请求都会被代理到另一个系统(不是 Apache Camel)。这使我不必为另一个系统上的每个 REST API 编写定义(有很多)。

一切都运行良好,直到我在 URI 中添加了带有 {custId} 的两个请求。这些请求工作正常,但每次我尝试应该通过代理的 URI 时,我都会收到 405 Method Not Allowed。

编辑: 我还应该提到我正在使用 Jetty 作为 REST 组件。 Camel 独立运行,使用 org.apache.camel.spring.Main 启动它。我在这个阶段用 Postman 调用它,405 响应似乎来自 Jetty/Camel。

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

<restConfiguration contextPath="/mobilegateway/api" scheme="http"
  host="0.0.0.0" bindingMode="off"
  enableCORS="true"
  component="jetty" port="8079">
  <endpointProperty key="handlers" value="securityHandler" />
  <endpointProperty key="sessionSupport" value="true" />
  <endpointProperty key="httpClient.idleTimeout" value="30000" />

</restConfiguration>

Proxy 请求全部发送到 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>

目的是在代理请求中传递 URI 中/v1 之后的所有内容。我已经使用 Wireshark 检查过,请求没有被代理。如果我删除路径中带有 {custId} 的路由,一切正常。

我是做错了什么还是 camel/camel-spring 中的错误?

最佳答案

Camel 虫,详情可以在这里找到:

https://issues.apache.org/jira/browse/CAMEL-11951

关于spring - 不允许使用 Apache Camel REST DSL 405 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46936348/

相关文章:

java - 使用 Java 使用来自 RESTful Web 服务的 json 字符串结果填充 jtable

python - 如何在 Django REST 框架中使用事务?

spring - 使用 hibernate 验证器 XML 配置和 Spring 自动验证

java - 带有 MySQL 数据库的 spring-data-elasticsearch

java - 当 SpringSecurity 找不到传入 token 时,阻止 SpringSecurity 发送自动 401

java - 使用 apache camel 从 xml 转换时,'@' 符号出现在输出 json 中

java - camel-cdi 中的异步事件

javascript - 在javascript中使用http请求下载文件

java - 如何从 Java 在 AWS 中生成签名

java - Apache Camel 。 throttle 部分路线