camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Willem Jiang <>
Subject Fwd: Re: Extracting request IP in Camel CXF
Date Mon, 27 Dec 2010 02:52:09 GMT
FYI, I committed a patch into Camel trunk, you can use the below codes 
With the latest Camel 2.6-SNAPSHOT.


-------- Original Message --------
Subject: Re: Extracting request IP in Camel CXF
Date: Fri, 24 Dec 2010 12:47:41 +0800
From: Willem Jiang <>

It's really a long answer for current solution of camel-cxf.
I think we can add a entry of in the camel message header to let people
access the CXFMessage contents from Camel message header.
That could be more easy to get the request remote IP by these same two lines

org.apache.cxf.message.Message cxfMessage = 
ServletRequest request = (ServletRequest)cxfMessage.get("HTTP.REQUEST");
String remoteAddress = request.getRemoteAddr();


On 12/24/10 5:49 AM, wrote:
> That was sort of helpful Ashwin, thanks. Your long answer did get me to
> explore the world of interceptors, but I am sorry to report that I still
> don't see the remote IP address.
> Here's what I did:
> 1) Create interceptors. I tried PRE_STREAM, but that didn't work so I just
> created two more, one each for RECEIVE and READ. This is all simple java
> code and is included in the
> attachment . The beans for the interceptors were added to camel-cxf.xml as
> follows:
> 	<bean id="preStreamIPInterceptor"
> class=""/>
> 	<bean id="readIPInterceptor"
> class=""/>
> 	<bean id="receiveIPInterceptor"
> class=""/>
> 2) Add the interceptors to the bus as follows:
>      <cxf-core:bus>
>          <cxf-core:inInterceptors>
>              <ref bean="receiveIPInterceptor"/>
>              <ref bean="preStreamIPInterceptor"/>
>              <ref bean="readIPInterceptor"/>
>          </cxf-core:inInterceptors>
>      </cxf-core:bus>
> I ended up having to use the namespace of
> cxf-core="" since I was already using cxf for
> "".
> 3) Inject the bus into the camel-cxf consumer endpoint: I couldn't find the
> "id" attribute on the cxf-core:bus tag. So I tried the following variations
> and I got the same results with each variation:
>      3.1) Do not inject the bus into the camel-cxf consumer endpoint
>      3.2) Inject the bus with a "presumed" ID of "Cxf" in camel-context.xml
> as follows:
>             <camel:from uri="cxf:bean:wsEndpoint?Bus=#Cxf" />
>             I got this idea from
> Willem's blog , although I must admit that I am not sure that's what he
> meant.
>      3.3) Specify the bus as a bean as described in the Enabling message
> logging using plain Spring bean elements section of
> . And then use the "id"
> specified here as the parameter in the uri. This would make the
> configuration in camel-context.xml identical to what you had suggested in
> <camel:from uri="cxf:bean:wsEndpoint?bus=#myCustomBus" />
>       3.4) Directly add the interceptors in the cxf:endpoint defined in
> camel-cxf.xml as described in the How to let camel-cxf response message with
> xml start document section of
> Irrespective, the result is the same in all cases. I put a breakpoint in
> each of my interceptors,  and the breakpoint was hit for each of the above
> methods.
> The problem is that once I hit the breakpoint and have access to the
> org.apache.cxf.message.Message object, I can't find the remote IP address in
> that object. Using my Eclipse's debugger, I looked into the Message object
> and noticed that it had the following two entries in its HashMap that are of
> interest to me:
> Key=HTTP.REQUEST, Value=Object of type org.mortbay.jetty.Request
> This Request object has the members "_remoteAddr" and "_remoteHost" but both
> are null.
>, Value=Object of type
> org.apache.cxf.transport.http.AbstractHTTPDestination$2
> Again, this object has the members "_remoteAddr" and "_remoteHost" but both
> are null here too.
> So conceptually, the interceptors make perfect sense. Adding the
> interceptors to the Bus and/or to the cxf endpoint also makes sense. Its
> just that I am unsure of the configuration, and even when my execution flow
> comes to the interceptor, I can't seem to find the IP address I am looking
> for.
> Oh, and I am looking to do exactly what you guessed: "allow/disallow
> requests based on IP address". This seems like a run-of-the-mill task and
> would seem like many people would have accomplished it already. I am hoping
> that someone will be able to pinpoint the exact piece of the puzzle that I
> am missing.
> Thanks again for your time and effort.
> Abhishek

Blog: (English)
Twitter: willemjiang

View raw message