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.RequestFilter;
    21  import com.eviware.soapui.impl.wsdl.submit.transports.http.BaseHttpRequestTransport;
    22  import com.eviware.soapui.impl.wsdl.submit.transports.http.TimeablePostMethod;
    23  import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
    24  import com.eviware.soapui.model.iface.SubmitContext;
    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 implements RequestFilter
    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 = PropertyExpansionRequestFilter.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.getOperation().getAction();
    56
    57  		postMethod.setRequestHeader( "Content-Type", soapVersion.getContentTypeHttpHeader( encoding, soapAction ));
    58
    59  		String soapActionHeader = soapVersion.getSoapActionHeader( soapAction );
    60  		if( soapActionHeader != null )
    61  			postMethod.setRequestHeader( "SOAPAction", soapActionHeader );
    62
    63  	}
    64  }