axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Deepal Jayasinghe <deep...@gmail.com>
Subject Re: How to get attribute from SOAPHeader with header.getFirstChildWithName()
Date Wed, 28 Jul 2010 03:47:53 GMT
In your case document element become the SOAP envelop, so you need to
get the soap header child element and from that you can get the
elements you want.

Deepal

On Tue, Jul 27, 2010 at 9:53 AM, hideki tihiri <hideki.tihiri@gmail.com> wrote:
> Hi Deepal,
> Thx for the feedback.
> I rewrite the code below as I was referring always to root, which I think is
> wrong, so I reprint the code:
> (I also attached the java class if this is more convenient to try for
> yourself).
> The XML STRING:
> public final static String XML_STRING2 = "" +
>         "<?xml version=\"1.0\" encoding='UTF-8'?> "+
> "<soapenv:Envelope
> xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\"> "+
> "  <soapenv:Header  xmlns:wsa=\"http://www.w3.org/2005/08/addressing\"> "+
> "    <wsse:Security
> xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"
> soapenv:mustUnderstand=\"true\"> "+
> "      <wsse:UsernameToken
> xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\"
> wsu:Id=\"UsernameToken-20656006\"> "+
> "        <wsse:Username>test</wsse:Username> "+
> "        <wsse:Password
> Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">TEST</wsse:Password>
> "+
> "      </wsse:UsernameToken> "+
> "    </wsse:Security> "+
> "
>  <wsa:To>http://localhost:8080/server/services/Remove.RemoveHttpSoap12Endpoint/</wsa:To>
> "+
> "    <wsa:MessageID>urn:uuid:463523964E8A11FEB11280155268837</wsa:MessageID>
> "+
> "    <wsa:Action>urn:request</wsa:Action> "+
> "  </soapenv:Header> "+
> "  <soapenv:Body> "+
> "    <ns1:request xmlns:ns1=\"http://services.betrust.be\"> "+
> "
>  <ns1:documentUUID>urn:uuid:100009-DFF4E3F5-95F5-7FA7-E73A-FE1F5D3C88F2</ns1:documentUUID>
> "+
> "    </ns1:request> "+
> "  </soapenv:Body> "+
> "</soapenv:Envelope> ";
>
> 1) Via  get the header element first, and then UsernameToken element
> and finally username element.
> Node that in the code below I now 'drill-down' from om1 to om2 to om3 and so
> on (I suppose this is the way it should work) ?
>   OMElement om1 = root.getFirstChildWithName(new
> QName("http://www.w3.org/2003/05/soap-envelope", "Envelope"));
>   OMElement om2 = om1.getFirstChildWithName(new
> QName("http://www.w3.org/2003/05/soap-envelope", "Header"));
>   OMElement om3 = om2.getFirstChildWithName(new
> QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
> "Security"));
>   OMElement om4 = om3.getFirstChildWithName(new
> QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
> "UserNameToken"));
>   OMElement om5 = om4.getFirstChildWithName(new
> QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
> "UserName"));
>   System.out.println("wsse-username:" + om5.getText());
> ==> Problem is that om1 is null !
> 2) XPath:
>       AXIOMXPath xpath = new
> AXIOMXPath("/Envelope/Header/wsse:Security/wsse:Username");
>       OMElement node = (OMElement) xpath.selectSingleNode(null);
>       System.out.println("wsse-username:" + node.getText());
> ==> The node is null ?
>
> Regards,
> H.
>
>
> On Tue, Jul 27, 2010 at 2:55 PM, Deepal Jayasinghe <deepalk@gmail.com>
> wrote:
>>
>> On Tue, Jul 27, 2010 at 6:06 AM, hideki tihiri <hideki.tihiri@gmail.com>
>> wrote:
>> > Hi Deepal,
>> >
>> > thx for the reply.
>> > I tried in 2 different ways but I don't succeed in reading the username:
>> > 1) Via  get the header element first, and then UsernameToken element and
>> > finally username element.
>> > ByteArrayInputStream xmlStream = new
>> > ByteArrayInputStream(XML_STRING2.getBytes());
>> > //Create a builder
>> > StAXBuilder builder = new StAXOMBuilder(xmlStream);
>> > // Get root element
>> > OMElement root = builder.getDocumentElement();
>> > OMElement headerElem = root.getFirstChildWithName(new
>> > QName("http://www.w3.org/2003/05/soap-envelope", "soapenv:Envelope"));
>>
>> This has to be
>>  OMElement headerElem = root.getFirstChildWithName(new
>> QName("http://www.w3.org/2003/05/soap-envelope", "Envelope"));
>>
>> >  headerElem = root.getFirstChildWithName(new
>> > QName("http://www.w3.org/2003/05/soap-envelope", "Header"));
>> >  headerElem = root.getFirstChildWithName(new
>> >
>> > QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
>> > "Security"));
>> >  headerElem = root.getFirstChildWithName(new
>> >
>> > QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
>> > "UserNameToken"));
>> >  headerElem = root.getFirstChildWithName(new
>> >
>> > QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
>> > "UserName"));
>> >  System.out.println("wsse-username:" + headerElem.getText());
>> > ==> Returns Exception in thread "main" java.lang.NullPointerException
>> > 2) XPath
>> > AXIOMXPath xpath = new
>> >
>> > AXIOMXPath("/soapenv:Envelope/soapenv:Header/wsse:Security/wsse:Username");
>> This has to be
>> > AXIOMXPath("/Envelope/Header/wsse:Security/wsse:Username");
>>
>>
>> > xpath.addNamespace("soapenv",
>> > "http://www.w3.org/2003/05/soap-envelope");
>> > xpath.addNamespace("wsse",
>> >
>> > "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
>> > OMElement node = (OMElement) xpath.selectSingleNode(root);
>> > System.out.println("wsse-username:" + node.getText());
>> > ==> Returns Exception in thread "main" java.lang.NullPointerException
>> > Can you please help ?
>> > H.
>> >
>> > On Mon, Jul 26, 2010 at 11:07 PM, Deepal Jayasinghe <deepalk@gmail.com>
>> > wrote:
>> >>
>> >> Here, you can use two mechanisms, first you can use Xpath based
>> >> navigation to get the element you need, or else you can get the header
>> >> element first, and then UsernameToken element and finally username
>> >> element.
>> >>
>> >> Deepal
>> >>
>> >> On Mon, Jul 26, 2010 at 3:05 PM, hideki tihiri
>> >> <hideki.tihiri@gmail.com>
>> >> wrote:
>> >> > Hi,
>> >> > I am unable to solve following problem, although it should be fairly
>> >> > simple:
>> >> > I have folloing SOAP header:
>> >> > <soapenv:Header
>> >> > xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
>> >> > xmlns:wsa="http://www.w3.org/2005/08/addressing">
>> >> >   <wsse:Security
>> >> >
>> >> >
>> >> > xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
>> >> > soapenv:mustUnderstand="true">
>> >> >     <wsse:UsernameToken
>> >> >
>> >> >
>> >> > xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
>> >> > wsu:Id="UsernameToken-12592762">
>> >> >     <wsse:Username>testr</wsse:Username>
>> >> >     <wsse:Password
>> >> >
>> >> >
>> >> > Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">TEST</wsse:Password>
>> >> >    </wsse:UsernameToken>
>> >> >   </wsse:Security>
>> >> >
>> >> >
>> >> >   <wsa:To>http://localhost:8080/server/services/Remove.RemoveHttpSoap12Endpoint/</wsa:To>
>> >> >
>> >> >
>> >> >   <wsa:MessageID>urn:uuid:40A03A83C5E5358B181280163771513</wsa:MessageID>
>> >> >   <wsa:Action>urn:request</wsa:Action>
>> >> > </soapenv:Header>
>> >> > I need to check the username .
>> >> > I have following code:
>> >> > MessageContext mc = MessageContext.getCurrentMessageContext();
>> >> > SOAPHeader header = mct.getEnvelope().getHeader();
>> >> >  OMElement headerElem = header.getFirstChildWithName(new
>> >> >
>> >> >
>> >> > QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
>> >> > "Username"));
>> >> >   LOGGER.info("wsse-username:" + headerElem.toString());
>> >> >
>> >> > The problem is that a 'null' is logged.
>> >> > Where do I go wrong ?
>> >> > Regards,
>> >> > H.
>> >>
>> >>
>> >>
>> >> --
>> >> http://blogs.deepal.org
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: java-dev-unsubscribe@axis.apache.org
>> >> For additional commands, e-mail: java-dev-help@axis.apache.org
>> >>
>> >
>> >
>>
>>
>>
>> --
>> http://blogs.deepal.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-dev-unsubscribe@axis.apache.org
>> For additional commands, e-mail: java-dev-help@axis.apache.org
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-dev-unsubscribe@axis.apache.org
> For additional commands, e-mail: java-dev-help@axis.apache.org
>



-- 
http://blogs.deepal.org

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@axis.apache.org
For additional commands, e-mail: java-dev-help@axis.apache.org


Mime
View raw message