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