You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "goelshek@yahoo.com" <go...@yahoo.com> on 2010/12/16 17:07:12 UTC

Extracting request IP in Camel CXF

Hi,

When I used a standalone CXF web service, I used to be able to extract the
remote IP address in my Impl class. CXF would inject a WebServiceContext
object in my Impl class and I would have the class as follows:

<code>
public class MyWSImpl implements IMyWS {
	@Resource
	private WebServiceContext context;
   
        public String foo( String message ) {
              System.out.println(
                        ( (HttpServletRequest) context.getMessageContext()
                        .get(AbstractHTTPDestination.HTTP_REQUEST) )
                        .getRemoteAddr();
              return "true";
         }
}
</code>

However, now I have made my web service a part of the an architecture where
the web service is simply an endpoint in Camel. Now Camel starts my web
service for me by virtue of making the WS endpoint be a part of a camel
route. As a result, I don't have my Impl class anymore.

The cxf web service endpoint in Camel is as follows:

<code>
	<cxf:cxfEndpoint id="myWsEndpoint" 
					 address="http://192.168.0.1:9000/MyWS"
					 serviceClass="com.company.service.IMyWS" 
					 serviceName="e:MyWS" 
					 endpointName="e:MyWS" 
					 xmlns:e="http://service.company.com/" >
	</cxf:cxfEndpoint>
</code>

And then this endpoint is a part of the camel route as follows:

<code>
		<camel:route id="WsXmlMessagesRoute">
			<camel:from uri="cxf:bean:myWsEndpoint" />
			<camel:process ref="testProcessor"/>
			<camel:inOnly uri="file:data/inbox" />
</code>

A request comes into my web service endpoint, gets forwarded to a Processor
and then gets written out to a file. The processor is a simple Java file
that has the following method:

public void process(Exchange exchange)

I would like to be able to extract the IP address of whoever invoked my web
service in this processor.

It seems that the IP address has to be hidden somewhere in the "exchange"
object that comes into the process method. I have spent multiple hours
trying to figure out how to extract the IP address, but have been
unsuccessful.

I looked for a solution on this forum, but couldn't find anything here
either.

Can anyone please guide me? Any help will be greatly appreciated.

Thanks.

Abhishek
-- 
View this message in context: http://camel.465427.n5.nabble.com/Extracting-request-IP-in-Camel-CXF-tp3308148p3308148.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Extracting request IP in Camel CXF

Posted by Willem Jiang <wi...@gmail.com>.
Which version of Camel are you using ?

On 12/22/10 8:11 AM, goelshek@yahoo.com wrote:
>
> Thanks for the response Ashwin, but I am unable to find the "HTTP.REQUEST"
> header in the exchange object.
>
> My process() method is as follows:
>
> public void process (Exchange exchange)
> {
>      Map<String, Object>  headers = exchange.getIn().getHeaders();
>
>      // loop through the headers object above and print out all the keys
> }
>
> I don't see "HTTP.REQUEST" as one of the keys in the map. I do see a key
> named "org.apache.cxf.headers.Header.list" but when I print out its value,
> the list is empty.
>
> Theoretically, what you said makes perfect sense in that "Protocol headers
> in CXF are propagated to Camel exchanges as Camel Header entries". However,
> I don't see those headers in the exchange or don't know how to access them.
>
> I don't know of a filter strategy that would prevent the headers from being
> propagated.
>
> Can you possibly provide some more guidance as to how do I go about
> extracting the "HTTP.REQUEST" header?
>
> Thanks.
>
> Abhishek


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang

Re: Extracting request IP in Camel CXF

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hi,

There is no id for the cxf:bus element. Any Spring cxf:bus automatically
overrides the default bus.

However you can also do the following

	<bean id="cxf" class="org.apache.cxf.bus.CXFBusImpl">
		<property name="inInterceptors">
			<list>
		             <ref bean="receiveIPInterceptor"/> 
                             <ref bean="preStreamIPInterceptor"/> 
                             <ref bean="readIPInterceptor"/>
			</list>
		</property>
	</bean>

Then you can add the new bus "cxf" to the camel endpoint as <camel:from
uri="cxf:bean:wsEndpoint?Bus=#cxf" />

Hope this helps.

Cheers,

Ashwin... 

-----
---------------------------------------------------------
Ashwin Karpe
Apache Camel Committer & Sr Principal Consultant
FUSESource (a Progress Software Corporation subsidiary)
http://fusesource.com http://fusesource.com 

Blog: http://opensourceknowledge.blogspot.com
http://opensourceknowledge.blogspot.com 
---------------------------------------------------------
-- 
View this message in context: http://camel.465427.n5.nabble.com/Extracting-request-IP-in-Camel-CXF-tp3308148p3318272.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Extracting request IP in Camel CXF

Posted by "goelshek@yahoo.com" <go...@yahoo.com>.
I am using camel-core-2.5.0.jar, camel-cxf-2.5.0.jar and cxf-api-2.2.11.jar.

I am now able to get the remoteAddress using the Request.getRemoteAddress()
method. Earlier I was making the mistake of looking at the "_remoteAddress"
variable using my debugger instead of actually invoking the method
getRemoteAddress(). When I looked into the source code of
getRemoteAddress(), I noticed that if "_remoteAddress" was null,
_endp.getRemoteAddress() was being invoked.
-- 
View this message in context: http://camel.465427.n5.nabble.com/Extracting-request-IP-in-Camel-CXF-tp3308148p3326187.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Extracting request IP in Camel CXF

Posted by Willem Jiang <wi...@gmail.com>.
Which version of CXF are your testing with?
I'm using CXF 2.3.1 within Camel 2.6-SNAPSHOT, I can get the 
remoteAddress without any trouble.

Here is the unit test[1] that you may have a look.
[1]https://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerTest.java

On 12/31/10 1:16 AM, goelshek@yahoo.com wrote:
>
> Got it!
>
> Thanks Willem.
>
> Here is what I was doing wrong: In the handleMessage method of my
> interceptor, I was inspecting the message object using the debugger. It DID
> contain the HTTP.REQUEST header as I mentioned earlier, but the
> _remoteAddress variable in the Request object was null. The IP address is
> actually stored in the "_endp" member of the Request object.
>
> So, as per your suggestion, I added the following two lines at the beginning
> of my handleMessage method in the interceptor
>
> <code>
> 		org.mortbay.jetty.Request jettyRequest =
> (org.mortbay.jetty.Request)message.get("HTTP.REQUEST");
> 		System.out.println("jettyRequest.getRemoteAddr(): " +
> jettyRequest.getRemoteAddr());
> </code>
>
> and when I step into the getRemoteAddr() method of the Request object, I see
> that _remoteAddr is null and therefore _endp.getRemoteAddr() is invoked.
>
> It was just a matter of knowing exactly what stores the IP address and how
> to extract it.
>
> Thanks for your help.
>
> Abhishek


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang

Re: Extracting request IP in Camel CXF

Posted by "goelshek@yahoo.com" <go...@yahoo.com>.
Got it!

Thanks Willem.

Here is what I was doing wrong: In the handleMessage method of my
interceptor, I was inspecting the message object using the debugger. It DID
contain the HTTP.REQUEST header as I mentioned earlier, but the
_remoteAddress variable in the Request object was null. The IP address is
actually stored in the "_endp" member of the Request object.

So, as per your suggestion, I added the following two lines at the beginning
of my handleMessage method in the interceptor

<code>
		org.mortbay.jetty.Request jettyRequest =
(org.mortbay.jetty.Request)message.get("HTTP.REQUEST");
		System.out.println("jettyRequest.getRemoteAddr(): " +
jettyRequest.getRemoteAddr());
</code>

and when I step into the getRemoteAddr() method of the Request object, I see
that _remoteAddr is null and therefore _endp.getRemoteAddr() is invoked.

It was just a matter of knowing exactly what stores the IP address and how
to extract it.

Thanks for your help.

Abhishek
-- 
View this message in context: http://camel.465427.n5.nabble.com/Extracting-request-IP-in-Camel-CXF-tp3308148p3322673.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Extracting request IP in Camel CXF

Posted by Willem Jiang <wi...@gmail.com>.
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 cxfMessage = camelMessage.getHeader("CXF_MESSAGE");
ServletRequest request = (ServletRequest)cxfMessage.get("HTTP.REQUEST");
String remoteAddress = request.getRemoteAddr();

Willem

On 12/24/10 5:49 AM, goelshek@yahoo.com 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
> 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


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang

Re: Extracting request IP in Camel CXF

Posted by "goelshek@yahoo.com" <go...@yahoo.com>.
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.

Re: using multiple activemq components

Posted by Willem Jiang <wi...@gmail.com>.
On 12/23/10 12:39 PM, Michael La Budde wrote:
>
> I have a question regarding the route syntax to use if I need to use more than one instance of the ActiveMQComponent.
>
> Here is my spring config file that I hope will work:
>
>      <bean id="activemq-out" class="org.apache.activemq.camel.component.ActiveMQComponent">
>          <property name="configuration" ref="jmsConfig"/>
>      </bean>
>
>
>      <bean id="activemq-in" class="org.apache.activemq.camel.component.ActiveMQComponent">
>          <property name="brokerURL">
>              <value>tcp://10.0.0.25:61616?jms.prefectPolicy=1</value>
>          </property>
>      </bean>
>
> The "activemq-out" bean would only be used to publish messages - to take advantage of pooling.
> The "activemq-in" bean would only be used to listen for messages.
>
> So, would this be the correct route specification?
>
> <route>
>
>      <from uri="activemq-in:MyCompany.Incoming?concurrentConsumers=5"/>
>
>      <to uri="bean:myBean"/>
>
>
> </route>
>
>
>
>
> <route>
>
>      <from uri="direct:bean:MyPublisher"/>
>
>
>
>      <to uri="activemq-out:MyCompany.VitalMessage"/>
>
>
> </route>
>
>
This route configure looks good to me.

>
>
>
> I should probably ask this in a separate post, but here goes:
>
> I would like to be able to take advantage of setting DestinationOptions using ActiveMQ. Here is an example from their website:
>
>
> Example
>
>
> queue = new ActiveMQQueue("TEST.QUEUE?consumer.dispatchAsync=false&consumer.prefetchSize=10");
> consumer = session.createConsumer(queue);
>
>
> Is there a way using Camel to pass this through to ActiveMQ?
>
No, I don't think current camel-activemq component support the 
DestinationOptions of the ActiveMQ. You can find camel-activemq supports 
options here[1]

[1]http://camel.apache.org/jms.html#JMS-Options

> TIA,
>
> Mike L. (aka patzerbud)
>
>   		 	   		


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang

using multiple activemq components

Posted by Michael La Budde <pa...@hotmail.com>.
I have a question regarding the route syntax to use if I need to use more than one instance of the ActiveMQComponent. 

Here is my spring config file that I hope will work: 

    <bean id="activemq-out" class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="configuration" ref="jmsConfig"/>
    </bean>


    <bean id="activemq-in" class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="brokerURL">
            <value>tcp://10.0.0.25:61616?jms.prefectPolicy=1</value>
        </property>
    </bean>

The "activemq-out" bean would only be used to publish messages - to take advantage of pooling.
The "activemq-in" bean would only be used to listen for messages.

So, would this be the correct route specification?

<route>

    <from uri="activemq-in:MyCompany.Incoming?concurrentConsumers=5"/>

    <to uri="bean:myBean"/>


</route>




<route>

    <from uri="direct:bean:MyPublisher"/>



    <to uri="activemq-out:MyCompany.VitalMessage"/>


</route>





I should probably ask this in a separate post, but here goes:

I would like to be able to take advantage of setting DestinationOptions using ActiveMQ. Here is an example from their website: 


Example


queue = new ActiveMQQueue("TEST.QUEUE?consumer.dispatchAsync=false&consumer.prefetchSize=10");
consumer = session.createConsumer(queue);


Is there a way using Camel to pass this through to ActiveMQ?

TIA,

Mike L. (aka patzerbud)

 		 	   		  

Re: Extracting request IP in Camel CXF

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hi,

If the IP address is in a SOAP Header, can you please try the following

1. Add a HeaderFilterStrategy bean in camel-context.xml as shown below

<bean id="foobar"
class="org.apache.camel.component.cxf.CxfHeaderFilterStrategy">
    <property name="relayAllMessageHeaders" value="true"/>
</bean>

2. Add this id to your camel-cxf endpoint as shown below

	<camel:route id="wsXmlMessagesRoute">
			<camel:from uri="cxf:bean:wsEndpoint?headerFilterStrategy=#foobar" />
			<camel:process ref="testProcessor"/>
			<camel:inOnly uri="file://test_files" />
		</camel:route>	

You might want to check out the section "Changes since Release 2.0" in the
documentation  http://camel.apache.org/cxf.html
http://camel.apache.org/cxf.html  It covers in-band and out-of-band headers
and how they are propagated in camel-cxf.

BTW, I checked out the code in 2.5.0 and it should be passing along the
headers. I suspect based on the fact that the MessageContentList Header
entry is an empty list that CXF is for some reason not passing headers
along. 

I am not sure if the IP address is passed in the HTTP headers and not SOAP
Headers. If so, the way to get at an IP address embedded in HTTP headers
surrounding the SOAP Headers, however this involves instantiating a CXF bus
object, adding an in-interceptor in the PRE_STREAM phase to get at the
header before it is stripped by CXF and injecting the bus object into the
camel-cxf consumer endpoint as shown below.

<camel:from uri="cxf:bean:wsEndpoint?&bus=#myCustomBus" /> 

If what you are looking to accomplish is to allow/disallow requests based on
IP address, the interceptor should do the trick. Just throw a remote
exception in the interceptor if the address does not match. Else you can add
a IP address as a new header to the SOAP Message Header in the interceptors
and then you should see the header in the processor.

For more details on creating CXF interceptors check out
http://cxf.apache.org/docs/interceptors.html
http://cxf.apache.org/docs/interceptors.html 

Phew.... Rather long answer. Hope this helps.

Cheers,

Ashwin...

-----
---------------------------------------------------------
Ashwin Karpe
Apache Camel Committer & Sr Principal Consultant
FUSESource (a Progress Software Corporation subsidiary)
http://fusesource.com http://fusesource.com 

Blog: http://opensourceknowledge.blogspot.com
http://opensourceknowledge.blogspot.com 
---------------------------------------------------------
-- 
View this message in context: http://camel.465427.n5.nabble.com/Extracting-request-IP-in-Camel-CXF-tp3308148p3315985.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Extracting request IP in Camel CXF

Posted by "goelshek@yahoo.com" <go...@yahoo.com>.
I'm using camel-core-2.5.0 and camel-cxf-2.5.0 which AFAIK is the latest
version.

I was reading through another 
http://stackoverflow.com/questions/3480334/camel-cxfrs-with-custom-http-headers
post on Stack Overflow  where someone had trouble getting to custom headers.
As per the post, that was a bug that was fixed in 2.5. So I doubt if
versioning is the issue here.

I am running camel standalone.

I have a camel-cxf.xml that specifies a CXF web service endpoint and a
camel-context.xml that specifies a camel route. The route starts at the CXF
web service, goes through a processor and then writes the incoming request
to a file. And I am trying to print out the IP address of the requestor in
the processor.

The requisite files are attached. 
http://camel.465427.n5.nabble.com/file/n3315100/CamelCXF_HeaderIPIssue.zip
CamelCXF_HeaderIPIssue.zip 

Thanks.

Abhishek


-- 
View this message in context: http://camel.465427.n5.nabble.com/Extracting-request-IP-in-Camel-CXF-tp3308148p3315100.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Extracting request IP in Camel CXF

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hi,

Can you please provide details of the version of camel-cxf you are using and
some details about the environment (aka Tomcat, standalone, app-server etc).

I verified that the code does exist for the headers to be propagated in the
camel-cxf trunk just as I mentioned it.

Cheers,

Ashwin...  
 

-----
---------------------------------------------------------
Ashwin Karpe
Apache Camel Committer & Sr Principal Consultant
FUSESource (a Progress Software Corporation subsidiary)
http://fusesource.com http://fusesource.com 

Blog: http://opensourceknowledge.blogspot.com
http://opensourceknowledge.blogspot.com 
---------------------------------------------------------
-- 
View this message in context: http://camel.465427.n5.nabble.com/Extracting-request-IP-in-Camel-CXF-tp3308148p3314962.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Extracting request IP in Camel CXF

Posted by "goelshek@yahoo.com" <go...@yahoo.com>.
Thanks for the response Ashwin, but I am unable to find the "HTTP.REQUEST"
header in the exchange object.

My process() method is as follows:

public void process (Exchange exchange)
{
    Map<String, Object> headers = exchange.getIn().getHeaders();

    // loop through the headers object above and print out all the keys
}

I don't see "HTTP.REQUEST" as one of the keys in the map. I do see a key
named "org.apache.cxf.headers.Header.list" but when I print out its value,
the list is empty. 

Theoretically, what you said makes perfect sense in that "Protocol headers
in CXF are propagated to Camel exchanges as Camel Header entries". However,
I don't see those headers in the exchange or don't know how to access them.

I don't know of a filter strategy that would prevent the headers from being
propagated.

Can you possibly provide some more guidance as to how do I go about
extracting the "HTTP.REQUEST" header?

Thanks.

Abhishek
-- 
View this message in context: http://camel.465427.n5.nabble.com/Extracting-request-IP-in-Camel-CXF-tp3308148p3314327.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Extracting request IP in Camel CXF

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hi,

Just ran across this one and am not sure if you figured out how to do this.

The Protocol headers in CXF are propagated to Camel exchanges as Camel
Header entries. 

The value of AbstractHTTPDestination.HTTP_REQUEST is set to "HTTP.REQUEST"
in the payload and should be found as the same in the Camel Header.

Hope this helps.

Cheers,

Ashwin...

P.S: The only possible reason for not propagating the header is if there is
a header filter strategy in place that prevents it from being added.


-----
---------------------------------------------------------
Ashwin Karpe
Apache Camel Committer & Sr Principal Consultant
FUSESource (a Progress Software Corporation subsidiary)
http://fusesource.com http://fusesource.com 

Blog: http://opensourceknowledge.blogspot.com
http://opensourceknowledge.blogspot.com 
---------------------------------------------------------
-- 
View this message in context: http://camel.465427.n5.nabble.com/Extracting-request-IP-in-Camel-CXF-tp3308148p3314112.html
Sent from the Camel - Users mailing list archive at Nabble.com.