01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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: public static final String HTTP = "http";
37: public static final String HTTPS = "https";
38:
39: private static Map<String, RequestTransport> transports = new HashMap<String, RequestTransport>();
40:
41: static {
42: HttpClientRequestTransport httpTransport = new HttpClientRequestTransport();
43:
44: httpTransport.addRequestFilter(new HttpSettingsRequestFilter());
45: httpTransport.addRequestFilter(new SoapHeadersRequestFilter());
46: httpTransport.addRequestFilter(new HttpProxyRequestFilter());
47: httpTransport
48: .addRequestFilter(new HttpAuthenticationRequestFilter());
49: httpTransport
50: .addRequestFilter(new WsSecurityAuthenticationRequestFilter());
51: httpTransport
52: .addRequestFilter(new PropertyExpansionRequestFilter());
53: httpTransport
54: .addRequestFilter(new RemoveEmptyContentRequestFilter());
55: httpTransport
56: .addRequestFilter(new StripWhitespacesRequestFilter());
57: // httpTransport.addRequestFilter( new ScriptExpansionRequestFilter() );
58:
59: transports.put(HTTP, httpTransport);
60: transports.put(HTTPS, httpTransport);
61: }
62:
63: public static RequestTransport getTransport(String endpoint,
64: SubmitContext submitContext)
65: throws MissingTransportException {
66: int ix = endpoint.indexOf("://");
67: if (ix == -1)
68: throw new MissingTransportException(
69: "Missing protocol in endpoint [" + endpoint + "]");
70:
71: String protocol = endpoint.substring(0, ix).toLowerCase();
72: RequestTransport transport = transports.get(protocol);
73:
74: if (transport == null)
75: throw new MissingTransportException(
76: "Missing transport for protocol [" + protocol + "]");
77:
78: return transport;
79: }
80:
81: public static class MissingTransportException extends Exception {
82: public MissingTransportException(String msg) {
83: super(msg);
84: }
85: }
86: }
|