Author: jfrederic.clere(a)jboss.com
Date: 2008-03-13 09:37:06 -0400 (Thu, 13 Mar 2008)
New Revision: 1435
Added:
sandbox/httpd/src/java/ConfigMethod.java
sandbox/httpd/src/java/DisableMethod.java
sandbox/httpd/src/java/EnableMethod.java
sandbox/httpd/src/java/RemoveMethod.java
sandbox/httpd/src/java/StatusMethod.java
sandbox/httpd/src/java/StopMethod.java
sandbox/httpd/src/java/TestHttpClient.java
Log:
Add basic Method for prototyping.
Added: sandbox/httpd/src/java/ConfigMethod.java
===================================================================
--- sandbox/httpd/src/java/ConfigMethod.java (rev 0)
+++ sandbox/httpd/src/java/ConfigMethod.java 2008-03-13 13:37:06 UTC (rev 1435)
@@ -0,0 +1,9 @@
+import org.apache.commons.httpclient.methods.PostMethod;
+public class ConfigMethod extends PostMethod {
+ public String getName() {
+ return "CONFIG";
+ }
+ public ConfigMethod(String uri) {
+ super(uri);
+ }
+}
Added: sandbox/httpd/src/java/DisableMethod.java
===================================================================
--- sandbox/httpd/src/java/DisableMethod.java (rev 0)
+++ sandbox/httpd/src/java/DisableMethod.java 2008-03-13 13:37:06 UTC (rev 1435)
@@ -0,0 +1,9 @@
+import org.apache.commons.httpclient.methods.PostMethod;
+public class DisableMethod extends PostMethod {
+ public String getName() {
+ return "DISABLE-APP";
+ }
+ public DisableMethod(String uri) {
+ super(uri);
+ }
+}
Added: sandbox/httpd/src/java/EnableMethod.java
===================================================================
--- sandbox/httpd/src/java/EnableMethod.java (rev 0)
+++ sandbox/httpd/src/java/EnableMethod.java 2008-03-13 13:37:06 UTC (rev 1435)
@@ -0,0 +1,9 @@
+import org.apache.commons.httpclient.methods.PostMethod;
+public class EnableMethod extends PostMethod {
+ public String getName() {
+ return "ENABLE-APP";
+ }
+ public EnableMethod(String uri) {
+ super(uri);
+ }
+}
Added: sandbox/httpd/src/java/RemoveMethod.java
===================================================================
--- sandbox/httpd/src/java/RemoveMethod.java (rev 0)
+++ sandbox/httpd/src/java/RemoveMethod.java 2008-03-13 13:37:06 UTC (rev 1435)
@@ -0,0 +1,9 @@
+import org.apache.commons.httpclient.methods.PostMethod;
+public class RemoveMethod extends PostMethod {
+ public String getName() {
+ return "REMOVE-APP";
+ }
+ public RemoveMethod(String uri) {
+ super(uri);
+ }
+}
Added: sandbox/httpd/src/java/StatusMethod.java
===================================================================
--- sandbox/httpd/src/java/StatusMethod.java (rev 0)
+++ sandbox/httpd/src/java/StatusMethod.java 2008-03-13 13:37:06 UTC (rev 1435)
@@ -0,0 +1,9 @@
+import org.apache.commons.httpclient.methods.PostMethod;
+public class StatusMethod extends PostMethod {
+ public String getName() {
+ return "STATUS";
+ }
+ public StatusMethod(String uri) {
+ super(uri);
+ }
+}
Added: sandbox/httpd/src/java/StopMethod.java
===================================================================
--- sandbox/httpd/src/java/StopMethod.java (rev 0)
+++ sandbox/httpd/src/java/StopMethod.java 2008-03-13 13:37:06 UTC (rev 1435)
@@ -0,0 +1,9 @@
+import org.apache.commons.httpclient.methods.PostMethod;
+public class StopMethod extends PostMethod {
+ public String getName() {
+ return "STOP-APP";
+ }
+ public StopMethod(String uri) {
+ super(uri);
+ }
+}
Added: sandbox/httpd/src/java/TestHttpClient.java
===================================================================
--- sandbox/httpd/src/java/TestHttpClient.java (rev 0)
+++ sandbox/httpd/src/java/TestHttpClient.java 2008-03-13 13:37:06 UTC (rev 1435)
@@ -0,0 +1,57 @@
+import org.apache.commons.httpclient.*;
+import org.apache.commons.httpclient.methods.*;
+
+public class TestHttpClient
+{
+
+ /**
+ *
+ * Usage:
+ * java TestHttpClient
http://mywebserver:80/ test
+ *
+ * @param args command line arguments
+ * Argument 0 is a URL to a web server
+ * Argument 1 is the command to execute.
+ *
+ */
+ public static void main(String[] args) throws Exception
+ {
+ if (args.length != 2)
+ {
+ System.err.println("missing command line arguments");
+ System.exit(1);
+ }
+ runit(args[0], args[1]);
+ }
+ public static int runit(String URL, String Command) throws Exception
+ {
+
+ HttpClient httpClient = new HttpClient();
+ DisableMethod pm = new DisableMethod(URL);
+ System.out.println("Connecting to " + URL);
+ pm.addParameter("firstname","moi");
+ pm.addParameter("lastname", "me");
+ pm.addParameter("context", "/myapp");
+ pm.addParameter("context", "/yourapp");
+ pm.addParameter("context", "/hisapp");
+/*
+ pm.setRequestEntity(new
StringRequestEntity("firstname=moi-meme&lastname=toi-meme&comment=test",
+
"application/x-www-form-urlencoded",
+ "UTF8"));
+ */
+ Integer connectionTimeout = 40000;
+ pm.getParams().setParameter("http.socket.timeout",
connectionTimeout);
+ pm.getParams().setParameter("http.connection.timeout",
connectionTimeout);
+ httpClient.getParams().setParameter("http.socket.timeout",
connectionTimeout);
+ httpClient.getParams().setParameter("http.connection.timeout",
connectionTimeout);
+
+ int httpResponseCode = 0;
+ try {
+ httpResponseCode = httpClient.executeMethod(pm);
+ System.out.println("response: " + httpResponseCode);
+ } catch(HttpException e) {
+ e.printStackTrace();
+ }
+ return httpResponseCode;
+ }
+}