Adding SOAPHeader using an Interceptor

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding SOAPHeader using an Interceptor

Ashvin Ramanjooloo
I'm trying to add a SOAPHeader to my request using a custom soap header OutInterceptor. I don't want to use ((BindingProvider) proxy).getRequestContext().put(Header.HEADER_LIST, headers);

The class is a such :

public class CustomSoapHeaderOutInterceptor extends AbstractSoapInterceptor {
       
        public CustomSoapHeaderOutInterceptor() {
                super(Phase.WRITE);
               
        }

        @Override
        public void handleMessage(SoapMessage message) throws Fault{
       
                       
                        SoapMessage soapMessage = (SoapMessage) message;
                        List<Header> list = message.getHeaders();
                       
                        QName q = new QName("http://commons.cxf.learning.com/", "HeaderService");
                        Person person = new Person();
                        person.setName("one person");
                        JAXBDataBinding dataBinding = null;
                                try {
                                        dataBinding = new JAXBDataBinding(person.getClass());
                                } catch (JAXBException e1) {
                                        e1.printStackTrace();
                                }
                               
                                SoapHeader header = new SoapHeader(q,person, dataBinding);
                        list.add(header);
                       
        }
}



This seems to work just fine. I just want to know if this is the correct way of doing it or do we need to extend some other specific interceptor.
Reply | Threaded
Open this post in threaded view
|

Re: Adding SOAPHeader using an Interceptor

Daniel Kulp
Administrator

That's the perfect way to do it.  

The only issue MIGHT be super(Phase.WRITE);     That's the same phase as the
SoapOutInterceptor which would be writing the headers.   Thus, if your
interceptor happens to run after the SoapOutInterceptor, your header wouldn't
get written.   I would suggest moving it to an earlier phase (PRE_PROTOCOL
maybe) or add a "addBefore(SoapOutInterceptor.class.getName())"


Dan



On Fri October 9 2009 6:12:02 am AshAce wrote:

> I'm trying to add a SOAPHeader to my request using a custom soap header
> OutInterceptor. I don't want to use ((BindingProvider)
> proxy).getRequestContext().put(Header.HEADER_LIST, headers);
>
> The class is a such :
>
> public class CustomSoapHeaderOutInterceptor extends AbstractSoapInterceptor
> {
>
> public CustomSoapHeaderOutInterceptor() {
> super(Phase.WRITE);
>
> }
>
> @Override
> public void handleMessage(SoapMessage message) throws Fault{
>
>
> SoapMessage soapMessage = (SoapMessage) message;
> List<Header> list = message.getHeaders();
>
> QName q = new QName("http://commons.cxf.learning.com/",
>  "HeaderService"); Person person = new Person();
> person.setName("one person");
> JAXBDataBinding dataBinding = null;
> try {
> dataBinding = new JAXBDataBinding(person.getClass());
> } catch (JAXBException e1) {
> e1.printStackTrace();
> }
>
> SoapHeader header = new SoapHeader(q,person, dataBinding);
> list.add(header);
>
> }
> }
>
>
> This seems to work just fine. I just want to know if this is the correct
>  way of doing it or do we need to extend some other specific interceptor.
>

--
Daniel Kulp
[hidden email]
http://www.dankulp.com/blog
Reply | Threaded
Open this post in threaded view
|

Re: Adding SOAPHeader using an Interceptor

Ashvin Ramanjooloo
Thanks Dan

dkulp wrote
That's the perfect way to do it.  

The only issue MIGHT be super(Phase.WRITE);     That's the same phase as the
SoapOutInterceptor which would be writing the headers.   Thus, if your
interceptor happens to run after the SoapOutInterceptor, your header wouldn't
get written.   I would suggest moving it to an earlier phase (PRE_PROTOCOL
maybe) or add a "addBefore(SoapOutInterceptor.class.getName())"


Dan



On Fri October 9 2009 6:12:02 am AshAce wrote:
> I'm trying to add a SOAPHeader to my request using a custom soap header
> OutInterceptor. I don't want to use ((BindingProvider)
> proxy).getRequestContext().put(Header.HEADER_LIST, headers);
>
> The class is a such :
>
> public class CustomSoapHeaderOutInterceptor extends AbstractSoapInterceptor
> {
>
> public CustomSoapHeaderOutInterceptor() {
> super(Phase.WRITE);
>
> }
>
> @Override
> public void handleMessage(SoapMessage message) throws Fault{
>
>
> SoapMessage soapMessage = (SoapMessage) message;
> List<Header> list = message.getHeaders();
>
> QName q = new QName("http://commons.cxf.learning.com/",
>  "HeaderService"); Person person = new Person();
> person.setName("one person");
> JAXBDataBinding dataBinding = null;
> try {
> dataBinding = new JAXBDataBinding(person.getClass());
> } catch (JAXBException e1) {
> e1.printStackTrace();
> }
>
> SoapHeader header = new SoapHeader(q,person, dataBinding);
> list.add(header);
>
> }
> }
>
>
> This seems to work just fine. I just want to know if this is the correct
>  way of doing it or do we need to extend some other specific interceptor.
>

--
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog
Reply | Threaded
Open this post in threaded view
|

Re: Adding SOAPHeader using an Interceptor

M.Faith
This post has NOT been accepted by the mailing list yet.
In reply to this post by Ashvin Ramanjooloo
Thank you. You saved my day!