[jboss-cvs] JBossAS SVN: r91303 - in projects/embedded/trunk: core/src/main/java/org/jboss/embedded/core/incubation/virtual/impl/vfs and 18 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jul 15 12:06:37 EDT 2009
Author: ALRubinger
Date: 2009-07-15 12:06:36 -0400 (Wed, 15 Jul 2009)
New Revision: 91303
Added:
projects/embedded/trunk/core/src/test/java/org/
projects/embedded/trunk/core/src/test/java/org/jboss/
projects/embedded/trunk/core/src/test/java/org/jboss/embedded/
projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/
projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/incubation/
projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/incubation/virtual/
projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/incubation/virtual/vfs/
projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/incubation/virtual/vfs/VirtualVfsArchiveTestCase.java
projects/embedded/trunk/core/src/test/resources/xml/
projects/embedded/trunk/core/src/test/resources/xml/something.xml
projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/embedded/testsuite/fulldep/servlet/
projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/embedded/testsuite/fulldep/servlet/JspForwardingServlet.java
projects/embedded/trunk/testsuite-full-dep/src/test/resources/jsp/
projects/embedded/trunk/testsuite-full-dep/src/test/resources/jsp/requestParamEcho.jsp
projects/embedded/trunk/testsuite-full-dep/src/test/resources/webxml/
projects/embedded/trunk/testsuite-full-dep/src/test/resources/webxml/servletForwardingToJsp.xml
Modified:
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/virtual/impl/base/AbstractVirtualArchive.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/virtual/impl/vfs/VirtualVfsArchiveImpl.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/virtual/spi/ExtensibleVirtualArchive.java
projects/embedded/trunk/testsuite-full-dep/pom.xml
projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java
Log:
[EMB-32] Test setup for Servlet/JSP in virtual deployments, extend the VirtualArchive bits to accommodate new URL resources
Modified: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/virtual/impl/base/AbstractVirtualArchive.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/virtual/impl/base/AbstractVirtualArchive.java 2009-07-15 15:59:53 UTC (rev 91302)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/virtual/impl/base/AbstractVirtualArchive.java 2009-07-15 16:06:36 UTC (rev 91303)
@@ -21,8 +21,11 @@
*/
package org.jboss.embedded.core.incubation.virtual.impl.base;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.net.URLConnection;
import org.jboss.embedded.core.incubation.virtual.spi.ExtensibleVirtualArchive;
import org.jboss.logging.Logger;
@@ -71,6 +74,54 @@
private static final String EXTENSION_CLASS = ".class";
//-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The ClassLoader used in loading resources and classes into the virtual deployment
+ */
+ private final ClassLoader classLoader;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructors -----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Constructor
+ *
+ * Creates a new instance using the Thread Context ClassLoader
+ * from which we'll load resources by default
+ */
+ protected AbstractVirtualArchive()
+ {
+ // Use the TCCL
+ this(SecurityActions.getThreadContextClassLoader());
+ }
+
+ /**
+ * Constructor
+ *
+ * Creates a new instance using the specified ClassLoader
+ * from which we'll load resources by default
+ *
+ * @param The ClassLoader to use by default
+ */
+ protected AbstractVirtualArchive(final ClassLoader cl)
+ {
+ // Invoke super
+ super();
+
+ // Precondition check
+ if (cl == null)
+ {
+ throw new IllegalArgumentException("ClassLoader must be specified");
+ }
+
+ // Set properties
+ this.classLoader = cl;
+ }
+
+ //-------------------------------------------------------------------------------------||
// Required Implementations -----------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -124,6 +175,91 @@
return this.covarientReturn();
}
+ /* (non-Javadoc)
+ * @see org.jboss.embedded.core.deployment.VirtualDeployment#addResource(java.lang.String)
+ */
+ @Override
+ public T addResource(final String name) throws IllegalArgumentException
+ {
+ return this.addResource(name, this.getClassLoader());
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.embedded.core.virtual.spi.ExtensibleVirtualArchive#addResource(java.lang.String, java.lang.ClassLoader)
+ */
+ @Override
+ public final T addResource(final String name, final ClassLoader cl) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (name == null || name.length() == 0)
+ {
+ throw new IllegalArgumentException("name must be specified");
+ }
+ if (cl == null)
+ {
+ throw new IllegalArgumentException("ClassLoader must be specified");
+ }
+
+ // Get the content of the resource
+ byte[] content = null;
+ try
+ {
+ content = this.getBytesOfResource(name, cl);
+ }
+ catch (final IOException ioe)
+ {
+ throw new RuntimeException("Could not add resource \"" + name + "\" to " + this, ioe);
+ }
+
+ // Add
+ this.addContent(content, name);
+
+ // Return
+ return this.covarientReturn();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.embedded.core.incubation.virtual.spi.ExtensibleVirtualArchive#addResource(java.net.URL, java.lang.String)
+ */
+ @Override
+ public T addResource(final URL location, final String newPath) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (location == null)
+ {
+ throw new IllegalArgumentException("location must be specified");
+ }
+
+ // Get the content of the location
+ byte[] content = null;
+ try
+ {
+ content = this.getBytesOfResource(location);
+ }
+ catch (final IOException ioe)
+ {
+ throw new RuntimeException("Could not add location \"" + location + "\" to " + this, ioe);
+ }
+
+ // Adjust the path if not explicitly defined
+ String path = newPath;
+ if (path == null)
+ {
+ path = location.getPath();
+ if (log.isTraceEnabled())
+ {
+ log.trace("Implicitly set new path to \"" + path + "\" while adding: " + location);
+ }
+ }
+
+ // Add
+ this.addContent(content, path);
+
+ // Return
+ return this.covarientReturn();
+ }
+
//-------------------------------------------------------------------------------------||
// Contracts --------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -136,6 +272,15 @@
*/
protected abstract Class<T> getActualClass();
+ /**
+ * Adds the specified content to the archive at the specified location
+ *
+ * @param content
+ * @param location
+ * @throws IllegalArgumentException
+ */
+ protected abstract void addContent(final byte[] content, final String location) throws IllegalArgumentException;
+
//-------------------------------------------------------------------------------------||
// Internal Helper Methods ------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -210,4 +355,138 @@
}
}
+ /**
+ * Obtains the contents (bytes) of the specified location
+ *
+ * @param location
+ * @return
+ * @throws IOException
+ * @throws IllegalArgumentException If the location is not specified
+ */
+ private byte[] getBytesOfResource(final URL location) throws IOException, IllegalArgumentException
+ {
+ // Precondition check
+ if (location == null)
+ {
+ throw new IllegalArgumentException("location must be specified");
+ }
+
+ // Open a connection and read in all the bytes
+ final URLConnection connection = location.openConnection();
+ final int length = connection.getContentLength();
+ assert length > -1 : "Content length is not known";
+ byte contents[] = new byte[length];
+ final InputStream in = connection.getInputStream();
+ int read = 0;
+ int currentLocation = 0;
+ int bytesToRead = 1024;
+ // Avoid ArrayIndexOutOfBounds by adjusting back the bytes we read in
+ if (bytesToRead + currentLocation > length)
+ {
+ bytesToRead = length;
+ }
+
+ // Read into the byte array
+ while ((read = (in.read(contents, currentLocation, bytesToRead))) > 0)
+ {
+ // Mark our new offset
+ currentLocation += read;
+
+ // Avoid ArrayIndexOutOfBounds
+ if (bytesToRead + currentLocation > length)
+ {
+ bytesToRead = length - currentLocation;
+ }
+ }
+
+ // Close up the stream
+ in.close();
+
+ // Return the byte array
+ if (log.isTraceEnabled())
+ {
+ log.trace("Read " + contents.length + " bytes for: " + location);
+ }
+ return contents;
+ }
+
+ /**
+ * Obtains the contents (bytes) of the specified resource using the
+ * specified ClassLoader
+ *
+ * @param name
+ * @param cl
+ * @return
+ * @throws IOException
+ * @throws IllegalArgumentException If the name or ClassLoader is not specified
+ */
+ private byte[] getBytesOfResource(final String name, final ClassLoader cl) throws IOException,
+ IllegalArgumentException
+ {
+ // Precondition check
+ if (name == null || name.length() == 0)
+ {
+ throw new IllegalArgumentException("name must be specified");
+ }
+ if (cl == null)
+ {
+ throw new IllegalArgumentException("ClassLoader must be specified");
+ }
+
+ // Get the URL
+ final URL resourceUrl = this.getResourceUrl(name, cl);
+
+ // Return
+ return this.getBytesOfResource(resourceUrl);
+ }
+
+ /**
+ * Obtains the URL of the resource with the requested name.
+ * The search order is described by {@link ClassLoader#getResource(String)}
+ *
+ * @param name
+ * @return
+ * @throws IllegalArgumentException If name is not specified or could not be found,
+ * or if the ClassLoader is not specified
+ */
+ private URL getResourceUrl(final String name, final ClassLoader cl) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (name == null || name.length() == 0)
+ {
+ throw new IllegalArgumentException("name must be specified");
+ }
+ if (cl == null)
+ {
+ throw new IllegalArgumentException("ClassLoader must be specified");
+ }
+
+ // Find
+ final URL url = cl.getResource(name);
+
+ // Ensure found
+ if (url == null)
+ {
+ throw new ResourceNotFoundException("Could not find resource with name \"" + name + "\" in: " + cl);
+ }
+
+ // Return
+ return url;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Returns the ClassLoader used to load classes
+ * and resources into this virtual deployment
+ *
+ * @return
+ */
+ protected final ClassLoader getClassLoader()
+ {
+ return this.classLoader;
+ }
+
}
Modified: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/virtual/impl/vfs/VirtualVfsArchiveImpl.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/virtual/impl/vfs/VirtualVfsArchiveImpl.java 2009-07-15 15:59:53 UTC (rev 91302)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/virtual/impl/vfs/VirtualVfsArchiveImpl.java 2009-07-15 16:06:36 UTC (rev 91303)
@@ -22,14 +22,11 @@
package org.jboss.embedded.core.incubation.virtual.impl.vfs;
import java.io.IOException;
-import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
-import java.net.URLConnection;
import java.util.List;
import org.jboss.embedded.core.incubation.virtual.impl.base.AbstractVirtualArchive;
-import org.jboss.embedded.core.incubation.virtual.impl.base.ResourceNotFoundException;
import org.jboss.embedded.core.incubation.virtual.spi.vfs.VirtualVfsArchive;
import org.jboss.logging.Logger;
import org.jboss.virtual.MemoryFileFactory;
@@ -66,6 +63,16 @@
*/
private static final char NEWLINE = '\n';
+ /**
+ * Empty String
+ */
+ private static final String EMPTY_STRING = "";
+
+ /**
+ * Separator
+ */
+ private static final char SEPARATOR = '/';
+
//-------------------------------------------------------------------------------------||
// Instance Members -------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -80,11 +87,6 @@
*/
private final URL rootUrl;
- /**
- * The ClassLoader used in loading resources and classes into the virtual deployment
- */
- private final ClassLoader classLoader;
-
//-------------------------------------------------------------------------------------||
// Constructors -----------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -112,6 +114,9 @@
*/
public VirtualVfsArchiveImpl(final String name, final ClassLoader cl) throws IllegalArgumentException
{
+ // Invoke super
+ super(cl);
+
// Precondition Check
if (name == null || name.length() == 0)
{
@@ -127,9 +132,11 @@
URL url = null;
try
{
- final URL memoryRootUrl = new URL(PROTOCOL_VFS_MEMORY, name, "");
+ final URL memoryRootUrl = new URL(PROTOCOL_VFS_MEMORY, name, EMPTY_STRING);
MemoryFileFactory.createRoot(memoryRootUrl);
- url = memoryRootUrl;
+ final URL stubUrl = new URL(memoryRootUrl, name);
+ MemoryFileFactory.createDirectory(stubUrl);
+ url = stubUrl;
file = VFS.getRoot(memoryRootUrl);
}
catch (final IOException ioe)
@@ -140,9 +147,6 @@
// Set properties for the root
this.root = file;
this.rootUrl = url;
-
- // Set the CL
- this.classLoader = cl;
}
//-------------------------------------------------------------------------------------||
@@ -169,63 +173,53 @@
return this.root;
}
- /* (non-Javadoc)
- * @see org.jboss.embedded.core.deployment.VirtualDeployment#addResource(java.lang.String)
- */
- @Override
- public VirtualVfsArchive addResource(final String name) throws IllegalArgumentException
- {
- return this.addResource(name, this.getClassLoader());
- }
-
/*
* (non-Javadoc)
- * @see org.jboss.embedded.core.virtual.spi.ExtensibleVirtualArchive#addResource(java.lang.String, java.lang.ClassLoader)
+ * @see org.jboss.embedded.core.incubation.virtual.impl.base.AbstractVirtualArchive#addContent(byte[], java.lang.String)
*/
@Override
- public final VirtualVfsArchive addResource(final String name, final ClassLoader cl) throws IllegalArgumentException
+ protected void addContent(final byte[] content, final String location) throws IllegalArgumentException
{
// Precondition check
- if (name == null || name.length() == 0)
+ if (content == null)
{
- throw new IllegalArgumentException("name must be specified");
+ throw new IllegalArgumentException("content must be specified");
}
- if (cl == null)
+ if (location == null || location.length() == 0)
{
- throw new IllegalArgumentException("ClassLoader must be specified");
+ throw new IllegalArgumentException("location must be specified");
}
- // Get the content of the resource
- byte[] content = null;
- try
- {
- content = this.getBytesOfResource(name, cl);
- }
- catch (final IOException ioe)
- {
- throw new RuntimeException("Could not add resource \"" + name + "\" to " + this, ioe);
- }
-
// Get the root URL of the memory file
final URL rootUrl = this.getRootUrl();
// Construct a new URL for this new memoryfile
- URL newUrl = null;
+ URL url = null;
try
{
- newUrl = new URL(rootUrl, name);
+ final StringBuilder sb = new StringBuilder();
+ sb.append(rootUrl.toExternalForm());
+ sb.append(SEPARATOR);
+ sb.append(location);
+ url = new URL(sb.toString());
}
catch (final MalformedURLException murle)
{
- throw new RuntimeException("Could not form URL for new resource \"" + name + "\" in " + this, murle);
+ throw new RuntimeException("Could not form URL for new resource \"" + location + "\" in " + this, murle);
}
- // Put the new memory file in place
- MemoryFileFactory.putFile(newUrl, content);
- log.debug("Added \"" + name + "\": " + newUrl);
+ // Add the content
+ this.addContent(content, url);
+ }
- // Return
- return this.covarientReturn();
+ /* (non-Javadoc)
+ * @see org.jboss.embedded.core.incubation.virtual.spi.ExtensibleVirtualArchive#addResource(java.net.URL)
+ */
+ @Override
+ public VirtualVfsArchive addResource(final URL location) throws IllegalArgumentException
+ {
+ // Delegate to the other implementation
+ return this.addResource(location, null);
}
/* (non-Javadoc)
@@ -250,70 +244,6 @@
//-------------------------------------------------------------------------------------||
/**
- * Obtains the contents (bytes) of the specified resource using the
- * specified ClassLoader
- *
- * @param name
- * @return
- * @throws IOException
- * @throws IllegalArgumentException If the name or ClassLoader is not specified
- */
- private byte[] getBytesOfResource(final String name, final ClassLoader cl) throws IOException,
- IllegalArgumentException
- {
- // Precondition check
- if (name == null || name.length() == 0)
- {
- throw new IllegalArgumentException("name must be specified");
- }
- if (cl == null)
- {
- throw new IllegalArgumentException("ClassLoader must be specified");
- }
-
- // Get the URL
- final URL resourceUrl = this.getResourceUrl(name, cl);
-
- // Open a connection and read in all the bytes
- final URLConnection connection = resourceUrl.openConnection();
- final int length = connection.getContentLength();
- assert length > -1 : "Content length is not known";
- byte contents[] = new byte[length];
- final InputStream in = connection.getInputStream();
- int read = 0;
- int currentLocation = 0;
- int bytesToRead = 1024;
- // Avoid ArrayIndexOutOfBounds by adjusting back the bytes we read in
- if (bytesToRead + currentLocation > length)
- {
- bytesToRead = length;
- }
-
- // Read into the byte array
- while ((read = (in.read(contents, currentLocation, bytesToRead))) > 0)
- {
- // Mark our new offset
- currentLocation += read;
-
- // Avoid ArrayIndexOutOfBounds
- if (bytesToRead + currentLocation > length)
- {
- bytesToRead = length - currentLocation;
- }
- }
-
- // Close up the stream
- in.close();
-
- // Return the byte array
- if (log.isTraceEnabled())
- {
- log.trace("Read " + contents.length + " bytes for: " + name);
- }
- return contents;
- }
-
- /**
* Describes this file in form:
*
* "/path/resource.ext - x bytes"
@@ -409,37 +339,27 @@
}
/**
- * Obtains the URL of the resource with the requested name.
- * The search order is described by {@link ClassLoader#getResource(String)}
- *
- * @param name
- * @return
- * @throws IllegalArgumentException If name is not specified or could not be found,
- * or if the ClassLoader is not specified
+ * Puts the specified content at the specified location as a memory file
+ * @param content
+ * @param location
+ * @throws IllegalArgumentException
*/
- private URL getResourceUrl(final String name, final ClassLoader cl) throws IllegalArgumentException
+ private void addContent(final byte[] content, final URL location) throws IllegalArgumentException
{
// Precondition check
- if (name == null || name.length() == 0)
+ if (content == null)
{
- throw new IllegalArgumentException("name must be specified");
+ throw new IllegalArgumentException("content must be specified");
}
- if (cl == null)
+ if (location == null)
{
- throw new IllegalArgumentException("ClassLoader must be specified");
+ throw new IllegalArgumentException("location must be specified");
}
- // Find
- final URL url = cl.getResource(name);
+ // Put the new memory file in place
+ MemoryFileFactory.putFile(location, content);
+ log.debug("Added: " + location);
- // Ensure found
- if (url == null)
- {
- throw new ResourceNotFoundException("Could not find resource with name \"" + name + "\" in: " + cl);
- }
-
- // Return
- return url;
}
//-------------------------------------------------------------------------------------||
@@ -456,15 +376,4 @@
{
return this.copyURL(this.rootUrl);
}
-
- /**
- * Returns the ClassLoader used to load classes
- * and resources into this virtual deployment
- *
- * @return
- */
- protected final ClassLoader getClassLoader()
- {
- return this.classLoader;
- }
}
Modified: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/virtual/spi/ExtensibleVirtualArchive.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/virtual/spi/ExtensibleVirtualArchive.java 2009-07-15 15:59:53 UTC (rev 91302)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/virtual/spi/ExtensibleVirtualArchive.java 2009-07-15 16:06:36 UTC (rev 91303)
@@ -21,6 +21,8 @@
*/
package org.jboss.embedded.core.incubation.virtual.spi;
+import java.net.URL;
+
import org.jboss.embedded.core.incubation.virtual.tempdev.VirtualDeploymentGroup;
/**
@@ -82,6 +84,27 @@
T addResource(String name, ClassLoader cl) throws IllegalArgumentException;
/**
+ * Adds the resource located at the specified URL to the archive
+ *
+ * @param location
+ * @return
+ * @throws IllegalArgumentException If the location is not specified
+ */
+ T addResource(URL location) throws IllegalArgumentException;
+
+ /**
+ * Adds the resource located at the specified URL to
+ * the archive at the specified path.
+ *
+ * @param location
+ * @param newPath The new path to assign, or null if
+ * the path portion of the location should be used
+ * @return
+ * @throws IllegalArgumentException If the location is not specified
+ */
+ T addResource(URL location, String newPath) throws IllegalArgumentException;
+
+ /**
* Returns a multiline "ls -l"-equse output of the contents of
* this deployment and (recursively) its children if the verbosity
* flag is set to "true". Otherwise the no-arg version is invoked
Added: projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/incubation/virtual/vfs/VirtualVfsArchiveTestCase.java
===================================================================
--- projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/incubation/virtual/vfs/VirtualVfsArchiveTestCase.java (rev 0)
+++ projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/incubation/virtual/vfs/VirtualVfsArchiveTestCase.java 2009-07-15 16:06:36 UTC (rev 91303)
@@ -0,0 +1,133 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.embedded.core.incubation.virtual.vfs;
+
+import java.net.URL;
+
+import org.jboss.bootstrap.impl.as.lifecycle.VfsInitializingLifecycleEventHandler;
+import org.jboss.embedded.core.incubation.virtual.impl.vfs.VirtualVfsArchiveImpl;
+import org.jboss.embedded.core.incubation.virtual.spi.vfs.VirtualVfsArchive;
+import org.jboss.logging.Logger;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * VirtualVfsArchiveTestCase
+ *
+ * Test Cases to ensure that Virtual Archives backed by VFS are
+ * working as expected
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class VirtualVfsArchiveTestCase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(VirtualVfsArchiveTestCase.class);
+
+ /**
+ * Path to "WEB-INF"
+ */
+ private static final String PATH_WEB_INF = "WEB-INF";
+
+ /**
+ * Filename of web.xml
+ */
+ private static final String FILENAME_WEB_XML = "web.xml";
+
+ /**
+ * Path, relative to the resources base, of a test XML file
+ */
+ private static final String PATH_SOMETHING_XML = "xml/something.xml";
+
+ /**
+ * Separator character within archives
+ */
+ private static final char SEPARATOR = '/';
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ //-------------------------------------------------------------------------------------||
+ // Lifecycle --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Installs the URL Handlers for VFS
+ */
+ @BeforeClass
+ public static void installUrlHandlers() throws Exception
+ {
+ //TODO Hack, this relies upon a server lifecycle event handler, should be done outright
+ new VfsInitializingLifecycleEventHandler().handleEvent(null);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Tests ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Tests that a resource may be added to an archive from a given location,
+ * and assigned a new path within the archive
+ */
+ @Test
+ public void testAddResourceExplicitPathName() throws Exception
+ {
+ // Log
+ log.info("testAddResourceExplicitPathName");
+
+ // Get the base
+ final URL base = this.getBase();
+
+ // Get the path to the test XML file
+ final URL location = new URL(base, PATH_SOMETHING_XML);
+
+ // Define the new path
+ final String newPath = PATH_WEB_INF + SEPARATOR + FILENAME_WEB_XML;
+
+ // Make a virtual archive
+ final VirtualVfsArchive archive = new VirtualVfsArchiveImpl("something.war").addResource(location, newPath);
+ log.info(archive.toString(true));
+
+ //TODO Actually test something when we have better hooks to examine archive contents
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the test resources base
+ */
+ private URL getBase() throws Exception
+ {
+ return this.getClass().getProtectionDomain().getCodeSource().getLocation();
+ }
+}
Added: projects/embedded/trunk/core/src/test/resources/xml/something.xml
===================================================================
--- projects/embedded/trunk/core/src/test/resources/xml/something.xml (rev 0)
+++ projects/embedded/trunk/core/src/test/resources/xml/something.xml 2009-07-15 16:06:36 UTC (rev 91303)
@@ -0,0 +1 @@
+<something></something>
\ No newline at end of file
Modified: projects/embedded/trunk/testsuite-full-dep/pom.xml
===================================================================
--- projects/embedded/trunk/testsuite-full-dep/pom.xml 2009-07-15 15:59:53 UTC (rev 91302)
+++ projects/embedded/trunk/testsuite-full-dep/pom.xml 2009-07-15 16:06:36 UTC (rev 91303)
@@ -26,6 +26,7 @@
<!-- Versioning -->
<version.org.jboss.embedded_jboss.embedded.core>0.1.0-SNAPSHOT</version.org.jboss.embedded_jboss.embedded.core>
+ <version.org.apache.httpcomponents_httpclient>4.0-beta2</version.org.apache.httpcomponents_httpclient>
</properties>
@@ -46,6 +47,14 @@
<artifactId>junit</artifactId>
</dependency>
+ <!-- Apache HttpClient -->
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>${version.org.apache.httpcomponents_httpclient}</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</project>
Modified: projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java
===================================================================
--- projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java 2009-07-15 15:59:53 UTC (rev 91302)
+++ projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java 2009-07-15 16:06:36 UTC (rev 91303)
@@ -22,6 +22,10 @@
//FIXME We have to be in org.jboss due to JMX getPackage in AS
package org.jboss;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.URL;
+
import javax.naming.InitialContext;
import junit.framework.Assert;
@@ -33,6 +37,7 @@
import org.jboss.embedded.core.server.JBossASEmbeddedServerImpl;
import org.jboss.embedded.testsuite.fulldep.ejb3.slsb.OutputBean;
import org.jboss.embedded.testsuite.fulldep.ejb3.slsb.OutputLocalBusiness;
+import org.jboss.embedded.testsuite.fulldep.servlet.JspForwardingServlet;
import org.jboss.logging.Logger;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -82,6 +87,31 @@
*/
private static JBossASEmbeddedServer server;
+ /**
+ * Path to "WEB-INF"
+ */
+ private static final String PATH_WEB_INF = "WEB-INF";
+
+ /**
+ * Filename of web.xml
+ */
+ private static final String FILENAME_WEB_XML = "web.xml";
+
+ /**
+ * Path, relative to the resources base, of a test web.xml
+ */
+ private static final String PATH_ACTUAL_WEB_XML = "webxml/servletForwardingToJsp.xml";
+
+ /**
+ * Path, relative to the resources base, of a test JSP
+ */
+ private static final String PATH_JSP = "jsp/requestParamEcho.jsp";
+
+ /**
+ * Separator character within archives
+ */
+ private static final char SEPARATOR = '/';
+
//-------------------------------------------------------------------------------||
// Lifecycle --------------------------------------------------------------------||
//-------------------------------------------------------------------------------||
@@ -153,4 +183,63 @@
Assert.assertEquals(OutputLocalBusiness.OUTPUT, output);
}
+
+ /**
+ * Tests virtual deployment of a WAR containing a servlet
+ * and JSP
+ * @throws Exception
+ */
+ @Test
+ public void testVirtualWarServletJsp() throws Exception
+ {
+ // Log
+ log.info("testVirtualWarServletJsp");
+
+ // Get the base
+ final URL base = this.getBase();
+
+ // Get the path to the test web.xml file and JSP
+ final URL locationWebXml = new URL(base, PATH_ACTUAL_WEB_XML);
+ final URL locationJsp = new URL(base, PATH_JSP);
+
+ // Define the new path
+ final String newPathWebXml = PATH_WEB_INF + SEPARATOR + FILENAME_WEB_XML;
+
+ // Make a deployment
+ final String appName = "testServletJsp";
+ final String name = appName + ".war";
+ final Class<?> servletClass = JspForwardingServlet.class;
+ final VirtualVfsArchive deployment = new VirtualVfsArchiveImpl(name).addResource(locationWebXml, newPathWebXml)
+ .addResource(locationJsp, PATH_JSP).addClass(servletClass);
+ log.info(deployment.toString(true));
+
+ // Deploy
+ server.deploy(deployment);
+
+ /*
+ * FAILURE at Deploy above, everything blow here is untested/unused
+ */
+
+ // Make an HTTP Request
+ //TODO Fake it for now, use Commons HttpClient after this one works
+ final String param = "Embedded Rules!";
+ final URL url = new URL("http://localhost/" + appName + SEPARATOR + servletClass.getSimpleName() + "?jsp="
+ + PATH_JSP + "&requestParam=" + param);
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
+ final String line = reader.readLine();
+ Assert.assertEquals(param, line);
+
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the test resources base
+ */
+ private URL getBase() throws Exception
+ {
+ return this.getClass().getProtectionDomain().getCodeSource().getLocation();
+ }
}
Added: projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/embedded/testsuite/fulldep/servlet/JspForwardingServlet.java
===================================================================
--- projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/embedded/testsuite/fulldep/servlet/JspForwardingServlet.java (rev 0)
+++ projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/embedded/testsuite/fulldep/servlet/JspForwardingServlet.java 2009-07-15 16:06:36 UTC (rev 91303)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.embedded.testsuite.fulldep.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.logging.Logger;
+
+/**
+ * JspForwardingServlet
+ *
+ * Servlet which forwards to a JSP as requested
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class JspForwardingServlet extends HttpServlet
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(JspForwardingServlet.class);
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Name of the request parameter denoting which JSP to forward
+ */
+ public static final String REQ_PARAM_JSP = "jsp";
+
+ /**
+ * 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 JSP page
+ final String jsp = request.getParameter(REQ_PARAM_JSP);
+
+ // Handle unspecified
+ if (jsp == 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 + jsp;
+ log.info("Forwarding to: " + resolvedLocation);
+ final RequestDispatcher dispatcher = request.getRequestDispatcher(resolvedLocation);
+ dispatcher.forward(request, response);
+ }
+
+}
Added: projects/embedded/trunk/testsuite-full-dep/src/test/resources/jsp/requestParamEcho.jsp
===================================================================
--- projects/embedded/trunk/testsuite-full-dep/src/test/resources/jsp/requestParamEcho.jsp (rev 0)
+++ projects/embedded/trunk/testsuite-full-dep/src/test/resources/jsp/requestParamEcho.jsp 2009-07-15 16:06:36 UTC (rev 91303)
@@ -0,0 +1 @@
+${requestParam}
\ No newline at end of file
Added: projects/embedded/trunk/testsuite-full-dep/src/test/resources/webxml/servletForwardingToJsp.xml
===================================================================
--- projects/embedded/trunk/testsuite-full-dep/src/test/resources/webxml/servletForwardingToJsp.xml (rev 0)
+++ projects/embedded/trunk/testsuite-full-dep/src/test/resources/webxml/servletForwardingToJsp.xml 2009-07-15 16:06:36 UTC (rev 91303)
@@ -0,0 +1,13 @@
+<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>JspForwardingServlet</servlet-name>
+ <servlet-class>org.jboss.embedded.testsuite.fulldep.servlet.JspForwardingServlet
+ </servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>JspForwardingServlet</servlet-name>
+ <url-pattern>/JspForwardingServlet</url-pattern>
+ </servlet-mapping>
+</web-app>
More information about the jboss-cvs-commits
mailing list