[jboss-svn-commits] JBoss Common SVN: r4674 - in shrinkwrap/trunk: extension-jetty-7 and 20 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Jul 4 02:10:06 EDT 2010


Author: dan.j.allen
Date: 2010-07-04 02:10:05 -0400 (Sun, 04 Jul 2010)
New Revision: 4674

Added:
   shrinkwrap/trunk/extension-jetty-7/
   shrinkwrap/trunk/extension-jetty-7/pom.xml
   shrinkwrap/trunk/extension-jetty-7/src/
   shrinkwrap/trunk/extension-jetty-7/src/main/
   shrinkwrap/trunk/extension-jetty-7/src/main/java/
   shrinkwrap/trunk/extension-jetty-7/src/main/java/org/
   shrinkwrap/trunk/extension-jetty-7/src/main/java/org/jboss/
   shrinkwrap/trunk/extension-jetty-7/src/main/java/org/jboss/shrinkwrap/
   shrinkwrap/trunk/extension-jetty-7/src/main/java/org/jboss/shrinkwrap/jetty_7/
   shrinkwrap/trunk/extension-jetty-7/src/main/java/org/jboss/shrinkwrap/jetty_7/api/
   shrinkwrap/trunk/extension-jetty-7/src/main/java/org/jboss/shrinkwrap/jetty_7/api/ShrinkWrapWebAppContext.java
   shrinkwrap/trunk/extension-jetty-7/src/main/resources/
   shrinkwrap/trunk/extension-jetty-7/src/main/resources/META-INF/
   shrinkwrap/trunk/extension-jetty-7/src/main/resources/META-INF/services/
   shrinkwrap/trunk/extension-jetty-7/src/main/resources/META-INF/services/org.jboss.shrinkwrap.jetty_7.api.ShrinkWrapWebAppContext
   shrinkwrap/trunk/extension-jetty-7/src/test/
   shrinkwrap/trunk/extension-jetty-7/src/test/java/
   shrinkwrap/trunk/extension-jetty-7/src/test/java/org/
   shrinkwrap/trunk/extension-jetty-7/src/test/java/org/jboss/
   shrinkwrap/trunk/extension-jetty-7/src/test/java/org/jboss/shrinkwrap/
   shrinkwrap/trunk/extension-jetty-7/src/test/java/org/jboss/shrinkwrap/jetty_7/
   shrinkwrap/trunk/extension-jetty-7/src/test/java/org/jboss/shrinkwrap/jetty_7/servlet/
   shrinkwrap/trunk/extension-jetty-7/src/test/java/org/jboss/shrinkwrap/jetty_7/servlet/ForwardingServlet.java
   shrinkwrap/trunk/extension-jetty-7/src/test/java/org/jboss/shrinkwrap/jetty_7/servlet/RequestParamEchoServlet.java
   shrinkwrap/trunk/extension-jetty-7/src/test/java/org/jboss/shrinkwrap/jetty_7/test/
   shrinkwrap/trunk/extension-jetty-7/src/test/java/org/jboss/shrinkwrap/jetty_7/test/JettyDeploymentIntegrationUnitTestCase.java
   shrinkwrap/trunk/extension-jetty-7/src/test/resources/
   shrinkwrap/trunk/extension-jetty-7/src/test/resources/test-web.xml
Log:
SHRINKWRAP-201



Property changes on: shrinkwrap/trunk/extension-jetty-7
___________________________________________________________________
Name: svn:ignore
   + target


Added: shrinkwrap/trunk/extension-jetty-7/pom.xml
===================================================================
--- shrinkwrap/trunk/extension-jetty-7/pom.xml	                        (rev 0)
+++ shrinkwrap/trunk/extension-jetty-7/pom.xml	2010-07-04 06:10:05 UTC (rev 4674)
@@ -0,0 +1,75 @@
+<?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-jetty-7</artifactId>
+   <!-- temporary while we link against 1.0.0-alpha-10 -->
+   <version>1.0.0-SNAPSHOT</version>
+   <name>ShrinkWrap Jetty 7 Integration Extension</name>
+   <description>ShrinkWrap integration extension for the Jetty 7 (and up) container</description>
+
+   <properties>
+      <!-- Known to work with Jetty version 7.0.0.v20091005 through 8.0.0.M0 -->
+      <version.org.eclipse.jetty_jetty>7.1.4.v20100610</version.org.eclipse.jetty_jetty>
+      <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.eclipse.jetty</groupId>
+         <artifactId>jetty-webapp</artifactId>
+         <version>${version.org.eclipse.jetty_jetty}</version>
+      </dependency>
+
+      <dependency> 
+         <groupId>javax.servlet</groupId> 
+         <artifactId>servlet-api</artifactId> 
+         <version>2.5</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-jetty-7/src/main/java/org/jboss/shrinkwrap/jetty_7/api/ShrinkWrapWebAppContext.java
===================================================================
--- shrinkwrap/trunk/extension-jetty-7/src/main/java/org/jboss/shrinkwrap/jetty_7/api/ShrinkWrapWebAppContext.java	                        (rev 0)
+++ shrinkwrap/trunk/extension-jetty-7/src/main/java/org/jboss/shrinkwrap/jetty_7/api/ShrinkWrapWebAppContext.java	2010-07-04 06:10:05 UTC (rev 4674)
@@ -0,0 +1,177 @@
+/*
+ * 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.jetty_7.api;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.logging.Logger;
+import org.eclipse.jetty.webapp.WebAppContext;
+
+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;
+
+/**
+ * Jetty's {@link WebAppContext} backed by a ShrinkWrap
+ * {@link Archive}; capable of being deployed into 
+ * the Embedded Jetty 7 {@link org.eclipse.jetty.Server}
+ * 
+ * @author Dan Allen
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ShrinkWrapWebAppContext extends WebAppContext implements Assignable
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger log = Logger.getLogger(ShrinkWrapWebAppContext.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";
+
+   /**
+    * 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() + "\"");
+      }
+   }
+
+   /**
+    *  /
+    */
+   private static final char ROOT = '/';
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Underlying delegate
+    */
+   private final Archive<?> archive;
+
+   //-------------------------------------------------------------------------------------||
+   // Constructor ------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Creates a new {@link ShrinkWrapWebAppContext} using the 
+    * specified underlying archive
+    * 
+    * @throws IllegalArgumentException If the archive is not specified
+    */
+   public ShrinkWrapWebAppContext(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 name = archive.getName();
+      final int extensionOffset = name.lastIndexOf('.');
+      final String baseName = extensionOffset >= 0 ? name.substring(0, extensionOffset) : name;
+      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, name, 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
+      final URL url;
+      try
+      {
+         url = exported.toURI().toURL();
+      }
+      catch (final MalformedURLException e)
+      {
+         throw new RuntimeException("Could not obtain URL of File " + exported.getAbsolutePath(), e);
+      }
+      log.info("Webapp archive location: " + url);
+
+      // Set properties regarding the webbapp
+      this.setWar(url.toExternalForm());
+      this.setContextPath(ROOT + baseName);
+
+      // 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-jetty-7/src/main/resources/META-INF/services/org.jboss.shrinkwrap.jetty_7.api.ShrinkWrapWebAppContext
===================================================================
--- shrinkwrap/trunk/extension-jetty-7/src/main/resources/META-INF/services/org.jboss.shrinkwrap.jetty_7.api.ShrinkWrapWebAppContext	                        (rev 0)
+++ shrinkwrap/trunk/extension-jetty-7/src/main/resources/META-INF/services/org.jboss.shrinkwrap.jetty_7.api.ShrinkWrapWebAppContext	2010-07-04 06:10:05 UTC (rev 4674)
@@ -0,0 +1 @@
+org.jboss.shrinkwrap.jetty_7.api.ShrinkWrapWebAppContext
\ No newline at end of file

Added: shrinkwrap/trunk/extension-jetty-7/src/test/java/org/jboss/shrinkwrap/jetty_7/servlet/ForwardingServlet.java
===================================================================
--- shrinkwrap/trunk/extension-jetty-7/src/test/java/org/jboss/shrinkwrap/jetty_7/servlet/ForwardingServlet.java	                        (rev 0)
+++ shrinkwrap/trunk/extension-jetty-7/src/test/java/org/jboss/shrinkwrap/jetty_7/servlet/ForwardingServlet.java	2010-07-04 06:10:05 UTC (rev 4674)
@@ -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.jetty_7.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 path denoted by the request parameter "to", 
+    * 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-jetty-7/src/test/java/org/jboss/shrinkwrap/jetty_7/servlet/RequestParamEchoServlet.java
===================================================================
--- shrinkwrap/trunk/extension-jetty-7/src/test/java/org/jboss/shrinkwrap/jetty_7/servlet/RequestParamEchoServlet.java	                        (rev 0)
+++ shrinkwrap/trunk/extension-jetty-7/src/test/java/org/jboss/shrinkwrap/jetty_7/servlet/RequestParamEchoServlet.java	2010-07-04 06:10:05 UTC (rev 4674)
@@ -0,0 +1,20 @@
+package org.jboss.shrinkwrap.jetty_7.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-jetty-7/src/test/java/org/jboss/shrinkwrap/jetty_7/test/JettyDeploymentIntegrationUnitTestCase.java
===================================================================
--- shrinkwrap/trunk/extension-jetty-7/src/test/java/org/jboss/shrinkwrap/jetty_7/test/JettyDeploymentIntegrationUnitTestCase.java	                        (rev 0)
+++ shrinkwrap/trunk/extension-jetty-7/src/test/java/org/jboss/shrinkwrap/jetty_7/test/JettyDeploymentIntegrationUnitTestCase.java	2010-07-04 06:10:05 UTC (rev 4674)
@@ -0,0 +1,198 @@
+/*
+ * 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.jetty_7.test;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Logger;
+
+import junit.framework.Assert;
+
+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.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.ContextHandler;
+import org.jboss.shrinkwrap.api.ArchivePath;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.jetty_7.api.ShrinkWrapWebAppContext;
+import org.jboss.shrinkwrap.jetty_7.servlet.ForwardingServlet;
+import org.jboss.shrinkwrap.jetty_7.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 JettyDeploymentIntegrationUnitTestCase
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger log = Logger.getLogger(JettyDeploymentIntegrationUnitTestCase.class.getName());
+
+   /**
+    * Host to which the HTTP server should bind
+    */
+   private static final String HTTP_BIND_HOST = "localhost";
+
+   /**
+    * 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 = "";
+
+   /**
+    * Path, relative to the resources base, of a test web.xml
+    */
+   private static final String PATH_ACTUAL_WEB_XML = PATH_RESOURCE_WEB_XML + "test-web.xml";
+
+   /**
+    * Path, relative to the resources base, of an echo servlet
+    */
+   private static final String PATH_ECHO_SERVLET = "RequestParamEchoServlet";
+
+   /**
+    * URI Separator
+    */
+   private static final char SEPARATOR = '/';
+
+   /**
+    * Jetty server
+    */
+   private static Server server;
+
+   /**
+    * Servlet Class under test
+    */
+   private static final Class<?> forwardingServletClass = 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 Jetty Embedded Server
+    */
+   @BeforeClass
+   public static void createServerAndDeployWebapp() throws Exception
+   {
+      // Create the new server
+      server = new Server(HTTP_BIND_PORT);
+
+      final WebArchive archive = ShrinkWrap.create(WebArchive.class, NAME_WAR);
+      final ArchivePath targetPathWebXml = ArchivePaths.create("web.xml");
+      archive.addWebResource(PATH_ACTUAL_WEB_XML, targetPathWebXml).addClasses(forwardingServletClass, echoServletClass);
+      log.info(archive.toString(true));
+
+      // Deploy
+      final ContextHandler handler = archive.as(ShrinkWrapWebAppContext.class);
+      server.setHandler(handler);
+
+      // Start the service
+      server.start();
+   }
+
+   /**
+    * Stops the Jetty Server
+    * @throws Exception
+    */
+   @AfterClass
+   public static void stopServer() throws Exception
+   {
+      server.stop();
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Tests ------------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Tests that we can execute an HTTP request and it's fulfilled as expected, 
+    * proving our deployment succeeded
+    */
+   @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>Jetty 7 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
+            + forwardingServletClass.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-jetty-7/src/test/resources/test-web.xml
===================================================================
--- shrinkwrap/trunk/extension-jetty-7/src/test/resources/test-web.xml	                        (rev 0)
+++ shrinkwrap/trunk/extension-jetty-7/src/test/resources/test-web.xml	2010-07-04 06:10:05 UTC (rev 4674)
@@ -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.jetty_7.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.jetty_7.servlet.RequestParamEchoServlet</servlet-class>
+   </servlet>
+   <servlet-mapping>
+      <servlet-name>RequestParamEchoServlet</servlet-name>
+      <url-pattern>/RequestParamEchoServlet</url-pattern>
+   </servlet-mapping>
+</web-app>



More information about the jboss-svn-commits mailing list