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 org.apache.commons.httpclient.URI;
16  
17  import com.eviware.soapui.SoapUI;
18  import com.eviware.soapui.impl.wsdl.WsdlInterface;
19  import com.eviware.soapui.impl.wsdl.WsdlRequest;
20  import com.eviware.soapui.impl.wsdl.submit.transports.http.BaseHttpRequestTransport;
21  import com.eviware.soapui.impl.wsdl.submit.transports.http.TimeablePostMethod;
22  import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
23  import com.eviware.soapui.model.iface.SubmitContext;
24  import com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils;
25  import com.eviware.soapui.settings.HttpSettings;
26  
27  /***
28   * RequestFilter that adds SOAP specific headers
29   * 
30   * @author Ole.Matzura
31   */
32  
33  public class SoapHeadersRequestFilter extends AbstractRequestFilter
34  {
35  	public void filterRequest(SubmitContext context, WsdlRequest wsdlRequest)
36  	{
37  		TimeablePostMethod postMethod = (TimeablePostMethod) context.getProperty( BaseHttpRequestTransport.POST_METHOD );
38  		
39  		WsdlInterface wsdlInterface = (WsdlInterface) wsdlRequest.getOperation().getInterface();
40  		String strURL = wsdlRequest.getEndpoint();
41  		strURL = PropertyExpansionUtils.expandProperties( context, strURL );
42  		try
43  		{
44  			postMethod.setURI(new URI(strURL, wsdlRequest.getSettings().getBoolean( HttpSettings.ENCODED_URLS )));
45  		}
46  		catch ( Exception e)
47  		{
48  			SoapUI.logError( e );
49  		}
50  		
51  		//	 init content-type and encoding
52  		String encoding = wsdlRequest.getEncoding();
53  		
54  		SoapVersion soapVersion = wsdlInterface.getSoapVersion();
55  		String soapAction = wsdlRequest.isSkipSoapAction() ? null : wsdlRequest.getOperation().getAction();
56  		
57  		postMethod.setRequestHeader( "Content-Type", soapVersion.getContentTypeHttpHeader( encoding, soapAction ));
58  
59  		if( !wsdlRequest.isSkipSoapAction())
60  		{
61  			String soapActionHeader = soapVersion.getSoapActionHeader( soapAction );
62  			if( soapActionHeader != null )
63  				postMethod.setRequestHeader( "SOAPAction", soapActionHeader );
64  		}
65  	}
66  }