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 | 90 | 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 | 90 | private String proxyHostname = null; |
76 | |
|
77 | 90 | private int proxyPort = HttpConstants.DEFAULT_HTTP_PORT; |
78 | |
|
79 | 90 | private String proxyUsername = null; |
80 | |
|
81 | 90 | private String proxyPassword = null; |
82 | |
|
83 | |
private String cookieSpec; |
84 | |
|
85 | 90 | private boolean enableCookies = false; |
86 | |
|
87 | |
protected HttpConnectionManager clientConnectionManager; |
88 | |
|
89 | |
|
90 | |
|
91 | |
protected void doInitialise() throws InitialisationException |
92 | |
{ |
93 | 88 | super.doInitialise(); |
94 | 88 | if (clientConnectionManager == null) |
95 | |
{ |
96 | 84 | clientConnectionManager = new MultiThreadedHttpConnectionManager(); |
97 | 84 | HttpConnectionManagerParams params = new HttpConnectionManagerParams(); |
98 | 84 | if (getSendBufferSize() != INT_VALUE_NOT_SET) |
99 | |
{ |
100 | 2 | params.setSendBufferSize(getSendBufferSize()); |
101 | |
} |
102 | 84 | if (getReceiveBufferSize() != INT_VALUE_NOT_SET) |
103 | |
{ |
104 | 0 | params.setReceiveBufferSize(getReceiveBufferSize()); |
105 | |
} |
106 | 84 | if (getSendTimeout() != INT_VALUE_NOT_SET) |
107 | |
{ |
108 | 0 | params.setSoTimeout(getSendTimeout()); |
109 | |
} |
110 | 84 | if (getSendSocketLinger() != INT_VALUE_NOT_SET) |
111 | |
{ |
112 | 0 | params.setLinger(getSendSocketLinger()); |
113 | |
} |
114 | |
|
115 | 84 | params.setTcpNoDelay(isSendTcpNoDelay()); |
116 | 84 | params.setMaxTotalConnections(getDispatcherThreadingProfile().getMaxThreadsActive()); |
117 | 84 | params.setDefaultMaxConnectionsPerHost(getDispatcherThreadingProfile().getMaxThreadsActive()); |
118 | |
|
119 | 84 | clientConnectionManager.setParams(params); |
120 | |
} |
121 | 88 | } |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
public UMOMessageReceiver registerListener(UMOComponent component, UMOEndpoint endpoint) throws Exception |
127 | |
{ |
128 | 84 | if (endpoint != null) |
129 | |
{ |
130 | 76 | Map endpointProperties = endpoint.getProperties(); |
131 | 76 | if (endpointProperties != null) |
132 | |
{ |
133 | |
|
134 | 76 | Map newProperties = new HashMap(endpointProperties.size()); |
135 | 76 | for (Iterator entries = endpointProperties.entrySet().iterator(); entries.hasNext();) |
136 | |
{ |
137 | 4 | Map.Entry entry = (Map.Entry) entries.next(); |
138 | 4 | Object key = entry.getKey(); |
139 | 4 | Object normalizedKey = HttpConstants.ALL_HEADER_NAMES.get(key); |
140 | 4 | if (normalizedKey != null) |
141 | |
{ |
142 | |
|
143 | 2 | key = normalizedKey; |
144 | |
} |
145 | 4 | newProperties.put(key, entry.getValue()); |
146 | 4 | } |
147 | |
|
148 | 76 | endpoint.setProperties(newProperties); |
149 | |
} |
150 | |
} |
151 | |
|
152 | 84 | return super.registerListener(component, endpoint); |
153 | |
} |
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
protected Object getReceiverKey(UMOComponent component, UMOEndpoint endpoint) |
163 | |
{ |
164 | 284 | String key = endpoint.getEndpointURI().toString(); |
165 | 284 | int i = key.indexOf('?'); |
166 | 284 | if (i > -1) |
167 | |
{ |
168 | 0 | key = key.substring(0, i); |
169 | |
} |
170 | 284 | return key; |
171 | |
} |
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
public String getProtocol() |
177 | |
{ |
178 | 528 | return "http"; |
179 | |
} |
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
public String getProxyHostname() |
185 | |
{ |
186 | 126 | return proxyHostname; |
187 | |
} |
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
public String getProxyPassword() |
193 | |
{ |
194 | 0 | return proxyPassword; |
195 | |
} |
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
public int getProxyPort() |
201 | |
{ |
202 | 0 | return proxyPort; |
203 | |
} |
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
public String getProxyUsername() |
209 | |
{ |
210 | 46 | return proxyUsername; |
211 | |
} |
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
public void setProxyHostname(String host) |
217 | |
{ |
218 | 0 | proxyHostname = host; |
219 | 0 | } |
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
public void setProxyPassword(String string) |
225 | |
{ |
226 | 0 | proxyPassword = string; |
227 | 0 | } |
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
public void setProxyPort(int port) |
233 | |
{ |
234 | 0 | proxyPort = port; |
235 | 0 | } |
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
public void setProxyUsername(String string) |
241 | |
{ |
242 | 0 | proxyUsername = string; |
243 | 0 | } |
244 | |
|
245 | |
public Map getReceivers() |
246 | |
{ |
247 | 6 | return this.receivers; |
248 | |
} |
249 | |
|
250 | |
public String getCookieSpec() |
251 | |
{ |
252 | 136 | return cookieSpec; |
253 | |
} |
254 | |
|
255 | |
public void setCookieSpec(String cookieSpec) |
256 | |
{ |
257 | 0 | if (!(COOKIE_SPEC_NETSCAPE.equalsIgnoreCase(cookieSpec) || COOKIE_SPEC_RFC2109.equalsIgnoreCase(cookieSpec))) |
258 | |
{ |
259 | 0 | throw new IllegalArgumentException( |
260 | |
CoreMessages.propertyHasInvalidValue("cookieSpec", cookieSpec).toString()); |
261 | |
} |
262 | 0 | this.cookieSpec = cookieSpec; |
263 | 0 | } |
264 | |
|
265 | |
public boolean isEnableCookies() |
266 | |
{ |
267 | 136 | return enableCookies; |
268 | |
} |
269 | |
|
270 | |
public void setEnableCookies(boolean enableCookies) |
271 | |
{ |
272 | 0 | this.enableCookies = enableCookies; |
273 | 0 | } |
274 | |
|
275 | |
|
276 | |
public HttpConnectionManager getClientConnectionManager() |
277 | |
{ |
278 | 48 | return clientConnectionManager; |
279 | |
} |
280 | |
|
281 | |
public void setClientConnectionManager(HttpConnectionManager clientConnectionManager) |
282 | |
{ |
283 | 0 | this.clientConnectionManager = clientConnectionManager; |
284 | 0 | } |
285 | |
} |