camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "goelshek@yahoo.com" <goels...@yahoo.com>
Subject Extracting request IP in Camel CXF
Date Thu, 16 Dec 2010 16:07:12 GMT

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.

Mime
View raw message