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 
http://camel.465427.n5.nabble.com/file/n3317027/CamelCXF_HeaderIPIssue.zip
attachment . The beans for the interceptors were added to camel-cxf.xml as
follows:

        <bean id="preStreamIPInterceptor"
class="com.company.interceptor.PreStreamIPInterceptor"/>
        <bean id="readIPInterceptor"
class="com.company.interceptor.ReadIPInterceptor"/>
        <bean id="receiveIPInterceptor"
class="com.company.interceptor.ReceiveIPInterceptor"/>

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="http://cxf.apache.org/core"; since I was already using cxf for
"http://camel.apache.org/schema/cxf";.

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 
http://willemjiang.blogspot.com/2010/02/configure-camel-cxf-endpoint-advance.html
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 
https://cwiki.apache.org/CXF20DOC/configuration.html
https://cwiki.apache.org/CXF20DOC/configuration.html . 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 
http://camel.apache.org/cxf.html#CXF-ChangessinceRelease2.0
http://camel.apache.org/cxf.html#CXF-ChangessinceRelease2.0 

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.

Key=org.apache.cxf.security.SecurityContext, 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
-- 
View this message in context: 
http://camel.465427.n5.nabble.com/Extracting-request-IP-in-Camel-CXF-tp3308148p3317027.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to