View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 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.submit.filters;
14  
15  import java.io.StringWriter;
16  
17  import org.w3c.dom.Document;
18  
19  import com.eviware.soapui.impl.wsdl.WsdlRequest;
20  import com.eviware.soapui.impl.wsdl.endpoint.DefaultEndpointStrategy;
21  import com.eviware.soapui.impl.wsdl.endpoint.DefaultEndpointStrategy.EndpointDefaults;
22  import com.eviware.soapui.impl.wsdl.submit.RequestFilter;
23  import com.eviware.soapui.impl.wsdl.submit.transports.http.BaseHttpRequestTransport;
24  import com.eviware.soapui.impl.wsdl.support.wss.OutgoingWss;
25  import com.eviware.soapui.impl.wsdl.support.wss.WssContainer;
26  import com.eviware.soapui.model.iface.SubmitContext;
27  import com.eviware.soapui.support.StringUtils;
28  import com.eviware.soapui.support.xml.XmlUtils;
29  
30  public class WssRequestFilter extends AbstractWssRequestFilter implements RequestFilter
31  {
32  	public void filterRequest( SubmitContext context, WsdlRequest wsdlRequest )
33  	{
34  		WssContainer wssContainer = wsdlRequest.getOperation().getInterface().getProject().getWssContainer();
35  		OutgoingWss outgoingWss = wssContainer.getOutgoingByName( wsdlRequest.getOutgoingWss() );
36  		
37  		DefaultEndpointStrategy des = ( DefaultEndpointStrategy ) wsdlRequest.getOperation().getInterface().getProject().getEndpointStrategy();
38  		EndpointDefaults endpointDefaults = des.getEndpointDefaults( context.expand( wsdlRequest.getEndpoint() ) );
39  		if( StringUtils.hasContent( endpointDefaults.getOutgoingWss() ))
40  			outgoingWss = wssContainer.getOutgoingByName( endpointDefaults.getOutgoingWss() );
41  		
42  		if( outgoingWss == null )
43  			return;
44  		
45  		try
46  		{
47  			Document wssDocument = getWssDocument( context );
48  			outgoingWss.processOutgoing( wssDocument, context );
49  			StringWriter writer = new StringWriter();
50  			XmlUtils.serialize( wssDocument, writer );
51  			context.setProperty( BaseHttpRequestTransport.REQUEST_CONTENT, writer.toString() );
52  		}
53  		catch( Exception e )
54  		{
55  			e.printStackTrace();
56  		}
57  	}
58  }