|
1 |
| package net.sf.crispy.impl; |
|
2 |
| |
|
3 |
| import java.lang.reflect.Method; |
|
4 |
| |
|
5 |
| import net.sf.crispy.Executor; |
|
6 |
| import net.sf.crispy.impl.http.Constant; |
|
7 |
| |
|
8 |
| import org.apache.commons.httpclient.HttpClient; |
|
9 |
| import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| public abstract class AbstractHttpExecutor extends Executor { |
|
19 |
| |
|
20 |
| protected HttpClient httpClient = null; |
|
21 |
| protected String url = ""; |
|
22 |
| |
|
23 |
106
| protected HttpClient createHttpClient () {
|
|
24 |
106
| if (httpClient == null) {
|
|
25 |
62
| httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
|
|
26 |
| |
|
27 |
| |
|
28 |
62
| String lvProxyHost = System.getProperty("http.proxyHost");
|
|
29 |
62
| String lvProxyPort = System.getProperty("http.proxyPort");
|
|
30 |
62
| int lvProxyPortInt = -1;
|
|
31 |
62
| try {
|
|
32 |
0
| if (lvProxyPort != null) { lvProxyPortInt = Integer.parseInt(lvProxyPort); }
|
|
33 |
| } catch (Exception e) { |
|
34 |
| if (log.isDebugEnabled()) { log.debug("Port is not Integer!", e); } |
|
35 |
| } |
|
36 |
62
| if ((lvProxyHost != null) && (lvProxyPortInt > 0)) {
|
|
37 |
0
| httpClient.getHostConfiguration().setProxy(lvProxyHost, lvProxyPortInt);
|
|
38 |
| if (log.isDebugEnabled()) { log.debug("User Proxy Host: " + lvProxyHost + " and Port: " + lvProxyPortInt); } |
|
39 |
| } |
|
40 |
| if (log.isDebugEnabled()) { log.debug("Create RestClient: " + httpClient + " - URL: " + getUrlAndPort()); } |
|
41 |
| } |
|
42 |
106
| return httpClient;
|
|
43 |
| } |
|
44 |
| |
|
45 |
106
| protected String getParameterTypesStrings(Class pvClass[]) {
|
|
46 |
106
| StringBuffer lvBuffer = new StringBuffer();
|
|
47 |
106
| if ((pvClass == null) || (pvClass.length == 0)) {
|
|
48 |
6
| return lvBuffer.toString();
|
|
49 |
| } else { |
|
50 |
100
| lvBuffer.append("&").append(Constant.PARAM_TYPES).append("=");
|
|
51 |
100
| for (int i = 0; i < pvClass.length; i++) {
|
|
52 |
138
| lvBuffer.append(pvClass[i].getName()).append(",");
|
|
53 |
| } |
|
54 |
100
| return lvBuffer.toString().substring(0, (lvBuffer.length()-1));
|
|
55 |
| } |
|
56 |
| } |
|
57 |
| |
|
58 |
106
| public Object execute(Class pvProxyClass, Object pvProxy, Method pvMethod, Object pvArgs[]) throws Exception {
|
|
59 |
106
| createHttpClient();
|
|
60 |
| |
|
61 |
106
| url = getInvocationStrategy().toString();
|
|
62 |
106
| url = url + getParameterTypesStrings(pvMethod.getParameterTypes());
|
|
63 |
| if (log.isDebugEnabled()) { log.debug("Crispy-Http-Client invocation String: " + url); } |
|
64 |
| |
|
65 |
106
| return null;
|
|
66 |
| } |
|
67 |
| |
|
68 |
| } |