camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <>
Subject Re: Obtain CXF Request?
Date Tue, 06 Nov 2012 14:12:31 GMT

On 06/11/12 14:02, Calvert, Zach (Zach)** CTR ** wrote:
> I am stuck using Camel CXF 2.6.0 (yes, I know I'm behind) and need to get the IP address
of the remote system making an HTTP POST to my cxfbean:
>          <!-- Define the camel route -->
>          <camel:route id="restApis">
>              <camel:from uri="jetty:{{protocol}}://{{port}}/rest/?matchOnUriPrefix=true&amp;handlers=securityHandler"/>
>              <camel:to uri="cxfbean:restfulService?providers=#restExceptionMapper"
>              <camel:log message="done"/>
>          </camel:route>
> My restfulService handles the posts.  When I turn on tracing, I see
> 07:10:29,783 | INFO  | qtp26579196-144  | Tracer                           | 76 - org.apache.camel.camel-core
- 2.6.0 | ID-centora-45480-1352207331927-4-1>>>  (restApis) from(
-->  restfulService<<<  Pattern:InOut, Headers:{, CamelHttpMethod=POST,
CamelHttpServletRequest=[POST /rest/domain/feed]@19570394 org.eclipse.jetty.server.Request@12a9eda,
Accept-Encoding=gzip,deflate, CamelHttpServletResponse=HTTP/1.1 200
> In my bean I have the function
>      @POST
>      @Path("{domainName}/{domainChild}")
>      public Response post(@PathParam("domainName") String domainName,
>              @PathParam("domainChild") String domainChildName,
>              JAXBElement<RestXml>  restXml) {
> ...
> }
> I have tried to add the parameter Exchange (camel), Exchange (cxf), Message, etc all
to no avail due to no longer having a mapping for my sample test post.  I want to know if
there is a way for me to access that header "CamelHttpServletRequest" inside of this bean's
function?  My end goal is simply to get the HttpRequest or ServletRequest or whatever request
that will have the "getRemoteAddress" function exposed on it.  I've been through the jaxrs
core annotations and cannot seem to figure out how to get a handle to the original incoming
request, or any context object that may contain the IP address of whoever is making the call
to my servlet.  I thought maybe UriInfo or Request (from contexts would
have the info I'm looking for, but if they do, I can't figure them out.
> I have also looked at building a custom provider, but I can't figure out how to build
one that not only gets the IP address, but manages to provide it along the route to my cxfbean.
 Is there a way I can do something like get the IP and then set it as a QueryParam for my
bean to consume?
> Any and all help would be greatly appreciated!

Injection "@Context HttpServletRequest" into the bean itself is one 
option. Another one is to inject it into a RequestFilter provider and 
update (CXF) Message.QUERY_STRING accordingly - this will let you add 
@QueryParam("remoteip") to the method signature

HTH, Sergey

> Thanks,
> Zach Calvert

Sergey Beryozkin

Talend Community Coders


View raw message