View Javadoc

1   package com.eviware.soapui.impl.wsdl.support.wss;
2   
3   import org.apache.xmlbeans.XmlException;
4   import org.apache.xmlbeans.XmlObject;
5   import org.w3c.dom.Element;
6   import org.w3c.dom.Node;
7   import org.w3c.dom.NodeList;
8   
9   import com.eviware.soapui.SoapUI;
10  import com.eviware.soapui.impl.wsdl.support.soap.SoapUtils;
11  import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
12  import com.eviware.soapui.impl.wsdl.support.wsa.WsaContainer;
13  import com.eviware.soapui.support.xml.XmlUtils;
14  
15  public class WssUtils {
16  	public final static String WSSE_NAMESPACE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
17  	public final static String WSU_NAMESPACE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
18  
19  	String content;
20  	SoapVersion soapVersion;
21  	
22  	public static String removeWSSOutgoing(String content, WsaContainer wsaContainer) {
23  		try {
24  			SoapVersion soapVersion = wsaContainer.getOperation().getInterface().getSoapVersion();
25  			XmlObject xmlContentObject = XmlObject.Factory.parse(content);
26  			Element header = (Element) SoapUtils.getHeaderElement(xmlContentObject,
27  					soapVersion, true).getDomNode();
28  
29  			NodeList headerProps = XmlUtils.getChildElements(header);
30  			for (int i = 0; i < headerProps.getLength(); i++) {
31  				Node headerChild = headerProps.item(i);
32  				if (headerChild.getNamespaceURI().equals(WSSE_NAMESPACE)) {
33  					header.removeChild(headerChild);
34  				}
35  			}
36  			content = xmlContentObject.xmlText();
37  		} catch (XmlException e) {
38  			SoapUI.logError(e);
39  		}
40  		return content;
41  	}
42  }