[webbeans-commits] Webbeans SVN: r2355 - in test-harness/trunk: tomcat and 1 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Wed Apr 8 15:00:07 EDT 2009
Author: pete.muir at jboss.org
Date: 2009-04-08 15:00:07 -0400 (Wed, 08 Apr 2009)
New Revision: 2355
Modified:
test-harness/trunk/pom.xml
test-harness/trunk/tomcat/
test-harness/trunk/tomcat/pom.xml
test-harness/trunk/tomcat/src/main/java/org/jboss/testharness/integration/tomcat/TomcatConnector.java
Log:
fixes for the tomcat connector
Modified: test-harness/trunk/pom.xml
===================================================================
--- test-harness/trunk/pom.xml 2009-04-08 18:59:16 UTC (rev 2354)
+++ test-harness/trunk/pom.xml 2009-04-08 19:00:07 UTC (rev 2355)
@@ -124,6 +124,12 @@
<artifactId>catalina</artifactId>
<version>6.0.18</version>
</dependency>
+
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ </dependency>
</dependencies>
</dependencyManagement>
Property changes on: test-harness/trunk/tomcat
___________________________________________________________________
Name: svn:ignore
+
.classpath
.project
target
bin
.settings
Modified: test-harness/trunk/tomcat/pom.xml
===================================================================
--- test-harness/trunk/tomcat/pom.xml 2009-04-08 18:59:16 UTC (rev 2354)
+++ test-harness/trunk/tomcat/pom.xml 2009-04-08 19:00:07 UTC (rev 2355)
@@ -17,16 +17,16 @@
<groupId>org.jboss.test-harness</groupId>
<artifactId>jboss-test-harness-api</artifactId>
</dependency>
-
- <dependency>
- <groupId>org.apache.tomcat</groupId>
- <artifactId>catalina</artifactId>
- </dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ </dependency>
</dependencies>
Modified: test-harness/trunk/tomcat/src/main/java/org/jboss/testharness/integration/tomcat/TomcatConnector.java
===================================================================
--- test-harness/trunk/tomcat/src/main/java/org/jboss/testharness/integration/tomcat/TomcatConnector.java 2009-04-08 18:59:16 UTC (rev 2354)
+++ test-harness/trunk/tomcat/src/main/java/org/jboss/testharness/integration/tomcat/TomcatConnector.java 2009-04-08 19:00:07 UTC (rev 2355)
@@ -5,9 +5,16 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
-import java.net.URL;
-import java.net.URLConnection;
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.log4j.Logger;
import org.jboss.testharness.api.DeploymentException;
import org.jboss.testharness.spi.Containers;
import org.jboss.testharness.spi.helpers.AbstractContainerConnector;
@@ -21,16 +28,24 @@
public class TomcatConnector extends AbstractContainerConnector implements Containers
{
+ private static final Logger log = Logger.getLogger(TomcatConnector.class);
+
private static final String SERVER_HOME_PROPERTY_NAME = "tomcat.home";
private String binDirectory;
private final File tmpdir;
+ private final HttpClient client;
public TomcatConnector() throws IOException
{
+ log.info("You must add the the tests/secret user to Tomcat, for example, in $CATALINA_BASE/conf/tomcat-users.xml add <user name=\"tests\" password=\"secret\" roles=\"standard,manager\" />");
tmpdir = new File(System.getProperty("java.io.tmpdir"), "org.jboss.webbeans.tck.integration.jbossas");
tmpdir.mkdir();
tmpdir.deleteOnExit();
+ client = new HttpClient();
+ client.getParams().setAuthenticationPreemptive(true);
+ Credentials credentials = new UsernamePasswordCredentials("tests", "secret");
+ client.getState().setCredentials(new AuthScope(null, 8080, null), credentials);
}
@Override
@@ -67,37 +82,38 @@
public void deploy(InputStream stream, String name) throws DeploymentException, IOException
{
- String deployUrl = getManagerUrl("deploy", "path=/" + name, "update=true");
- URLConnection connection = new URL(deployUrl).openConnection();
- if (!(connection instanceof HttpURLConnection))
+ String deployUrl = getManagerUrl("deploy", "path=/" + getContextName(name), "update=true");
+ PutMethod put = new PutMethod(deployUrl);
+ put.setRequestEntity(new InputStreamRequestEntity(stream));
+ try
{
- throw new IllegalStateException("Not an http connection! " + connection);
+ int status = client.executeMethod(put);
+ if (status != HttpURLConnection.HTTP_OK)
+ {
+ throw new DeploymentException(new String(put.getResponseBody()));
+ }
}
- HttpURLConnection httpConnection = (HttpURLConnection) connection;
- httpConnection.setRequestMethod("PUT");
- httpConnection.connect();
- copy(stream, httpConnection.getOutputStream());
- httpConnection.disconnect();
- if (httpConnection.getResponseCode() != HttpURLConnection.HTTP_OK)
+ finally
{
- throw new DeploymentException(httpConnection.getResponseMessage());
+ put.releaseConnection();
}
}
public void undeploy(String name) throws IOException
{
- String deployUrl = getManagerUrl("undeploy", "path=/" + name);
- URLConnection connection = new URL(deployUrl).openConnection();
- if (!(connection instanceof HttpURLConnection))
+ String deployUrl = getManagerUrl("undeploy", "path=/" + getContextName(name));
+ HttpMethod get = new GetMethod(deployUrl);
+ try
{
- throw new IllegalStateException("Not an http connection! " + connection);
+ int status = client.executeMethod(get);
+ if (status != HttpURLConnection.HTTP_OK)
+ {
+ throw new IllegalStateException(new String(get.getResponseBody()));
+ }
}
- HttpURLConnection httpConnection = (HttpURLConnection) connection;
- httpConnection.connect();
- httpConnection.disconnect();
- if (httpConnection.getResponseCode() != HttpURLConnection.HTTP_OK)
+ finally
{
- throw new IllegalStateException("Error undeploying app " + httpConnection.getResponseMessage());
+ get.releaseConnection();
}
}
@@ -118,5 +134,10 @@
}
return url;
}
+
+ protected String getContextName(String name)
+ {
+ return name.substring(0, name.length() - 4);
+ }
}
\ No newline at end of file
More information about the weld-commits
mailing list