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;
    14
    15  import java.util.HashMap;
    16  import java.util.Map;
    17
    18  import com.eviware.soapui.impl.wsdl.submit.filters.HttpAuthenticationRequestFilter;
    19  import com.eviware.soapui.impl.wsdl.submit.filters.HttpProxyRequestFilter;
    20  import com.eviware.soapui.impl.wsdl.submit.filters.HttpSettingsRequestFilter;
    21  import com.eviware.soapui.impl.wsdl.submit.filters.PropertyExpansionRequestFilter;
    22  import com.eviware.soapui.impl.wsdl.submit.filters.RemoveEmptyContentRequestFilter;
    23  import com.eviware.soapui.impl.wsdl.submit.filters.SoapHeadersRequestFilter;
    24  import com.eviware.soapui.impl.wsdl.submit.filters.StripWhitespacesRequestFilter;
    25  import com.eviware.soapui.impl.wsdl.submit.filters.WsSecurityAuthenticationRequestFilter;
    26  import com.eviware.soapui.impl.wsdl.submit.transports.http.HttpClientRequestTransport;
    27  import com.eviware.soapui.model.iface.SubmitContext;
    28
    29  /***
    30   * Registry of available transports, currently hard-coded but should be configurable in the future.
    31   *
    32   * @author Ole.Matzura
    33   */
    34
    35  public class RequestTransportRegistry
    36  {
    37  	public static final String HTTP = "http";
    38  	public static final String HTTPS = "https";
    39
    40  	private static Map<String,RequestTransport> transports = new HashMap<String,RequestTransport>();
    41
    42  	static
    43  	{
    44  		HttpClientRequestTransport httpTransport = new HttpClientRequestTransport();
    45
    46  		httpTransport.addRequestFilter( new HttpSettingsRequestFilter() );
    47  		httpTransport.addRequestFilter( new SoapHeadersRequestFilter() );
    48  		httpTransport.addRequestFilter( new HttpProxyRequestFilter() );
    49  		httpTransport.addRequestFilter( new HttpAuthenticationRequestFilter() );
    50  		httpTransport.addRequestFilter( new WsSecurityAuthenticationRequestFilter() );
    51  		httpTransport.addRequestFilter( new PropertyExpansionRequestFilter() );
    52  		httpTransport.addRequestFilter( new RemoveEmptyContentRequestFilter() );
    53  		httpTransport.addRequestFilter( new StripWhitespacesRequestFilter() );
    54  	//	httpTransport.addRequestFilter( new ScriptExpansionRequestFilter() );
    55
    56  		transports.put( HTTP, httpTransport );
    57  		transports.put( HTTPS, httpTransport );
    58  	}
    59
    60  	public static RequestTransport getTransport( String endpoint, SubmitContext submitContext ) throws MissingTransportException
    61     {
    62     	int ix = endpoint.indexOf( "://" );
    63     	if( ix == -1 )
    64     		throw new MissingTransportException( "Missing protocol in endpoint [" + endpoint + "]" );
    65
    66     	String protocol = endpoint.substring( 0, ix ).toLowerCase();
    67     	RequestTransport transport = transports.get( protocol );
    68
    69     	if( transport == null )
    70     		throw new MissingTransportException( "Missing transport for protocol [" + protocol + "]" );
    71
    72     	return transport;
    73     }
    74
    75     public static class MissingTransportException extends Exception
    76  	{
    77  		public MissingTransportException(String msg)
    78  		{
    79  			super( msg );
    80  		}
    81  	}
    82  }