it appears that I spoke to soon.
The jaxrsContext is null. So when I attempt to get the ip address when
running a REST query i get a null pointer.
What i have figured out is if i switch jaxrsContext to a
org.apache.cxf.jaxrs.ext.MessgeContext from a
javax.xml.ws.handler.MessageContext the rest side start to work. But, the
SOAP side no longer works (which it does if I use the
javax.xml.ws.handler.MessageContext.
I am not sure why changing the package of the MessageContext for
jaxrsContext affects the jaxwsContext but it does.
so to be clear i am including the relevant code again with package info.
@Resource javax.xml.ws.WebServiceContext jaxwsContext;
@Resource javax.xml.ws.handler.MessageContext jaxrsContext;
private String getIpAddress() {
String ipAddress = " unknown";
javax.servlet.http.HttpServletRequest request = null;
if (jaxrsContext != null) {
request = (HttpServletRequest)
jaxrsContext.get(org.apache.cxf.transport.http.AbstractHTTPDestination.HTTP_REQUEST);
} else if (jaxwsContext != null) {
request = (HttpServletRequest)
jaxwsContext.getMessageContext().get(javax.xml.ws.handler.MessageContext.SERVLET_REQUEST);
} else {
// TODO can not get ip address
// should we through and exception
}
if (request != null){
if
(StringUtils.isNotBlank(request.getHeader("X-Forwarded-For"))) {
ipAddress =
request.getHeader("X-Forwarded-For");
} else {
ipAddress = request.getRemoteAddr();
}
}
// System.out.println("IP ADDRESS: " + ipAddress);
return ipAddress;
}
any help would be greatly appreciated.
Thanks,
Chris
--
View this message in context:
http://cxf.547215.n5.nabble.com/Getting-the-IP-Address-of-SOAP-Clients-works-for-REST-clients-but-not-for-SOAP-clients-tp4476334p4484400.html
Sent from the cxf-user mailing list archive at Nabble.com.