Author: jfrederic.clere(a)jboss.com
Date: 2008-05-22 07:25:43 -0400 (Thu, 22 May 2008)
New Revision: 1611
Added:
trunk/mod_cluster/test/java/CauseErrorMethod.java
trunk/mod_cluster/test/java/ConfigMethod.java
trunk/mod_cluster/test/java/DisableMethod.java
trunk/mod_cluster/test/java/DumpMethod.java
trunk/mod_cluster/test/java/EnableMethod.java
trunk/mod_cluster/test/java/InfoMethod.java
trunk/mod_cluster/test/java/RemoveMethod.java
trunk/mod_cluster/test/java/StatusMethod.java
trunk/mod_cluster/test/java/StopMethod.java
trunk/mod_cluster/test/java/TestHttpClient.java
trunk/mod_cluster/test/java/TestHttpClient.sh
Log:
Java tools using httpclient to test.
Added: trunk/mod_cluster/test/java/CauseErrorMethod.java
===================================================================
--- trunk/mod_cluster/test/java/CauseErrorMethod.java (rev 0)
+++ trunk/mod_cluster/test/java/CauseErrorMethod.java 2008-05-22 11:25:43 UTC (rev 1611)
@@ -0,0 +1,9 @@
+import org.apache.commons.httpclient.methods.PostMethod;
+public class CauseErrorMethod extends PostMethod {
+ public String getName() {
+ return "ERROR";
+ }
+ public CauseErrorMethod(String uri) {
+ super(uri);
+ }
+}
Added: trunk/mod_cluster/test/java/ConfigMethod.java
===================================================================
--- trunk/mod_cluster/test/java/ConfigMethod.java (rev 0)
+++ trunk/mod_cluster/test/java/ConfigMethod.java 2008-05-22 11:25:43 UTC (rev 1611)
@@ -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: trunk/mod_cluster/test/java/DisableMethod.java
===================================================================
--- trunk/mod_cluster/test/java/DisableMethod.java (rev 0)
+++ trunk/mod_cluster/test/java/DisableMethod.java 2008-05-22 11:25:43 UTC (rev 1611)
@@ -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: trunk/mod_cluster/test/java/DumpMethod.java
===================================================================
--- trunk/mod_cluster/test/java/DumpMethod.java (rev 0)
+++ trunk/mod_cluster/test/java/DumpMethod.java 2008-05-22 11:25:43 UTC (rev 1611)
@@ -0,0 +1,9 @@
+import org.apache.commons.httpclient.methods.PostMethod;
+public class DumpMethod extends PostMethod {
+ public String getName() {
+ return "DUMP";
+ }
+ public DumpMethod(String uri) {
+ super(uri);
+ }
+}
Added: trunk/mod_cluster/test/java/EnableMethod.java
===================================================================
--- trunk/mod_cluster/test/java/EnableMethod.java (rev 0)
+++ trunk/mod_cluster/test/java/EnableMethod.java 2008-05-22 11:25:43 UTC (rev 1611)
@@ -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: trunk/mod_cluster/test/java/InfoMethod.java
===================================================================
--- trunk/mod_cluster/test/java/InfoMethod.java (rev 0)
+++ trunk/mod_cluster/test/java/InfoMethod.java 2008-05-22 11:25:43 UTC (rev 1611)
@@ -0,0 +1,9 @@
+import org.apache.commons.httpclient.methods.PostMethod;
+public class InfoMethod extends PostMethod {
+ public String getName() {
+ return "INFO";
+ }
+ public InfoMethod(String uri) {
+ super(uri);
+ }
+}
Added: trunk/mod_cluster/test/java/RemoveMethod.java
===================================================================
--- trunk/mod_cluster/test/java/RemoveMethod.java (rev 0)
+++ trunk/mod_cluster/test/java/RemoveMethod.java 2008-05-22 11:25:43 UTC (rev 1611)
@@ -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: trunk/mod_cluster/test/java/StatusMethod.java
===================================================================
--- trunk/mod_cluster/test/java/StatusMethod.java (rev 0)
+++ trunk/mod_cluster/test/java/StatusMethod.java 2008-05-22 11:25:43 UTC (rev 1611)
@@ -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: trunk/mod_cluster/test/java/StopMethod.java
===================================================================
--- trunk/mod_cluster/test/java/StopMethod.java (rev 0)
+++ trunk/mod_cluster/test/java/StopMethod.java 2008-05-22 11:25:43 UTC (rev 1611)
@@ -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: trunk/mod_cluster/test/java/TestHttpClient.java
===================================================================
--- trunk/mod_cluster/test/java/TestHttpClient.java (rev 0)
+++ trunk/mod_cluster/test/java/TestHttpClient.java 2008-05-22 11:25:43 UTC (rev 1611)
@@ -0,0 +1,103 @@
+import org.apache.commons.httpclient.*;
+import org.apache.commons.httpclient.methods.*;
+
+public class TestHttpClient
+{
+
+ public static String JVMRoute = System.getProperty("JVMRoute",
"node1");
+ public static String Host = System.getProperty("Host",
"localhost");
+ /**
+ *
+ * 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();
+ PostMethod pm = null;
+ if (command.compareToIgnoreCase("ENABLE")==0) {
+ pm = (PostMethod) new EnableMethod(URL);
+ pm.addParameter("JVMRoute", JVMRoute);
+ pm.addParameter("context", "/myapp");
+ System.out.println("ENABLE");
+ }
+ else if (command.compareToIgnoreCase("DISABLE")==0) {
+ pm = (PostMethod) new DisableMethod(URL);
+ pm.addParameter("JVMRoute", JVMRoute);
+ pm.addParameter("context", "/myapp");
+ }
+ else if (command.compareToIgnoreCase("STOP")==0) {
+ pm = (PostMethod) new StopMethod(URL);
+ pm.addParameter("JVMRoute", JVMRoute);
+ pm.addParameter("context", "/myapp");
+ }
+ else if (command.compareToIgnoreCase("REMOVE")==0) {
+ pm = (PostMethod) new RemoveMethod(URL);
+ pm.addParameter("JVMRoute", JVMRoute);
+ pm.addParameter("context", "/hisapp");
+ }
+ else if (command.compareToIgnoreCase("CONFIG")==0) {
+ pm = (PostMethod) new ConfigMethod(URL);
+ pm.addParameter("JVMRoute", JVMRoute);
+ pm.addParameter("Domain", "domain1");
+ pm.addParameter("Host", Host);
+ pm.addParameter("Port", "8009");
+ pm.addParameter("Type", "ajp");
+ // pm.addParameter("Reversed", "yes");
+ pm.addParameter("Context", "/hisapp,/ourapp");
+ }
+ else if (command.compareToIgnoreCase("DUMP")==0) {
+ pm = (PostMethod) new DumpMethod(URL);
+ }
+ else if (command.compareToIgnoreCase("STATUS")==0) {
+ pm = (PostMethod) new StatusMethod(URL);
+ pm.addParameter("JVMRoute", JVMRoute);
+ pm.addParameter("Load", "50");
+ }
+ else if (command.compareToIgnoreCase("ERROR")==0) {
+ pm = (PostMethod) new CauseErrorMethod(URL);
+ }
+ else
+ pm = (PostMethod) new InfoMethod(URL);
+
+ System.out.println("Connecting to " + URL);
+
+ 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);
+ System.out.println("response: " + pm.getStatusLine());
+ if (httpResponseCode == 500) {
+ System.out.println(pm.getResponseHeader("Version"));
+ System.out.println(pm.getResponseHeader("Type"));
+ System.out.println(pm.getResponseHeader("Mess"));
+ }
+ int len = (int) pm.getResponseContentLength();
+ System.out.println("response:\n" +
pm.getResponseBodyAsString(len));
+ } catch(HttpException e) {
+ e.printStackTrace();
+ }
+ return httpResponseCode;
+ }
+}
Added: trunk/mod_cluster/test/java/TestHttpClient.sh
===================================================================
--- trunk/mod_cluster/test/java/TestHttpClient.sh (rev 0)
+++ trunk/mod_cluster/test/java/TestHttpClient.sh 2008-05-22 11:25:43 UTC (rev 1611)
@@ -0,0 +1,43 @@
+#
+# Copyright 2008 Red Hat Middleware, LLC.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#
http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software distributed
+# under the License is distributed on an "AS IS" BASIS,i
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+CLASSES=$HOME/java/commons-httpclient-3.1/commons-httpclient-3.1.jar
+javac -classpath $CLASSES *Method.java
+javac -classpath $CLASSES:. TestHttpClient.java
+CLASSES=$CLASSES:$HOME/java/commons-logging-1.0.4/commons-logging.jar:$HOME/java/commons-codec-1.3/commons-codec-1.3.jar:.
+
+HTTPD=localhost
+JVMROUTE=node1
+HOST=localhost
+SCHEME=http
+SECURITY="-Djavax.net.ssl.trustStore=$HOME/.keystore
-Djavax.net.ssl.keyStore=$HOME/CERTS/demoCA/test.p12
-Djavax.net.ssl.keyStorePassword=changeit
-Djavax.net.ssl.keyStoreType=\"PKCS12\""
+
+
+# Send a CONFIG command.
+java ${SECURITY} -classpath $CLASSES -DJVMRoute=${JVMROUTE} -DHost=${HOST}
-DJVMRoute=${JVMROUTE} -DHost=${HOST} TestHttpClient ${SCHEME}://${HTTPD}:6666/test_bla/
CONFIG
+
+java ${SECURITY} -classpath $CLASSES -DJVMRoute=${JVMROUTE} -DHost=${HOST} TestHttpClient
${SCHEME}://${HTTPD}:6666/test_bla/ DUMP
+
+# Send a ENABLE for /myapp
+java ${SECURITY} -classpath $CLASSES -DJVMRoute=${JVMROUTE} -DHost=${HOST} TestHttpClient
${SCHEME}://${HTTPD}:6666/test_bla/ ENABLE
+
+java ${SECURITY} -classpath $CLASSES -DJVMRoute=${JVMROUTE} -DHost=${HOST} TestHttpClient
${SCHEME}://${HTTPD}:6666/test_bla/ DUMP
+
+# Send a REMOVE for /hisapp
+java ${SECURITY} -classpath $CLASSES -DJVMRoute=${JVMROUTE} -DHost=${HOST} TestHttpClient
${SCHEME}://${HTTPD}:6666/test_bla/ REMOVE
+
+java ${SECURITY} -classpath $CLASSES -DJVMRoute=${JVMROUTE} -DHost=${HOST} TestHttpClient
${SCHEME}://${HTTPD}:6666/test_bla/ DUMP
+
+java ${SECURITY} -classpath $CLASSES -DJVMRoute=${JVMROUTE} -DHost=${HOST} TestHttpClient
${SCHEME}://${HTTPD}:6666/test_bla/ STATUS
+
+#java ${SECURITY} -classpath $CLASSES -DJVMRoute=${JVMROUTE} -DHost=${HOST}
TestHttpClient ${SCHEME}://${HTTPD}:6666/test_bla/ INFO