1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.providers.http; |
12 | |
|
13 | |
import org.mule.config.i18n.CoreMessages; |
14 | |
import org.mule.providers.tcp.TcpConnector; |
15 | |
import org.mule.umo.UMOComponent; |
16 | |
import org.mule.umo.endpoint.UMOEndpoint; |
17 | |
import org.mule.umo.lifecycle.InitialisationException; |
18 | |
import org.mule.umo.provider.UMOConnector; |
19 | |
import org.mule.umo.provider.UMOMessageReceiver; |
20 | |
|
21 | |
import java.util.HashMap; |
22 | |
import java.util.Iterator; |
23 | |
import java.util.Map; |
24 | |
|
25 | |
import org.apache.commons.httpclient.HttpConnectionManager; |
26 | |
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; |
27 | |
import org.apache.commons.httpclient.params.HttpConnectionManagerParams; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 0 | public class HttpConnector extends TcpConnector |
48 | |
{ |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
public static final String HTTP_STATUS_PROPERTY = "http.status"; |
54 | |
public static final String HTTP_VERSION_PROPERTY = "http.version"; |
55 | |
public static final String HTTP_CUSTOM_HEADERS_MAP_PROPERTY = "http.custom.headers"; |
56 | |
public static final String HTTP_METHOD_PROPERTY = "http.method"; |
57 | |
public static final String HTTP_REQUEST_PROPERTY = "http.request"; |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
public static final String HTTP_PARAMS_PROPERTY = "http.params"; |
64 | |
public static final String HTTP_GET_BODY_PARAM_PROPERTY = "http.get.body.param"; |
65 | |
public static final String DEFAULT_HTTP_GET_BODY_PARAM_PROPERTY = "body"; |
66 | |
public static final String HTTP_POST_BODY_PARAM_PROPERTY = "http.post.body.param"; |
67 | |
|
68 | |
public static final String HTTP_COOKIE_SPEC_PROPERTY = "cookieSpec"; |
69 | |
public static final String HTTP_COOKIES_PROPERTY = "cookies"; |
70 | |
public static final String HTTP_ENABLE_COOKIES_PROPERTY = "enableCookies"; |
71 | |
|
72 | |
public static final String COOKIE_SPEC_NETSCAPE = "netscape"; |
73 | |
public static final String COOKIE_SPEC_RFC2109 = "rcf2109"; |
74 | |
|
75 | 0 | private String proxyHostname = null; |
76 | |
|
77 | 0 | private int proxyPort = HttpConstants.DEFAULT_HTTP_PORT; |
78 | |
|
79 | 0 | private String proxyUsername = null; |
80 | |
|
81 | 0 | private String proxyPassword = null; |
82 | |
|
83 | |
private String cookieSpec; |
84 | |
|
85 | 0 | private boolean enableCookies = false; |
86 | |
|
87 | |
protected HttpConnectionManager clientConnectionManager; |
88 | |
|
89 | |
|
90 | |
|
91 | |
protected void doInitialise() throws InitialisationException |
92 | |
{ |
93 | 0 | super.doInitialise(); |
94 | 0 | if(clientConnectionManager==null) |
95 | |
{ |
96 | 0 | clientConnectionManager = new MultiThreadedHttpConnectionManager(); |
97 | 0 | HttpConnectionManagerParams params = new HttpConnectionManagerParams(); |
98 | 0 | if(getSendBufferSize()!= INT_VALUE_NOT_SET ) params.setSendBufferSize(getSendBufferSize()); |
99 | 0 | if(getReceiveBufferSize()!= INT_VALUE_NOT_SET ) params.setReceiveBufferSize(getReceiveBufferSize()); |
100 | 0 | if(getSendTimeout()!= INT_VALUE_NOT_SET ) params.setSoTimeout(getSendTimeout()); |
101 | 0 | if(getSendSocketLinger()!= INT_VALUE_NOT_SET ) params.setLinger(getSendSocketLinger()); |
102 | |
|
103 | 0 | params.setTcpNoDelay(isSendTcpNoDelay()); |
104 | 0 | params.setMaxTotalConnections(getDispatcherThreadingProfile().getMaxThreadsActive()); |
105 | 0 | params.setDefaultMaxConnectionsPerHost(getDispatcherThreadingProfile().getMaxThreadsActive()); |
106 | |
|
107 | 0 | clientConnectionManager.setParams(params); |
108 | |
} |
109 | 0 | } |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
public UMOMessageReceiver registerListener(UMOComponent component, UMOEndpoint endpoint) throws Exception |
115 | |
{ |
116 | 0 | if (endpoint != null) |
117 | |
{ |
118 | 0 | Map endpointProperties = endpoint.getProperties(); |
119 | 0 | if (endpointProperties != null) |
120 | |
{ |
121 | |
|
122 | 0 | Map newProperties = new HashMap(endpointProperties.size()); |
123 | 0 | for (Iterator entries = endpointProperties.entrySet().iterator(); entries.hasNext();) |
124 | |
{ |
125 | 0 | Map.Entry entry = (Map.Entry)entries.next(); |
126 | 0 | Object key = entry.getKey(); |
127 | 0 | Object normalizedKey = HttpConstants.ALL_HEADER_NAMES.get(key); |
128 | 0 | if (normalizedKey != null) |
129 | |
{ |
130 | |
|
131 | 0 | key = normalizedKey; |
132 | |
} |
133 | 0 | newProperties.put(key, entry.getValue()); |
134 | |
} |
135 | |
|
136 | 0 | endpoint.setProperties(newProperties); |
137 | |
} |
138 | |
} |
139 | |
|
140 | 0 | return super.registerListener(component, endpoint); |
141 | |
} |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
protected Object getReceiverKey(UMOComponent component, UMOEndpoint endpoint) |
151 | |
{ |
152 | 0 | String key = endpoint.getEndpointURI().toString(); |
153 | 0 | int i = key.indexOf('?'); |
154 | 0 | if (i > -1) |
155 | |
{ |
156 | 0 | key = key.substring(0, i); |
157 | |
} |
158 | 0 | return key; |
159 | |
} |
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
public String getProtocol() |
165 | |
{ |
166 | 0 | return "http"; |
167 | |
} |
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
public String getProxyHostname() |
173 | |
{ |
174 | 0 | return proxyHostname; |
175 | |
} |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
public String getProxyPassword() |
181 | |
{ |
182 | 0 | return proxyPassword; |
183 | |
} |
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
public int getProxyPort() |
189 | |
{ |
190 | 0 | return proxyPort; |
191 | |
} |
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
public String getProxyUsername() |
197 | |
{ |
198 | 0 | return proxyUsername; |
199 | |
} |
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
public void setProxyHostname(String host) |
205 | |
{ |
206 | 0 | proxyHostname = host; |
207 | 0 | } |
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
public void setProxyPassword(String string) |
213 | |
{ |
214 | 0 | proxyPassword = string; |
215 | 0 | } |
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
public void setProxyPort(int port) |
221 | |
{ |
222 | 0 | proxyPort = port; |
223 | 0 | } |
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
public void setProxyUsername(String string) |
229 | |
{ |
230 | 0 | proxyUsername = string; |
231 | 0 | } |
232 | |
|
233 | |
public Map getReceivers() |
234 | |
{ |
235 | 0 | return this.receivers; |
236 | |
} |
237 | |
|
238 | |
public String getCookieSpec() |
239 | |
{ |
240 | 0 | return cookieSpec; |
241 | |
} |
242 | |
|
243 | |
public void setCookieSpec(String cookieSpec) |
244 | |
{ |
245 | 0 | if (!(cookieSpec.equalsIgnoreCase(COOKIE_SPEC_NETSCAPE) && cookieSpec.equalsIgnoreCase(COOKIE_SPEC_RFC2109))) |
246 | |
{ |
247 | 0 | throw new IllegalArgumentException( |
248 | |
CoreMessages.propertyHasInvalidValue("cookieSpec", cookieSpec).toString()); |
249 | |
} |
250 | 0 | this.cookieSpec = cookieSpec; |
251 | 0 | } |
252 | |
|
253 | |
public boolean isEnableCookies() |
254 | |
{ |
255 | 0 | return enableCookies; |
256 | |
} |
257 | |
|
258 | |
public void setEnableCookies(boolean enableCookies) |
259 | |
{ |
260 | 0 | this.enableCookies = enableCookies; |
261 | 0 | } |
262 | |
|
263 | |
|
264 | |
public HttpConnectionManager getClientConnectionManager() |
265 | |
{ |
266 | 0 | return clientConnectionManager; |
267 | |
} |
268 | |
|
269 | |
public void setClientConnectionManager(HttpConnectionManager clientConnectionManager) |
270 | |
{ |
271 | 0 | this.clientConnectionManager = clientConnectionManager; |
272 | 0 | } |
273 | |
} |