[resolved] SOAP header in tJavaRow

Highlighted
One Star

[resolved] SOAP header in tJavaRow

Hi
I wanted to access the soap headers from a tESBProviderRequest. I have the tESBReq connected to a tJavaRow and then connected to a tXmlMap but it doesnt necessarily have to be like this, I am just looking to extract the header values.
My request envelope looks like this 

<Envelope xmlns="">
    <Header>
        <securityHeader xmlns="">
            <username xmlns=""></username>
            <hased_password xmlns=""></hased_password>
        </securityHeader>
    </Header>
    <Body>
        <getRequest xmlns="">
            <ID xmlns="">100103308911W600</ID>
        </getRequest>
    </Body>
</Envelope>  
How can I retrieve the values of username and password from the header? 
When I print out the input_row it only prints out the body, no headers.
I did try a couple of other threads which suggested "((java.util.Collection<org.apache.cxf.headers.Header>) globalMap.get("tESBProviderRequest_1_HEADERS_SOAP"))" however I cant figure out the way to extract the values.
Appreciate the help.
Thanks

Accepted Solutions
One Star

Re: [resolved] SOAP header in tJavaRow

Hello,
I could do it like this :
java.util.Collection<org.apache.cxf.headers.Header> soapHeaders =
((java.util.Collection<org.apache.cxf.headers.Header>) globalMap.get("tESBProviderRequest_1_HEADERS_SOAP"));
java.util.Iterator<org.apache.cxf.headers.Header> it = soapHeaders.iterator();
org.apache.cxf.headers.Header h = (org.apache.cxf.headers.Header) it.next(); 
/*get the key*/
Node n1;
row2.key =  ((Element) h.getName());
/*get the value*/
org.w3c.dom.NodeList nl = ((org.w3c.dom.Element) h.getObject()).getChildNodes();
row2.value = nl.item(0).getTextContent().toString();
/*if you have multiple items*/
org.apache.cxf.headers.Header h = (org.apache.cxf.headers.Header) it.next();
.....

All Replies
One Star

Re: [resolved] SOAP header in tJavaRow

Any responses? I have the same problem
One Star

Re: [resolved] SOAP header in tJavaRow

I ended up just doing this but I would still like to explore a neater refactor of the implementation if possible:
java.util.Collection<org.apache.cxf.headers.Header> soapHeaders = ((java.util.Collection<org.apache.cxf.headers.Header>) globalMap.get("tESBProviderRequest_1_HEADERS_SOAP"));
Iterator<org.apache.cxf.headers.Header> it = soapHeaders.iterator();
org.apache.cxf.headers.Header h = (org.apache.cxf.headers.Header) it.next();
Node n1,n2;
n1 =  ((Element) h.getObject());
NodeList nl = ((Element) h.getObject()).getChildNodes();
var1 = nl.item(1 /* Just trial and error to get this number */ ).getTextContent().trim();   
var2 = nl.item(3 /* same here */ ).getTextContent().trim();  
One Star

Re: [resolved] SOAP header in tJavaRow

Hello,
I could do it like this :
java.util.Collection<org.apache.cxf.headers.Header> soapHeaders =
((java.util.Collection<org.apache.cxf.headers.Header>) globalMap.get("tESBProviderRequest_1_HEADERS_SOAP"));
java.util.Iterator<org.apache.cxf.headers.Header> it = soapHeaders.iterator();
org.apache.cxf.headers.Header h = (org.apache.cxf.headers.Header) it.next(); 
/*get the key*/
Node n1;
row2.key =  ((Element) h.getName());
/*get the value*/
org.w3c.dom.NodeList nl = ((org.w3c.dom.Element) h.getObject()).getChildNodes();
row2.value = nl.item(0).getTextContent().toString();
/*if you have multiple items*/
org.apache.cxf.headers.Header h = (org.apache.cxf.headers.Header) it.next();
.....

Cloud Free Trial

Try Talend Cloud free for 30 days.

Tutorial

Introduction to Talend Open Studio for Data Integration.

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.