[jboss-svn-commits] JBoss Common SVN: r4581 - in shrinkwrap/trunk: extension-tomcat and 21 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jun 28 17:56:42 EDT 2010


Author: dan.j.allen
Date: 2010-06-28 17:56:41 -0400 (Mon, 28 Jun 2010)
New Revision: 4581

Added:
   shrinkwrap/trunk/extension-tomcat/
   shrinkwrap/trunk/extension-tomcat/pom.xml
   shrinkwrap/trunk/extension-tomcat/src/
   shrinkwrap/trunk/extension-tomcat/src/main/
   shrinkwrap/trunk/extension-tomcat/src/main/java/
   shrinkwrap/trunk/extension-tomcat/src/main/java/org/
   shrinkwrap/trunk/extension-tomcat/src/main/java/org/jboss/
   shrinkwrap/trunk/extension-tomcat/src/main/java/org/jboss/shrinkwrap/
   shrinkwrap/trunk/extension-tomcat/src/main/java/org/jboss/shrinkwrap/tomcat/
   shrinkwrap/trunk/extension-tomcat/src/main/java/org/jboss/shrinkwrap/tomcat/api/
   shrinkwrap/trunk/extension-tomcat/src/main/java/org/jboss/shrinkwrap/tomcat/api/ShrinkWrapStandardContext.java
   shrinkwrap/trunk/extension-tomcat/src/main/resources/
   shrinkwrap/trunk/extension-tomcat/src/main/resources/META-INF/
   shrinkwrap/trunk/extension-tomcat/src/main/resources/META-INF/services/
   shrinkwrap/trunk/extension-tomcat/src/main/resources/META-INF/services/org.jboss.shrinkwrap.tomcat.api.ShrinkWrapStandardContext
   shrinkwrap/trunk/extension-tomcat/src/test/
   shrinkwrap/trunk/extension-tomcat/src/test/java/
   shrinkwrap/trunk/extension-tomcat/src/test/java/org/
   shrinkwrap/trunk/extension-tomcat/src/test/java/org/jboss/
   shrinkwrap/trunk/extension-tomcat/src/test/java/org/jboss/shrinkwrap/
   shrinkwrap/trunk/extension-tomcat/src/test/java/org/jboss/shrinkwrap/tomcat/
   shrinkwrap/trunk/extension-tomcat/src/test/java/org/jboss/shrinkwrap/tomcat/servlet/
   shrinkwrap/trunk/extension-tomcat/src/test/java/org/jboss/shrinkwrap/tomcat/servlet/ForwardingServlet.java
   shrinkwrap/trunk/extension-tomcat/src/test/java/org/jboss/shrinkwrap/tomcat/servlet/RequestParamEchoServlet.java
   shrinkwrap/trunk/extension-tomcat/src/test/java/org/jboss/shrinkwrap/tomcat/test/
   shrinkwrap/trunk/extension-tomcat/src/test/java/org/jboss/shrinkwrap/tomcat/test/TomcatDeploymentIntegrationUnitTestCase.java
   shrinkwrap/trunk/extension-tomcat/src/test/resources/
   shrinkwrap/trunk/extension-tomcat/src/test/resources/webxml/
   shrinkwrap/trunk/extension-tomcat/src/test/resources/webxml/servletForwarding.xml
Modified:
   shrinkwrap/trunk/pom.xml
Log:
SHRINKWRAP-198 initial implementation



Property changes on: shrinkwrap/trunk/extension-tomcat
___________________________________________________________________
Name: svn:ignore
   + target
.project
.classpath
.settings


Added: shrinkwrap/trunk/extension-tomcat/pom.xml
===================================================================
--- shrinkwrap/trunk/extension-tomcat/pom.xml	                        (rev 0)
+++ shrinkwrap/trunk/extension-tomcat/pom.xml	2010-06-28 21:56:41 UTC (rev 4581)
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+   <parent>
+      <groupId>org.jboss.shrinkwrap</groupId>
+      <artifactId>shrinkwrap-build</artifactId>
+      <!-- temporary while we link against 1.0.0-alpha-10 -->
+      <version>1.0.0-alpha-10</version>
+      <relativePath>../build/pom.xml</relativePath>
+   </parent>
+
+   <modelVersion>4.0.0</modelVersion>
+
+   <artifactId>shrinkwrap-extension-tomcat</artifactId>
+   <!-- temporary while we link against 1.0.0-alpha-10 -->
+   <version>1.0.0-SNAPSHOT</version>
+   <name>ShrinkWrap Tomcat Integration Extension</name>
+   <description>ShrinkWrap integration extension for the Jetty Project</description>
+
+   <properties>
+      <!-- Known to work with Tomcat version 6.0.13 and up (that's the minimum version in central) -->
+      <version.org.apache.tomcat_tomcat>6.0.26</version.org.apache.tomcat_tomcat>
+      <version.org.apache.httpcomponents_httpclient>4.0.1</version.org.apache.httpcomponents_httpclient>
+   </properties>
+
+   <dependencies>
+
+      <dependency>
+         <groupId>org.jboss.shrinkwrap</groupId>
+         <artifactId>shrinkwrap-api</artifactId>
+         <!-- temporary while we link against 1.0.0-alpha-10 -->
+         <version>1.0.0-alpha-10</version>
+      </dependency>
+
+      <dependency>
+         <groupId>org.jboss.shrinkwrap</groupId>
+         <artifactId>shrinkwrap-impl-base</artifactId>
+         <!-- temporary while we link against 1.0.0-alpha-10 -->
+         <version>1.0.0-alpha-10</version>
+         <scope>test</scope>
+      </dependency>
+
+      <dependency>
+         <groupId>junit</groupId>
+         <artifactId>junit</artifactId>
+         <scope>test</scope>
+      </dependency>
+      
+      <dependency>
+          <groupId>org.apache.tomcat</groupId>
+          <artifactId>catalina</artifactId>
+          <version>${version.org.apache.tomcat_tomcat}</version>
+          <scope>provided</scope>
+      </dependency>
+
+      <dependency>
+          <groupId>org.apache.tomcat</groupId>
+          <artifactId>coyote</artifactId>
+          <version>${version.org.apache.tomcat_tomcat}</version>
+          <scope>provided</scope>
+      </dependency>
+
+      <dependency>
+          <groupId>org.apache.tomcat</groupId>
+          <artifactId>jasper</artifactId>
+          <version>${version.org.apache.tomcat_tomcat}</version>
+          <scope>provided</scope>
+      </dependency>
+      
+      <dependency>
+         <groupId>org.apache.httpcomponents</groupId>
+         <artifactId>httpclient</artifactId>
+         <version>${version.org.apache.httpcomponents_httpclient}</version>
+         <scope>test</scope>
+      </dependency>
+
+   </dependencies>
+
+<!--
+vi:ts=2:sw=2:expandtab:
+-->
+</project>

Added: shrinkwrap/trunk/extension-tomcat/src/main/java/org/jboss/shrinkwrap/tomcat/api/ShrinkWrapStandardContext.java
===================================================================
--- shrinkwrap/trunk/extension-tomcat/src/main/java/org/jboss/shrinkwrap/tomcat/api/ShrinkWrapStandardContext.java	                        (rev 0)
+++ shrinkwrap/trunk/extension-tomcat/src/main/java/org/jboss/shrinkwrap/tomcat/api/ShrinkWrapStandardContext.java	2010-06-28 21:56:41 UTC (rev 4581)
@@ -0,0 +1,173 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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,
+ * 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.
+ */
+package org.jboss.shrinkwrap.tomcat.api;
+
+import java.io.File;
+import java.io.IOException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.logging.Logger;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.session.StandardManager;
+import org.apache.catalina.startup.ContextConfig;
+
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Assignable;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+
+/**
+ * Tomcat's {@link StandardContext} backed by a ShrinkWrap
+ * {@link Archive}; capable of being deployed into 
+ * the Tomcat Embedded container
+ * 
+ * @author Dan Allen
+ * @version $Revision: $
+ */
+public class ShrinkWrapStandardContext extends StandardContext implements Assignable
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger log = Logger.getLogger(ShrinkWrapStandardContext.class.getName());
+
+   /**
+    * System property denoting the name of the temp directory
+    */
+   private static final String SYSPROP_KEY_TMP_DIR = "java.io.tmpdir";
+
+   /**
+    * The prefix assigned to the temporary file where the archive is exported
+    */
+   private static final String EXPORT_FILE_PREFIX = "export";
+
+   /**
+    * The folder name of the Tomcat work directory
+    */
+   private static final String WORK_FOLDER = "work";
+
+   /**
+    * Temporary directory into which we'll extract the {@link WebArchive}s
+    */
+   private static final File TMP_DIR;
+   static
+   {
+      TMP_DIR = new File(AccessController.doPrivileged(new PrivilegedAction<String>()
+      {
+
+         @Override
+         public String run()
+         {
+            return System.getProperty(SYSPROP_KEY_TMP_DIR);
+         }
+
+      }));
+      // If the temp location doesn't exist or isn't a directory
+      if (!TMP_DIR.exists() || !TMP_DIR.isDirectory())
+      {
+         throw new IllegalStateException("Could not obtain temp directory \"" + TMP_DIR.getAbsolutePath() + "\"");
+      }
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Underlying delegate
+    */
+   private final Archive<?> archive;
+
+   //-------------------------------------------------------------------------------------||
+   // Constructor ------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Creates a new {@link ShrinkWrapStandardContext} using the
+    * specified underlying archive
+    * 
+    * @throws IllegalArgumentException If the archive is not specified
+    */
+   public ShrinkWrapStandardContext(final Archive<?> archive) throws IllegalArgumentException
+   {
+      // Invoke super
+      super();
+
+      // Precondition checks
+      if (archive == null)
+      {
+         throw new IllegalArgumentException("archive must be specified");
+      }
+
+      // Flush to file
+      final String archiveName = archive.getName();
+      final int extensionOffset = archiveName.lastIndexOf('.');
+      final String baseName = extensionOffset >= 0 ? archiveName.substring(0, extensionOffset) : archiveName;
+      final File exported;
+      try
+      {
+         // If this method returns successfully then it is guaranteed that:
+         // 1. The file denoted by the returned abstract pathname did not exist before this method was invoked, and
+         // 2. Neither this method nor any of its variants will return the same abstract pathname again in the current invocation of the virtual machine.
+         exported = File.createTempFile(EXPORT_FILE_PREFIX, archiveName, TMP_DIR);
+      }
+      catch (IOException e)
+      {
+         throw new RuntimeException("Could not create temporary File in " + TMP_DIR + " to write exported archive", e);
+      }
+      // We are overwriting the temporary file placeholder reserved by File#createTemplateFile()
+      archive.as(ZipExporter.class).exportZip(exported, true);
+
+      // Mark to delete when we come down
+      exported.deleteOnExit();
+
+      // Add the context
+      log.info("Webapp archive location: " + exported.getAbsolutePath());
+      this.setDocBase(exported.getAbsolutePath());
+      // path should not begin with a / or else Tomcat fails to deploy the webapp properly
+      this.setPath(baseName);
+      this.setUnpackWAR(false);
+      // QUESTION are we over-stepping the bounds w/ ContextConfig, StandardManager and work folder?
+      ContextConfig config = new ContextConfig();
+      ((Lifecycle) this).addLifecycleListener(config);
+      this.setManager(new StandardManager());
+      this.setWorkDir(new File(TMP_DIR, WORK_FOLDER).getAbsolutePath());
+
+      // Remember the archive from which we're created
+      this.archive = archive;
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Required Implementations -----------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.shrinkwrap.api.Assignable#as(java.lang.Class)
+    */
+   @Override
+   public <TYPE extends Assignable> TYPE as(final Class<TYPE> clazz)
+   {
+      return archive.as(clazz);
+   }
+}

Added: shrinkwrap/trunk/extension-tomcat/src/main/resources/META-INF/services/org.jboss.shrinkwrap.tomcat.api.ShrinkWrapStandardContext
===================================================================
--- shrinkwrap/trunk/extension-tomcat/src/main/resources/META-INF/services/org.jboss.shrinkwrap.tomcat.api.ShrinkWrapStandardContext	                        (rev 0)
+++ shrinkwrap/trunk/extension-tomcat/src/main/resources/META-INF/services/org.jboss.shrinkwrap.tomcat.api.ShrinkWrapStandardContext	2010-06-28 21:56:41 UTC (rev 4581)
@@ -0,0 +1 @@
+org.jboss.shrinkwrap.tomcat.api.ShrinkWrapStandardContext
\ No newline at end of file

Added: shrinkwrap/trunk/extension-tomcat/src/test/java/org/jboss/shrinkwrap/tomcat/servlet/ForwardingServlet.java
===================================================================
--- shrinkwrap/trunk/extension-tomcat/src/test/java/org/jboss/shrinkwrap/tomcat/servlet/ForwardingServlet.java	                        (rev 0)
+++ shrinkwrap/trunk/extension-tomcat/src/test/java/org/jboss/shrinkwrap/tomcat/servlet/ForwardingServlet.java	2010-06-28 21:56:41 UTC (rev 4581)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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,
+ * 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.
+ */
+package org.jboss.shrinkwrap.tomcat.servlet;
+
+import java.io.IOException;
+import java.util.logging.Logger;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * ForwardingServlet
+ * 
+ * Servlet which forwards to a path as requested
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ForwardingServlet extends HttpServlet
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger log = Logger.getLogger(ForwardingServlet.class.getName());
+
+   /**
+    * serialVersionUID
+    */
+   private static final long serialVersionUID = 1L;
+
+   /**
+    * Name of the request parameter denoting which path to forward
+    */
+   public static final String REQ_PARAM_TO = "to";
+
+   /**
+    * Context root
+    */
+   private static final char ROOT = '/';
+
+   /**
+    * Content type to use in forwarding
+    */
+   private static final String CONTENT_TYPE_TEXT_PLAIN = "text/plain";
+
+   //-------------------------------------------------------------------------------------||
+   // Overridden Implementations ---------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Forwards the request to a JSP denoted by the request parameter "jsp", 
+    * returning a status of 400/Bad Request if not specified 
+    * 
+    * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+    */
+   @Override
+   protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException,
+         IOException
+   {
+      // Log
+      log.info("Request: " + request);
+
+      // Get the target page
+      final String to = request.getParameter(REQ_PARAM_TO);
+
+      // Handle unspecified
+      if (to == null)
+      {
+         // HTTP 400 and return
+         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+         return;
+      }
+
+      // Set the content-type to text
+      response.setContentType(CONTENT_TYPE_TEXT_PLAIN);
+
+      // Forward
+      final String resolvedLocation = ROOT + to;
+      log.info("Forwarding to: " + resolvedLocation);
+      final RequestDispatcher dispatcher = request.getRequestDispatcher(resolvedLocation);
+      dispatcher.forward(request, response);
+   }
+
+}

Added: shrinkwrap/trunk/extension-tomcat/src/test/java/org/jboss/shrinkwrap/tomcat/servlet/RequestParamEchoServlet.java
===================================================================
--- shrinkwrap/trunk/extension-tomcat/src/test/java/org/jboss/shrinkwrap/tomcat/servlet/RequestParamEchoServlet.java	                        (rev 0)
+++ shrinkwrap/trunk/extension-tomcat/src/test/java/org/jboss/shrinkwrap/tomcat/servlet/RequestParamEchoServlet.java	2010-06-28 21:56:41 UTC (rev 4581)
@@ -0,0 +1,20 @@
+package org.jboss.shrinkwrap.tomcat.servlet;
+
+import java.io.IOException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author Dan Allen
+ */
+public class RequestParamEchoServlet extends HttpServlet
+{
+   @Override
+   protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+   {
+      resp.getWriter().append(req.getParameter("echo"));
+   }
+
+}

Added: shrinkwrap/trunk/extension-tomcat/src/test/java/org/jboss/shrinkwrap/tomcat/test/TomcatDeploymentIntegrationUnitTestCase.java
===================================================================
--- shrinkwrap/trunk/extension-tomcat/src/test/java/org/jboss/shrinkwrap/tomcat/test/TomcatDeploymentIntegrationUnitTestCase.java	                        (rev 0)
+++ shrinkwrap/trunk/extension-tomcat/src/test/java/org/jboss/shrinkwrap/tomcat/test/TomcatDeploymentIntegrationUnitTestCase.java	2010-06-28 21:56:41 UTC (rev 4581)
@@ -0,0 +1,209 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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,
+ * 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.
+ */
+
+package org.jboss.shrinkwrap.tomcat.test;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.InetAddress;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Logger;
+
+import junit.framework.Assert;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Host;
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.startup.Embedded;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.utils.URIUtils;
+import org.apache.http.client.utils.URLEncodedUtils;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.message.BasicNameValuePair;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.tomcat.api.ShrinkWrapStandardContext;
+import org.jboss.shrinkwrap.tomcat.servlet.ForwardingServlet;
+import org.jboss.shrinkwrap.tomcat.servlet.RequestParamEchoServlet;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Ensures that deployment on {@link ShrinkWrapWebAppContext} into
+ * the Jetty {@link Server} works as expected
+ * 
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class TomcatDeploymentIntegrationUnitTestCase
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger log = Logger.getLogger(TomcatDeploymentIntegrationUnitTestCase.class.getName());
+
+   private static final String HTTP_BIND_HOST = "127.0.0.1";
+
+   /**
+    * Port to which the HTTP server should bind (above 1024 for *nix non-root environments)
+    */
+   private static final int HTTP_BIND_PORT = 12345;
+
+   /**
+    * Path, relative to the resources base, of the directory containing web.xml descriptor for tests
+    */
+   private static final String PATH_RESOURCE_WEB_XML = "webxml/";
+
+   /**
+    * Path, relative to the resources base, of a test web.xml
+    */
+   private static final String PATH_ACTUAL_WEB_XML = PATH_RESOURCE_WEB_XML + "servletForwarding.xml";
+
+   /**
+    * Path, relative to the resources base, of a test JSP
+    */
+   private static final String PATH_ECHO_SERVLET = "RequestParamEchoServlet";
+
+   /**
+    * URI Separator
+    */
+   private static final char SEPARATOR = '/';
+
+   /**
+    * Tomcat server
+    */
+   private static Embedded server;
+
+   /**
+    * Servlet Class under test
+    */
+   private static final Class<?> servletClass = ForwardingServlet.class;
+
+   private static final Class<?> echoServletClass = RequestParamEchoServlet.class;
+
+   /**
+    * Name of the web application
+    */
+   private static final String NAME_WEBAPP = "testServlet";
+
+   /**
+    * Name to assign to the WAR
+    */
+   private static final String NAME_WAR = NAME_WEBAPP + ".war";
+
+   //-------------------------------------------------------------------------------------||
+   // Lifecycle --------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Configures and starts the Tomcat Embedded Server
+    */
+   @BeforeClass
+   public static void createServerAndDeployWebapp() throws Exception
+   {
+      // Create the new server
+      server = new Embedded();
+      server.setName("tomcat");
+      Engine engine = server.createEngine();
+		engine.setName("tomcat");
+		engine.setDefaultHost(HTTP_BIND_HOST + SEPARATOR);
+		engine.setService(server);
+		server.setContainer(engine);
+		server.addEngine(engine);
+      Host host = server.createHost(HTTP_BIND_HOST + SEPARATOR, System.getProperty("java.io.tmpdir"));
+      host.setParent(engine);
+		engine.addChild(host);
+		Connector connector = server.createConnector(InetAddress.getByName(HTTP_BIND_HOST), HTTP_BIND_PORT, false);
+		server.addConnector(connector);
+		connector.setContainer(engine);
+		//starts tomcat embedded
+		server.init();
+		server.start();
+
+      final WebArchive archive = ShrinkWrap.create(WebArchive.class, NAME_WAR);
+      archive.setWebXML(PATH_ACTUAL_WEB_XML).addClasses(servletClass, echoServletClass);
+      log.info(archive.toString(true));
+
+      // Deploy
+      final StandardContext context = archive.as(ShrinkWrapStandardContext.class);
+		context.setParent(host);
+      host.addChild(context);
+   }
+
+   /**
+    * Stops the Tomcat Server
+    * @throws Exception
+    */
+   @AfterClass
+   public static void stopServer() throws Exception
+   {
+      server.stop();
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Tests ------------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Doesn't really test anything now; shows end-user view only
+    */
+   @Test
+   public void requestWebapp() throws Exception
+   {
+      // Get an HTTP Client
+      final HttpClient client = new DefaultHttpClient();
+
+      // Make an HTTP Request, adding in a custom parameter which should be echoed back to us
+      final String echoValue = "ShrinkWrap>Tomcat Integration";
+      final List<NameValuePair> params = new ArrayList<NameValuePair>();
+      params.add(new BasicNameValuePair("to", PATH_ECHO_SERVLET));
+      params.add(new BasicNameValuePair("echo", echoValue));
+      final URI uri = URIUtils.createURI("http", HTTP_BIND_HOST, HTTP_BIND_PORT, NAME_WEBAPP + SEPARATOR
+            + servletClass.getSimpleName(), URLEncodedUtils.format(params, "UTF-8"), null);
+      final HttpGet request = new HttpGet(uri);
+
+      // Execute the request
+      log.info("Executing request to: " + request.getURI());
+      final HttpResponse response = client.execute(request);
+      System.out.println(response.getStatusLine());
+      final HttpEntity entity = response.getEntity();
+      if (entity == null)
+      {
+         Assert.fail("Request returned no entity");
+      }
+
+      // Read the result, ensure it's what we're expecting (should be the value of request param "echo")
+      final BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
+      final String line = reader.readLine();
+      Assert.assertEquals("Unexpected response from Servlet", echoValue, line);
+
+   }
+
+}

Added: shrinkwrap/trunk/extension-tomcat/src/test/resources/webxml/servletForwarding.xml
===================================================================
--- shrinkwrap/trunk/extension-tomcat/src/test/resources/webxml/servletForwarding.xml	                        (rev 0)
+++ shrinkwrap/trunk/extension-tomcat/src/test/resources/webxml/servletForwarding.xml	2010-06-28 21:56:41 UTC (rev 4581)
@@ -0,0 +1,20 @@
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+  version="2.5">
+  <servlet>
+    <servlet-name>ForwardingServlet</servlet-name>
+    <servlet-class>org.jboss.shrinkwrap.tomcat.servlet.ForwardingServlet</servlet-class>
+  </servlet>
+  <servlet-mapping>
+    <servlet-name>ForwardingServlet</servlet-name>
+    <url-pattern>/ForwardingServlet</url-pattern>
+  </servlet-mapping>
+  <servlet>
+    <servlet-name>RequestParamEchoServlet</servlet-name>
+    <servlet-class>org.jboss.shrinkwrap.tomcat.servlet.RequestParamEchoServlet</servlet-class>
+  </servlet>
+  <servlet-mapping>
+    <servlet-name>RequestParamEchoServlet</servlet-name>
+    <url-pattern>/RequestParamEchoServlet</url-pattern>
+  </servlet-mapping>
+</web-app>

Modified: shrinkwrap/trunk/pom.xml
===================================================================
--- shrinkwrap/trunk/pom.xml	2010-06-28 20:16:51 UTC (rev 4580)
+++ shrinkwrap/trunk/pom.xml	2010-06-28 21:56:41 UTC (rev 4581)
@@ -70,6 +70,7 @@
     <module>impl-base</module>
     <module>spi</module>
     <module>extension-glassfish</module>
+    <module>extension-tomcat</module>
     <module>extension-jetty</module>
     <module>extension-openejb</module>
     <module>extension-tar</module>



More information about the jboss-svn-commits mailing list