View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
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.impl.wsdl.WsdlInterface;
18  import com.eviware.soapui.impl.wsdl.WsdlRequest;
19  import com.eviware.soapui.impl.wsdl.submit.RequestFilter;
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.settings.HttpSettings;
25  
26  /***
27   * RequestFilter that adds SOAP 1.1 specific headers
28   * 
29   * @author Ole.Matzura
30   */
31  
32  public class SoapHeadersRequestFilter implements RequestFilter
33  {
34  	public void filterRequest(SubmitContext context, WsdlRequest wsdlRequest)
35  	{
36  		TimeablePostMethod postMethod = (TimeablePostMethod) context.getProperty( BaseHttpRequestTransport.POST_METHOD );
37  		
38  		WsdlInterface wsdlInterface = (WsdlInterface) wsdlRequest.getOperation().getInterface();
39  		String strURL = wsdlInterface.getEndpointURL(wsdlRequest.getEndpoint());
40  		strURL = PropertyExpansionRequestFilter.expandProperties( context, strURL );
41  		try
42  		{
43  			postMethod.setURI(new URI(strURL, wsdlRequest.getSettings().getBoolean( HttpSettings.ENCODED_URLS )));
44  		}
45  		catch ( Exception e)
46  		{
47  			e.printStackTrace();
48  		}
49  		
50  		//	 init content-type and encoding
51  		String encoding = wsdlRequest.getEncoding();
52  		
53  		SoapVersion soapVersion = wsdlInterface.getSoapVersion();
54  		postMethod.setRequestHeader( "Content-Type", soapVersion.getContentTypeHttpHeader( encoding ));
55  
56  		// set soapaction
57  		String soapAction = wsdlRequest.getOperation().getAction();
58  		if (soapAction == null || soapAction.length() == 0)
59  		{
60  			soapAction = "\"\"";
61  		}
62  		else
63  		{
64  			soapAction = "\"" + soapAction + "\"";
65  		}
66  
67  		postMethod.setRequestHeader("SOAPAction", soapAction);
68  
69  	}
70  }