3
votes

I'm currently developing a REST Application with Apache Camel (using camel-spring), and getting some confusing behaviour. I have a set of endpoints defined in REST DSL, some are simply proxy requests to another server, and some others are passed on to routes I've defined for data aggregation. The DSL looks as follows:

<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>

The idea is that any requests with no exact matching URI get proxied through to another system (which is not Apache Camel). This saves me having to write a definition for every REST API on the other system (there are a lot).

All was working well, until I added the two requests with {custId} in the URI. Those requests work fine, but every time I try a URI that should get proxied through, I get 405 Method Not Allowed.

EDIT: I should also have mentioned that I'm using Jetty as the REST component. Camel is running stand-alone, using org.apache.camel.spring.Main to start it up. I'm calling it with Postman at this stage, and the 405 response appears to be coming from Jetty/Camel.

The REST configuration looks like this (The security handler is using the 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>

The Proxy requests all send to the direct:proxyOut route, which looks like this:

<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>

The intention is that everything after the /v1 in the URI is passed over in the proxied request. I've checked using Wireshark, and the request is not getting proxied. If I remove the routes with {custId} in the path, everything works fine.

Am I doing something wrong or is this a bug in camel/camel-spring?

3
Add more details to your question before anyone can helpClaus Ibsen
I should also have mentioned, I am using Jetty as the rest component. Camel is running stand-alone, using org.apache.camel.spring.Main to start it up.Robert Hillier
Was there any other information you feel is missing? Thanks.Robert Hillier
Yeah surely, there is many details, where do you get 405, what do you call with, what does those proxy routes do you call via direct, and so on and so on ..Claus Ibsen
I've added some more information above. If there's anything else, please let me know.Robert Hillier

3 Answers

1
votes
0
votes

Its not clear whom is returning 405, is it the proxied backend you call, or does it not call that backend at all.

However when you proxy HTTP via Camel, then you may need to remove some CamelHttp* headers that can interfere.

So try adding

 <removeHeaders pattern="CamelHttp*" />
0
votes

The similar bug is still in place, I've filed one here:

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

I've managed to make a workaround for my case, see my comment in the bugtracker