Integrating Apache Camel CXF-RS + CXF Jax-RS OAuth

I am using Apache Camel with CXF-RS using the standard integration provided by Camel (using an embedded Jetty in executable JAR) and it works perfectly.

I want to add OAuth support (as OAuth 1 provider) to my REST server, as I am already using CXF, I plan to use CXF JAX-RS OAuth integration on it: http://cxf.apache.org/docs/jax-rs-oauth.html

Unfortunately, it seems I need to use a servlet for OAuth support and I am struggling to add this before the call of my Camel Processor. As my route is defined by:

String CONTEXT = "?resourceClasses=" + MyServiceResource.class.getName();
final String cxfRSEndpointUri = "cxfrs://http://" + restServerUrl + ":" + restServerPort + CONTEXT;
from(cxfRSEndpointUri).process(restProcessor);

From the processor point of view (restProcessor), I can't get a HttpServletRequest and a HttpServletResponse from the Exchange object, the cxfrs route don't give me correct bodies:

final HttpServletRequest request = exchange.getIn().getBody(HttpServletRequest.class);
final HttpServletResponse response = exchange.getOut().getBody(HttpServletResponse.class);

These two commands return null: cxfrs is not like a classic Camel HTTP route.

Is there a way to configure a Camel Route that would add a servlet filter (OAuthServletFilter given by CXF JAX-RS OAuth) before using the cxfrs route?

The other way I see is to check the sources of CXF JAX-RS OAuth: the class AbstractAuthFilter.java contains the implementation of the checks needed by OAuth, but if possible I prefer not to fork a part of this class, and it would require me to check HTTP headers / values from the exchange object given by camel manually. I believe there should be a better way to do so, but maybe I am wrong.

Answers


I finally made it work cleanly: I don't use a "cxfrs:http..." route but instead a "cxfrs:bean:rsServer..." route.

It enables me to define in Spring a CXFRS server bean in which I can add an OAuthRequestFilter to it. Then I reference it in my Camel route and it works!


Need Your Help

How to mapp an array to a complex type using Dozer

java dozer

I am using Dozer to map some beans, and I have a mapping that I can't figure out.