Hi
>
> here is the code that i am using to get the HttpServletReqeust object (this
> is in my service implementation class):
>
> @Resource
> private HttpServletRequest request = null;
>
> @Resource
> public void setContext(WebServiceContext context) {
> if (context != null && context.getMessageContext() != null &&
> context.getMessageContext().get(AbstractHTTPDestination.HTTP_REQUEST) !=
> null) {
> this.request = (HttpServletRequest)
> context.getMessageContext().get(AbstractHTTPDestination.HTTP_REQUEST);
> }
> }
>
> As i said, REST works great. But when i try to use SOAP the request object
> returns null as soon as i do a getRemoteAddr().
I'm not sure you can get a valid HttpServletRequest at the moment
WebServiceContext is being injected.
If you have a single service bean instance serving both plain HTTP and
SOAP requests and would to check the context info then you probably
need to inject
JAX-WS WebServiceContext
and
CXF JAX-RS MessageContext
and then check at runtime if it's jaxws or jaxrs chain which is being invoked:
http://cxf.apache.org/docs/jax-rs-and-jax-ws.html#JAX-RSandJAX-WS-Dealingwithcontexts
I was thinking of introducing a CXF extension, something like
ServiceContext, which could be used seamlessly irrespectively of
whether it was JAXWS or JAXRS invocation in progress. Loss of
portability vs simpler access to contexts. May get to it later on.
The other option is to check this info from CXF interceptors - a
single interceptor can be shared for this purpose.
Cheers, Sergey
>
> The soap request it being submitted using Apache HttpClient.
>
> here is some CXF output about the request:
>
> INFO: Inbound Message
> ----------------------------
> ID: 1
> Address: http://localhost:8080/GoldenKey/svc/soap
> Encoding: UTF-8
> Http-Method: POST
> Content-Type: text/xml; charset=utf-8
> Headers: {connection=[Keep-Alive], Content-Length=[387],
> content-type=[text/xml; charset=utf-8], host=[localhost:8080],
> user-agent=[Apache-HttpClient/4.1 (java 1.5)], x-forwarded-for=[This is my
> ip address: 127.0.0.1]}
> Payload: <soap:Envelope
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:getAddressTypes
> xmlns:ns2="http://com.upmc.tdc.server"><ns2:Application><applicationId>2a24907c-59c2-4415-b944-a5d1148544d1</applicationId></ns2:Application><ns2:User><username>myerscb</username></ns2:User><ns2:DataSourceType>EPCD</ns2:DataSourceType></ns2:getAddressTypes></soap:Body></soap:Envelope>
> --------------------------------------
>
> it certainly looks like the headers are there, even one that I inserted
> (x-forwarded-for). But, when I attempt to try and access the headers
> through the request object, i get a null pointer exception.
>
> I am wondering what i am missing? is there a different way to get header
> information for a soap request?
>
> Thanks for your help,
>
> 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-tp4476334p4476334.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
--
Sergey Beryozkin
Application Integration Division of Talend
http://sberyozkin.blogspot.com