You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Gabriel <ga...@online.de> on 2013/01/28 14:03:16 UTC

insert custom Soap Header problem

Hi,
I want to add a custom SOAP-Header to a pojo message. For that I configured
the following route:

<route id="CustomerServiceUpdateCustomerTest">
        <camel:from uri="direct:iccsUpdateCustomerRequest"/>
        <camel:process ref="addCredentials"/>
        <to uri="cxf:bean:ICCSCustomerService"/>  
</route>

The Header should be inserted by the processor witch looks like that:
@Override 
public void process(Exchange exchange) throws Exception { 
   List<SoapHeader> soapHeaders =
CastUtils.cast((List<?)exchange.getOut().getHeader(Header.HEADER_LIST)); 
    // Insert a new header 
    String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><outofbandHeader
&quot; 
        + &quot;xmlns=\&quot;http://cxf.apache.org/outofband/Header\&quot;
hdrAttribute=\&quot;testHdrAttribute\&quot; &quot; 
        +
&quot;xmlns:soap=\&quot;http://schemas.xmlsoap.org/soap/envelope/\&quot;
soap:mustUnderstand=\&quot;1\&quot;>" 
        + "<name>simpleAuth username=\"xxx\" password=\"abc\"
xmlns=\"http://xsoap.iccs.de/v1\"</name></outofbandHeader>"; 

    SoapHeader newHeader = new SoapHeader(new
QName("http://xsoap.iccs.de/v1", "simpleAuth"), 
                   DOMUtils.readXml(new
StringReader(xml)).getDocumentElement()); 
    // make sure direction is OUT since it is a response message. 
    newHeader.setDirection(Direction.DIRECTION_OUT); 
    //newHeader.setMustUnderstand(false); 
    soapHeaders.add(newHeader); 
}


CastUtils.cast((List<?)exchange.getOut().getHeader(Header.HEADER_LIST)); 
throws a npe. 
This should be the correct way to insert an custom Soap-Header. What's
wrong?
Can someone help me which that?

Thanks Gabriel




--
View this message in context: http://camel.465427.n5.nabble.com/insert-custom-Soap-Header-problem-tp5726415.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: insert custom Soap Header problem

Posted by Gabriel <ga...@online.de>.
Thank you Willem, everything works fine now



--
View this message in context: http://camel.465427.n5.nabble.com/insert-custom-Soap-Header-problem-tp5726415p5726553.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: insert custom Soap Header problem

Posted by Willem jiang <wi...@gmail.com>.
Did you copy the in message body to the out message?
Please do it to let camel-cxf generate the right invocation message for you.


--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem




On Wednesday, January 30, 2013 at 1:21 AM, Gabriel wrote:

> Hi Willem,
> I have now a Header.HEADER_LIST witch contains one outofbandHeader. But this
> Item (outofbandHeader) does not contain any object. I expected my simpleAuth
> tag here. (Please see my first post).
> Do you have a idea what's wrong?  
>  
> Thanks
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/insert-custom-Soap-Header-problem-tp5726415p5726506.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Re: insert custom Soap Header problem

Posted by Gabriel <ga...@online.de>.
Hi Willem,
I have now a Header.HEADER_LIST witch contains one outofbandHeader. But this
Item (outofbandHeader) does not contain any object. I expected my simpleAuth
tag here. (Please see my first post).
Do you have a idea what's wrong? 

Thanks



--
View this message in context: http://camel.465427.n5.nabble.com/insert-custom-Soap-Header-problem-tp5726415p5726506.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: insert custom Soap Header problem

Posted by Gabriel <ga...@online.de>.
Thank you Willem, 
thats the solution. 
Thanks Gabriel



--
View this message in context: http://camel.465427.n5.nabble.com/insert-custom-Soap-Header-problem-tp5726415p5726422.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: insert custom Soap Header problem

Posted by Willem jiang <wi...@gmail.com>.
It looks like you want to set the cxf message header before routing the request to the camel-cxf endpoint.
As you know, camel message header doesn't any thing know about the CXF message headers information before routing the message into the CXF endpoint.
That could explain why you get the NPE.  
If you want to add the customer SOAP header for the cxf endpoint, you can just create a new List of SoapHeader, and set it into camel message header with the key Header.HEADER_LIST like this

List<SoapHeader> soapHeaders = new ArrayList<SoapHeader>();
……
exchange.getOut().setHeader(Header.HEADER_LIST, soapHeaders);


--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem




On Monday, January 28, 2013 at 9:03 PM, Gabriel wrote:

> Hi,
> I want to add a custom SOAP-Header to a pojo message. For that I configured
> the following route:
>  
> <route id="CustomerServiceUpdateCustomerTest">
> <camel:from uri="direct:iccsUpdateCustomerRequest"/>
> <camel:process ref="addCredentials"/>
> <to uri="cxf:bean:ICCSCustomerService"/>  
> </route>
>  
> The Header should be inserted by the processor witch looks like that:
> @Override  
> public void process(Exchange exchange) throws Exception {  
> List<SoapHeader> soapHeaders =
> CastUtils.cast((List<?)exchange.getOut().getHeader(Header.HEADER_LIST));  
> // Insert a new header  
> String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><outofbandHeader
> &quot;  
> + &quot;xmlns=\&quot;http://cxf.apache.org/outofband/Header\&quot;
> hdrAttribute=\&quot;testHdrAttribute\&quot; &quot;  
> +
> &quot;xmlns:soap=\&quot;http://schemas.xmlsoap.org/soap/envelope/\&quot;
> soap:mustUnderstand=\&quot;1\&quot;>"  
> + "<name>simpleAuth username=\"xxx\" password=\"abc\"
> xmlns=\"http://xsoap.iccs.de/v1\"</name></outofbandHeader>";  
>  
> SoapHeader newHeader = new SoapHeader(new
> QName("http://xsoap.iccs.de/v1", "simpleAuth"),  
> DOMUtils.readXml(new
> StringReader(xml)).getDocumentElement());  
> // make sure direction is OUT since it is a response message.  
> newHeader.setDirection(Direction.DIRECTION_OUT);  
> //newHeader.setMustUnderstand(false);  
> soapHeaders.add(newHeader);  
> }
>  
>  
> CastUtils.cast((List<?)exchange.getOut().getHeader(Header.HEADER_LIST));  
> throws a npe.  
> This should be the correct way to insert an custom Soap-Header. What's
> wrong?
> Can someone help me which that?
>  
> Thanks Gabriel
>  
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/insert-custom-Soap-Header-problem-tp5726415.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Re: insert custom Soap Header problem

Posted by Willem jiang <wi...@gmail.com>.
Yeah, you can do it by setting up a customer interceptor on the CXF endpoint.


--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Tuesday, January 29, 2013 at 3:37 AM, peter.berkman wrote:

> not sure if this is the same, but I had to do something similar for SAML.  
>  
> I did it through an Interecepter:
>  
> {code}
> public class SAMLResponseInterceptor extends AbstractSoapInterceptor {
>  
> private static final transient Logger LOG =
> LoggerFactory.getLogger(SAMLResponseInterceptor.class);
>  
> public SAMLResponseInterceptor() {
> super(Phase.PRE_PROTOCOL);
> }
>  
> @Override
> public void handleMessage(SoapMessage message) throws Fault {
>  
> LOG.debug("Out interceptor called.....");
>  
> SAMLHelper sam = new SAMLHelper();
>  
> Element saml = sam.getResponseSAML();
>  
> if (saml != null) {
>  
> QName q = new
> QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Security",
> "wsse");
> Header h = message.getHeader(q);
>  
> if (h == null) {
>  
> QName q1 = new
> QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Security",
> "o");
> Header h1 = message.getHeader(q1);
>  
> if (h1 == null) {
>  
> h = new Header(q, saml);
> message.getHeaders().add(h);
> LOG.debug("New soap header added");
> }
> else {
> h1.setObject(saml);
> LOG.debug("soap header updated");
> }
> }
> else {
> h.setObject(saml);
> LOG.debug("soap header updated");
> }
> }
> }
> }
>  
> {code}
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/insert-custom-Soap-Header-problem-tp5726415p5726438.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Re: insert custom Soap Header problem

Posted by "peter.berkman" <pe...@cornergrove.com>.
not sure if this is the same, but I had to do something similar for SAML. 

I did it through an Interecepter:

{code}
public class SAMLResponseInterceptor extends AbstractSoapInterceptor {
	
	private static final transient Logger LOG =
LoggerFactory.getLogger(SAMLResponseInterceptor.class);

    public SAMLResponseInterceptor() {
        super(Phase.PRE_PROTOCOL);
    }

    @Override
    public void handleMessage(SoapMessage message) throws Fault {
    	
        LOG.debug("Out interceptor called.....");
        
        SAMLHelper sam = new SAMLHelper();
        
        Element saml = sam.getResponseSAML();
        
        if (saml != null) {
        	
            QName q = new
QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Security",
"wsse");
            Header h = message.getHeader(q);
            
            if (h == null) {
            	
                QName q1 = new
QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Security",
"o");
                Header h1 = message.getHeader(q1);
                
                if (h1 == null) {
                	
                    h = new Header(q, saml);
                    message.getHeaders().add(h);
                    LOG.debug("New soap header added");
                }
                else {
                    h1.setObject(saml);
                    LOG.debug("soap header updated");
                }
            }
            else {
                h.setObject(saml);
                LOG.debug("soap header updated");
            }
        }
    }
}

{code}



--
View this message in context: http://camel.465427.n5.nabble.com/insert-custom-Soap-Header-problem-tp5726415p5726438.html
Sent from the Camel - Users mailing list archive at Nabble.com.