View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl.support.wss;
14  
15  import org.apache.xmlbeans.XmlException;
16  import org.apache.xmlbeans.XmlObject;
17  import org.w3c.dom.Element;
18  import org.w3c.dom.Node;
19  import org.w3c.dom.NodeList;
20  
21  import com.eviware.soapui.SoapUI;
22  import com.eviware.soapui.impl.wsdl.support.soap.SoapUtils;
23  import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
24  import com.eviware.soapui.impl.wsdl.support.wsa.WsaContainer;
25  import com.eviware.soapui.support.xml.XmlUtils;
26  
27  public class WssUtils
28  {
29  	public final static String WSSE_NAMESPACE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
30  	public final static String WSU_NAMESPACE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
31  
32  	String content;
33  	SoapVersion soapVersion;
34  
35  	public static String removeWSSOutgoing( String content, WsaContainer wsaContainer )
36  	{
37  		try
38  		{
39  			SoapVersion soapVersion = wsaContainer.getOperation().getInterface().getSoapVersion();
40  			XmlObject xmlContentObject = XmlObject.Factory.parse( content );
41  			Element header = ( Element )SoapUtils.getHeaderElement( xmlContentObject, soapVersion, true ).getDomNode();
42  
43  			NodeList headerProps = XmlUtils.getChildElements( header );
44  			for( int i = 0; i < headerProps.getLength(); i++ )
45  			{
46  				Node headerChild = headerProps.item( i );
47  				if( headerChild.getNamespaceURI().equals( WSSE_NAMESPACE ) )
48  				{
49  					header.removeChild( headerChild );
50  				}
51  			}
52  			content = xmlContentObject.xmlText();
53  		}
54  		catch( XmlException e )
55  		{
56  			SoapUI.logError( e );
57  		}
58  		return content;
59  	}
60  }