-
1. Re: How to get the ip address using cxfbc?
ffang Aug 19, 2011 4:00 AM (in response to llwang0455)Hi,
You can add an customer inInterceptor for cxf bc consumer endpoint to do so. something like
public class GrepClientIPInterceptor extends AbstractPhaseInterceptor{
public GrepClientIPInterceptor() {
super(Phase.RECEIVE);
}
public void handleMessage(Message message) throws Fault {
HttpServletRequest request = (HttpServletRequest)
message.get(AbstractHTTPDestination.HTTP_REQUEST);
request.getRemoteAddr();// this is the client ip address
}
}
}
Freeman
-
2. Re: How to get the ip address using cxfbc?
llwang0455 Aug 19, 2011 5:20 AM (in response to ffang)Thank you for your answer.
I get it ,using the Interceptor I can get the request before cxfbc consumer,and I have another question , it is that I have many consumer,namely I have many bundles in the deploy folder,then how can I config the same Interceptor to all the cxfbc consumer? Or Could I not change the beans.xml file in the bundle which provides the proxy webservice,and add the Interceptor configuration to all cxfbc consumer?
I know the description is a lot chaos, sorry about that.Hope your advice.
-
3. Re: How to get the ip address using cxfbc?
ffang Aug 19, 2011 5:34 AM (in response to llwang0455)Hi,
You can expose this interceptor as a OSGi service and refer it in all of your cxf bc consumer bundles, but you do need change beans.xml to refer it anyway.
Freeman
-
4. Re: How to get the ip address using cxfbc?
llwang0455 Aug 19, 2011 5:47 AM (in response to ffang)Got it ,thx a lot!
How can I take the ip address getting from the interceptor to the cxfbc ? Such as saving it to the MessageExchange object? If so,I would get the address in the listener class.
Do you have any ideas to tell me?
-
5. Re: How to get the ip address using cxfbc?
ffang Aug 19, 2011 6:02 AM (in response to llwang0455)Hi,
You can get the MessageExchange from cxf message like
MessageExchange exchange = message
.getContent(MessageExchange.class);
then you can save the client ip address as the MessageExchange property.
You need change your interceptor phase as Phase.INVOKE, as in this phase the JBI MessageExchange is avaible in cxf message.
Hope this helps.
Freeman
-
6. Re: How to get the ip address using cxfbc?
llwang0455 Aug 21, 2011 10:51 PM (in response to ffang)Thanks for your answers!
Get it,I will try!
I have an idea about the problem of not changing the beans.xml file,I need your opinion.
It is that if I can modify the source code in cxfbc about the interceptor,then I can put the interceptor as the default interceptor of the cxfbc consumer element .
It's just a thought,could I do that as that?
-
7. Re: How to get the ip address using cxfbc?
ffang Aug 21, 2011 11:09 PM (in response to llwang0455)Hi,
Yeah, you can do it, you need download the src and modify it and then build it again.
Add a interceptor should be straightfoward, just add your interceptor in CxfBcConsumer should be ok.
Freeman