You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Nathaniel Auvil <na...@gmail.com> on 2012/02/16 18:48:47 UTC

Set HTTP Header on response from SOAP web service

i generated server stubs from WSDL.  I have a use case where i need to be
able to set the HTTP Status code in responses is certain error conditions.
How do i get a handle to the HTTP response in my SOAP based service which
has the JAXB objects as input and outputs?

For the WS-Addressing header info i inject the WebServiceContext in my bean
so i can access that.  I seem to remember there being a RequestContext
object in CXF at some point which used thread local to get the current
context and allowed for HTTP Header access request and response, but i do
not see that in 2.5.1

Any help is greatly appreciated.

Re: Set HTTP Header on response from SOAP web service

Posted by skousouris <st...@hotmail.com>.
Despite not being able to read a value from them I managed to set them in the
interceptor and now the encoding works

    message.put(Message.ENCODING, "UTF-8");
    message.put(Message.CONTENT_TYPE, "text/xml;charset=UTF-8");



--
View this message in context: http://cxf.547215.n5.nabble.com/Set-HTTP-Header-on-response-from-SOAP-web-service-tp5490251p5715693.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Set HTTP Header on response from SOAP web service

Posted by skousouris <st...@hotmail.com>.
Is it possible to explain how to modify in my client's interceptor chain the
HTTPResponse Headers?

    LOGGER.debug("Header CHARACTER ENCODING=",
message.getExchange().getInMessage().get(Message.ENCODING));
    LOGGER.debug("Header CONTENT TYPE=",
message.getExchange().getInMessage().get(Message.CONTENT_TYPE));  

both result in an empty string 
Header CHARACTER ENCODING=
Header CONTENT TYPE=

I need to access them in order to modify them but at the moment I am not
able to access them nor modify them could you provide some assistance?

The problem I am facing is that the response returns
Encoding: ISO-8859-1 
Content-Type: text/xml 

and since the other side returns UTF-8 in the payload (the payload does say
it is UTF-8) the CXF does not seem to be able to handle the UTF-8 characters
correctly. Therefore I am trying to change the headers to

Encoding: UTF-8 
Content-Type: text/xml;charset=UTF-8 

which when present (I have mocked the external webservice) result in the
correct character set seems to be used by CXF.



--
View this message in context: http://cxf.547215.n5.nabble.com/Set-HTTP-Header-on-response-from-SOAP-web-service-tp5490251p5715638.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Set HTTP Header on response from SOAP web service

Posted by Daniel Kulp <dk...@apache.org>.
On Thursday, February 16, 2012 1:54:58 PM Nathaniel Auvil wrote:
> thanks for the reply, but this example is from a client point of view.  I
> need to access http header on the server side, specifically the response.
> From code, how do i get access to the RequestContext/ResponseContext or
> something like that?  My wsdl to java generated server stubs only accept
> the XML types going in and out.
> 

It should be roughly the same.  If you have the injected context, you can do:

ctx.get(MessageContext.HTTP_RESPONSE_HEADERS) 

and add the headers.   However, it sounds like you want the response code, not 
headers, right?   Thus, just do:

ctx.put(MessageContext.HTTP_RESPONSE_CODE, "555")

or similar.

Dan




> On Thu, Feb 16, 2012 at 1:49 PM, Glen Mazza <gm...@talend.com> wrote:
> > http://java.dzone.com/**articles/apache-cxf-how-add-**custom-http<http://j
> > ava.dzone.com/articles/apache-cxf-how-add-custom-http> ?
> > 
> > HTH,
> > Glen
> > 
> > On 02/16/2012 12:48 PM, Nathaniel Auvil wrote:
> >> i generated server stubs from WSDL.  I have a use case where i need to be
> >> able to set the HTTP Status code in responses is certain error
> >> conditions.
> >> How do i get a handle to the HTTP response in my SOAP based service which
> >> has the JAXB objects as input and outputs?
> >> 
> >> For the WS-Addressing header info i inject the WebServiceContext in my
> >> bean
> >> so i can access that.  I seem to remember there being a RequestContext
> >> object in CXF at some point which used thread local to get the current
> >> context and allowed for HTTP Header access request and response, but i do
> >> not see that in 2.5.1
> >> 
> >> Any help is greatly appreciated.
> > 
> > --
> > Glen Mazza
> > Talend Community Coders - coders.talend.com
> > blog: www.jroller.com/gmazza
-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com

Re: Set HTTP Header on response from SOAP web service

Posted by Nathaniel Auvil <na...@gmail.com>.
thanks for the reply, but this example is from a client point of view.  I
need to access http header on the server side, specifically the response.
>From code, how do i get access to the RequestContext/ResponseContext or
something like that?  My wsdl to java generated server stubs only accept
the XML types going in and out.




On Thu, Feb 16, 2012 at 1:49 PM, Glen Mazza <gm...@talend.com> wrote:

> http://java.dzone.com/**articles/apache-cxf-how-add-**custom-http<http://java.dzone.com/articles/apache-cxf-how-add-custom-http>
> ?
>
> HTH,
> Glen
>
>
> On 02/16/2012 12:48 PM, Nathaniel Auvil wrote:
>
>> i generated server stubs from WSDL.  I have a use case where i need to be
>> able to set the HTTP Status code in responses is certain error conditions.
>> How do i get a handle to the HTTP response in my SOAP based service which
>> has the JAXB objects as input and outputs?
>>
>> For the WS-Addressing header info i inject the WebServiceContext in my
>> bean
>> so i can access that.  I seem to remember there being a RequestContext
>> object in CXF at some point which used thread local to get the current
>> context and allowed for HTTP Header access request and response, but i do
>> not see that in 2.5.1
>>
>> Any help is greatly appreciated.
>>
>>
>
> --
> Glen Mazza
> Talend Community Coders - coders.talend.com
> blog: www.jroller.com/gmazza
>
>

Re: Set HTTP Header on response from SOAP web service

Posted by Glen Mazza <gm...@talend.com>.
http://java.dzone.com/articles/apache-cxf-how-add-custom-http?

HTH,
Glen

On 02/16/2012 12:48 PM, Nathaniel Auvil wrote:
> i generated server stubs from WSDL.  I have a use case where i need to be
> able to set the HTTP Status code in responses is certain error conditions.
> How do i get a handle to the HTTP response in my SOAP based service which
> has the JAXB objects as input and outputs?
>
> For the WS-Addressing header info i inject the WebServiceContext in my bean
> so i can access that.  I seem to remember there being a RequestContext
> object in CXF at some point which used thread local to get the current
> context and allowed for HTTP Header access request and response, but i do
> not see that in 2.5.1
>
> Any help is greatly appreciated.
>


-- 
Glen Mazza
Talend Community Coders - coders.talend.com
blog: www.jroller.com/gmazza