/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package test;

import java.io.ByteArrayInputStream;
import java.util.Iterator;
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.impl.builder.StAXBuilder;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.xpath.AXIOMXPath;

/**
 *
 * @author Stefan
 */
public class SOAPTest {

  

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.server.be\"> "+
"      <ns1:documentUUID>urn:uuid:100009-DFF4E3F5-95F5-7FA7-E73A-FE1F5D3C88F2</ns1:documentUUID> "+
"    </ns1:request> "+
"  </soapenv:Body> "+
"</soapenv:Envelope> ";



    public static void main(String[] args) throws Exception {

      ByteArrayInputStream xmlStream = new ByteArrayInputStream(XML_STRING2.getBytes());

      //Create a builder
      StAXBuilder builder = new StAXOMBuilder(xmlStream);

      // Get root element
      OMElement root = builder.getDocumentElement();

// AXIOM
  OMElement om1 = root.getFirstChildWithName(new QName("http://www.w3.org/2003/05/soap-envelope", "soapenv: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());


// XPAH
      AXIOMXPath xpath = new AXIOMXPath("/Envelope/Header/wsse:Security/wsse:Username"); //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(null);

      System.out.println("wsse-username:" + node.getText());




       
     }
    }

