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 * Remote-Call with HTTP protocoll.
14 *
15 * @author Linke
16 *
17 */
18 public abstract class AbstractHttpExecutor extends Executor {
19
20 protected HttpClient httpClient = null;
21 protected String url = "";
22
23 protected HttpClient createHttpClient () {
24 if (httpClient == null) {
25 httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
26
27
28 String lvProxyHost = System.getProperty("http.proxyHost");
29 String lvProxyPort = System.getProperty("http.proxyPort");
30 int lvProxyPortInt = -1;
31 try {
32 if (lvProxyPort != null) { lvProxyPortInt = Integer.parseInt(lvProxyPort); }
33 } catch (Exception e) {
34 if (log.isDebugEnabled()) { log.debug("Port is not Integer!", e); }
35 }
36 if ((lvProxyHost != null) && (lvProxyPortInt > 0)) {
37 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 return httpClient;
43 }
44
45 protected String getParameterTypesStrings(Class pvClass[]) {
46 StringBuffer lvBuffer = new StringBuffer();
47 if ((pvClass == null) || (pvClass.length == 0)) {
48 return lvBuffer.toString();
49 } else {
50 lvBuffer.append("&").append(Constant.PARAM_TYPES).append("=");
51 for (int i = 0; i < pvClass.length; i++) {
52 lvBuffer.append(pvClass[i].getName()).append(",");
53 }
54 return lvBuffer.toString().substring(0, (lvBuffer.length()-1));
55 }
56 }
57
58 public Object execute(Class pvProxyClass, Object pvProxy, Method pvMethod, Object pvArgs[]) throws Exception {
59 createHttpClient();
60
61 url = getInvocationStrategy().toString();
62 url = url + getParameterTypesStrings(pvMethod.getParameterTypes());
63 if (log.isDebugEnabled()) { log.debug("Crispy-Http-Client invocation String: " + url); }
64
65 return null;
66 }
67
68 }