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.submit.filters;
14  
15  import org.apache.commons.httpclient.HttpMethod;
16  
17  import com.eviware.soapui.impl.wsdl.WsdlInterface;
18  import com.eviware.soapui.impl.wsdl.WsdlRequest;
19  import com.eviware.soapui.impl.wsdl.submit.transports.http.BaseHttpRequestTransport;
20  import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
21  import com.eviware.soapui.model.iface.SubmitContext;
22  
23  /***
24   * RequestFilter that adds SOAP specific headers
25   * 
26   * @author Ole.Matzura
27   */
28  
29  public class SoapHeadersRequestFilter extends AbstractRequestFilter
30  {
31  	public void filterWsdlRequest( SubmitContext context, WsdlRequest wsdlRequest )
32  	{
33  		HttpMethod postMethod = ( HttpMethod )context.getProperty( BaseHttpRequestTransport.HTTP_METHOD );
34  
35  		WsdlInterface wsdlInterface = ( WsdlInterface )wsdlRequest.getOperation().getInterface();
36  
37  		// init content-type and encoding
38  		String encoding = System.getProperty( "soapui.request.encoding", wsdlRequest.getEncoding() );
39  
40  		SoapVersion soapVersion = wsdlInterface.getSoapVersion();
41  		String soapAction = wsdlRequest.isSkipSoapAction() ? null : wsdlRequest.getOperation().getAction();
42  
43  		postMethod.setRequestHeader( "Content-Type", soapVersion.getContentTypeHttpHeader( encoding, soapAction ) );
44  
45  		if( !wsdlRequest.isSkipSoapAction() )
46  		{
47  			String soapActionHeader = soapVersion.getSoapActionHeader( soapAction );
48  			if( soapActionHeader != null )
49  				postMethod.setRequestHeader( "SOAPAction", soapActionHeader );
50  		}
51  	}
52  }