ws-kandula-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 Tue, 27 Jul 2010 12:55:45 GMT
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


Mime
View raw message