tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1196869 - in /openejb/trunk/openejb: arquillian-tomee/arquillian-tomee-common/ arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee/arquillian-tomee-remote/ arquillian-tomee/arquilli...
Date Wed, 02 Nov 2011 23:42:59 GMT
Author: rmannibucau
Date: Wed Nov  2 23:42:59 2011
New Revision: 1196869

URL: http://svn.apache.org/viewvc?rev=1196869&view=rev
Log:
adding a test for cdi session scope

Added:
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/resources/default.remote.logging.properties
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/session/
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/session/PojoSessionScoped.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/session/PojoSessionScopedServletWrapper.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/session/SessionScopeTest.java
Modified:
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/pom.xml
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/MavenCache.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/SimpleMavenBuilderImpl.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/pom.xml
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
    openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappLoader.java
    openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/pom.xml?rev=1196869&r1=1196868&r2=1196869&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/pom.xml (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/pom.xml Wed Nov  2 23:42:59
2011
@@ -279,6 +279,11 @@
       <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
       <version>${version.shrinkwrap.resolver}</version>
     </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>1.6.1</version>
+    </dependency>
   </dependencies>
 
 </project>

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/MavenCache.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/MavenCache.java?rev=1196869&r1=1196868&r2=1196869&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/MavenCache.java
(original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/MavenCache.java
Wed Nov  2 23:42:59 2011
@@ -16,12 +16,6 @@
  */
 package org.apache.openejb.arquillian.common;
 
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URL;
-
 import org.apache.maven.repository.internal.MavenRepositorySystemSession;
 import org.codehaus.plexus.DefaultPlexusContainer;
 import org.codehaus.plexus.PlexusContainerException;
@@ -30,7 +24,6 @@ import org.jboss.shrinkwrap.resolver.imp
 import org.sonatype.aether.RepositorySystem;
 import org.sonatype.aether.RepositorySystemSession;
 import org.sonatype.aether.artifact.Artifact;
-import org.sonatype.aether.graph.Dependency;
 import org.sonatype.aether.installation.InstallRequest;
 import org.sonatype.aether.installation.InstallationException;
 import org.sonatype.aether.repository.LocalRepository;
@@ -39,6 +32,12 @@ import org.sonatype.aether.resolution.Ar
 import org.sonatype.aether.resolution.ArtifactResult;
 import org.sonatype.aether.util.artifact.DefaultArtifact;
 
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+
 /**
  * This class resolves artifacts in Maven. If an artifact (such as the Tomcat
  * zip) isn't available in Maven, this class can obtain it from an alternative
@@ -78,14 +77,14 @@ public class MavenCache {
 	}
 
 	public Artifact getArtifact(String coords, String altUrl) {
-		return getArtifact(getDependency(coords), altUrl);
+		return getArtifact(getArtifact(coords), altUrl);
 	}
 
-	public Artifact getArtifact(Dependency dependency, String altUrl) {
+	public Artifact getArtifact(Artifact art, String altUrl) {
 		Artifact artifact = null;
 		
 		try {
-			artifact = resolve(dependency);
+			artifact = resolve(art);
 		} catch (Exception e) {
 			// so lets try and download and install it instead
 			try {
@@ -93,10 +92,10 @@ public class MavenCache {
 					File file = download(altUrl);
 					
 					InstallRequest request = new InstallRequest();
-					artifact = dependency.getArtifact().setFile(file);
+					artifact = art.setFile(file);
 					request.addArtifact(artifact);
 					system.install(session, request);
-					artifact = resolve(dependency);
+					artifact = resolve(art);
 				}
 			} catch (InstallationException e1) {
 				e1.printStackTrace();
@@ -110,15 +109,14 @@ public class MavenCache {
 		return artifact;
 	}
 
-	public Dependency getDependency(String coords) {
-		return new Dependency(new DefaultArtifact(coords), "");
+	public Artifact getArtifact(String coords) {
+		return new DefaultArtifact(coords);
 	}
 
-	public Artifact resolve(Dependency dependency) throws ArtifactResolutionException {
-		ArtifactRequest artifactRequest = new ArtifactRequest(dependency.getArtifact(), settings.getRemoteRepositories(),
null);
+	public Artifact resolve(Artifact artifact) throws ArtifactResolutionException {
+        ArtifactRequest artifactRequest = new ArtifactRequest(artifact, settings.getRemoteRepositories(),
null);
 		ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest);
-		Artifact artifact = artifactResult.getArtifact();
-		return artifact;
+		return artifactResult.getArtifact();
 	}
 	
 	public File download(String source) throws DownloadException {
@@ -163,7 +161,8 @@ public class MavenCache {
 	}
 
 	public static void main(String[] args) {
-		File file = new MavenCache().getArtifact("org.apache.openejb:tomcat:zip:6.0.33", "http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.21/bin/apache-tomcat-7.0.21.zip").getFile();
+		// File file = new MavenCache().getArtifact("org.apache.openejb:tomcat:zip:6.0.33", "http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.21/bin/apache-tomcat-7.0.21.zip").getFile();
+		File file = new MavenCache().getArtifact("org.apache.openejb:apache-tomee:zip:plus:1.0.0-beta-2-SNAPSHOT",
"http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.21/bin/apache-tomcat-7.0.21.zip").getFile();
 		System.out.println(file.getAbsolutePath());
 	}
 }

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/SimpleMavenBuilderImpl.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/SimpleMavenBuilderImpl.java?rev=1196869&r1=1196868&r2=1196869&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/SimpleMavenBuilderImpl.java
(original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/SimpleMavenBuilderImpl.java
Wed Nov  2 23:42:59 2011
@@ -34,7 +34,7 @@ public class SimpleMavenBuilderImpl exte
 		List<Dependency> dependencies = MavenConverter.asDependencies(super.getDependencies());
 		for (Dependency dependency : dependencies) {
 			try {
-				Artifact artifact = new MavenCache().getArtifact(dependency, altUrl);
+				Artifact artifact = new MavenCache().getArtifact(dependency.getArtifact(), altUrl);
 				files.add(artifact.getFile());
 			} catch (Exception e) {
 				throw new ResolutionException("Unable to resolve an artifact", e);

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java?rev=1196869&r1=1196868&r2=1196869&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
(original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
Wed Nov  2 23:42:59 2011
@@ -64,11 +64,6 @@ public abstract class TomEEContainer imp
             out.write(SHUTDOWN_COMMAND.getBytes());
 
             waitForShutdown(10);
-
-            File dir = new File(configuration.getDir());
-            if (dir.exists()) {
-                FileUtils.deleteOnExit(dir); // if we can avoid to delete it between each
test it is better
-            }
         } catch (Exception e) {
             throw new LifecycleException("Unable to stop TomEE", e);
         }
@@ -103,7 +98,7 @@ public abstract class TomEEContainer imp
             File file;
             int i = 0;
             do { // be sure we don't override something existing
-                file = new File(tmpDir + File.separator + i + File.separator + archive.getName());
+                file = new File(tmpDir + File.separator + i++ + File.separator + archive.getName());
             } while (file.exists());
             if (!file.getParentFile().mkdirs()) {
                 LOGGER.warning("can't create " + file.getParent());

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/pom.xml?rev=1196869&r1=1196868&r2=1196869&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/pom.xml (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/pom.xml Wed Nov  2 23:42:59
2011
@@ -327,14 +327,53 @@
       <scope>compile</scope>
     </dependency>
     <dependency>
-    	<groupId>org.codehaus.swizzle</groupId>
-    	<artifactId>swizzle-stream</artifactId>
-    	<version>1.0.2</version>
+      <groupId>org.codehaus.swizzle</groupId>
+      <artifactId>swizzle-stream</artifactId>
+      <version>1.0.2</version>
     </dependency>
     <dependency>
-    	<groupId>org.jboss.shrinkwrap.descriptors</groupId>
-    	<artifactId>shrinkwrap-descriptors-impl</artifactId>
-    	<version>${version.shrinkwrap.descriptor}</version>
+      <groupId>org.jboss.shrinkwrap.descriptors</groupId>
+      <artifactId>shrinkwrap-descriptors-impl</artifactId>
+      <version>${version.shrinkwrap.descriptor}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>commons-httpclient</groupId>
+      <artifactId>commons-httpclient</artifactId>
+      <version>3.1</version>
+      <scope>test</scope>
     </dependency>
   </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <version>2.1</version>
+        <executions>
+          <execution>
+            <id>copy-test-libs</id>
+            <phase>process-test-resources</phase>
+            <configuration>
+              <artifactItems>
+                <artifactItem>
+                  <groupId>commons-httpclient</groupId>
+                  <artifactId>commons-httpclient</artifactId>
+                  <version>3.1</version>
+                </artifactItem>
+              </artifactItems>
+              <outputDirectory>
+                ${project.build.directory}/test-libs
+              </outputDirectory>
+              <stripVersion>true</stripVersion>
+            </configuration>
+            <goals>
+              <goal>copy</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
 </project>

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java?rev=1196869&r1=1196868&r2=1196869&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
(original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
Wed Nov  2 23:42:59 2011
@@ -16,6 +16,15 @@
  */
 package org.apache.openejb.arquillian.remote;
 
+import org.apache.openejb.arquillian.common.FileUtils;
+import org.apache.openejb.arquillian.common.MavenCache;
+import org.apache.openejb.arquillian.common.TomEEContainer;
+import org.apache.openejb.config.RemoteServer;
+import org.apache.tomee.installer.Installer;
+import org.apache.tomee.installer.Paths;
+import org.jboss.arquillian.container.spi.client.container.LifecycleException;
+import org.sonatype.aether.artifact.Artifact;
+
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
@@ -27,233 +36,248 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.net.Socket;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 
-import org.apache.openejb.arquillian.common.FileUtils;
-import org.apache.openejb.arquillian.common.MavenCache;
-import org.apache.openejb.arquillian.common.TomEEContainer;
-import org.apache.openejb.config.RemoteServer;
-import org.apache.tomee.installer.Installer;
-import org.apache.tomee.installer.Paths;
-import org.jboss.arquillian.container.spi.client.container.LifecycleException;
-import org.sonatype.aether.artifact.Artifact;
-
 /*
  * TODO: delete old embedded adapter, move the tests and set those up
  */
 public class RemoteTomEEContainer extends TomEEContainer {
-	private RemoteServer container;
-	private boolean needsStart = false;
+    private static File DOWNLOADED = null;
+
+    private RemoteServer container;
+    private boolean needsStart = false;
 
     public void start() throws LifecycleException {
-    	// see if TomEE is already running by checking the http port
-    	try {
-			connect(configuration.getHttpPort());
-		} catch (Exception e) {
-			needsStart = true;
-		}
-    	
-    	if (! needsStart) {
-    		return;
-    	}
-    	
-    	try {
-	    	File workingDirectory = new File(configuration.getDir());
-	    	workingDirectory.mkdirs();
-	
-	    	File openejbHome = null;
-	    	
-	    	if (configuration.getTomcatVersion() == null || configuration.getTomcatVersion().length()
== 0) {
-	        	downloadTomEE(workingDirectory);
-	        	openejbHome = findOpenEJBHome(workingDirectory);
-	    	} else {
-	    		downloadTomcat(workingDirectory, configuration.getTomcatVersion());
-	    		openejbHome = findOpenEJBHome(workingDirectory);
-	            File webappsOpenEJB = new File(openejbHome, "webapps/openejb");
-	            webappsOpenEJB.mkdirs();
-	            downloadOpenEJBWebapp(webappsOpenEJB);
-	
-	            System.setProperty("catalina.home", openejbHome.getAbsolutePath());
-			    System.setProperty("catalina.base", openejbHome.getAbsolutePath());
-			    System.setProperty("openejb.deploymentId.format","{appId}/{ejbJarId}/{ejbName}");
-			    Paths paths = new Paths(new File(openejbHome.getAbsolutePath(), "/webapps/openejb"));
-			    Installer installer = new Installer(paths, true);
-			    installer.installAll();
-	    	}
-	
-	    	if (openejbHome == null || (! openejbHome.exists())) {
-	    		throw new LifecycleException("Error finding OPENEJB_HOME");
-	    	}
-	    	
-	    	FileUtils.deleteOnExit(openejbHome);
-	    	Map<String, String> replacements = new HashMap<String, String>();
-		    replacements.put("8080", String.valueOf(configuration.getHttpPort()));
-		    replacements.put("8005", String.valueOf(configuration.getStopPort()));
-		    replace(replacements, new File(openejbHome, "conf/server.xml"));
-	    	
-	    	System.setProperty("tomee.http.port", String.valueOf(configuration.getHttpPort()));
-	    	System.setProperty("tomee.shutdown.port", String.valueOf(configuration.getStopPort()));
-	    	System.setProperty("java.naming.provider.url","http://localhost:" + configuration.getHttpPort()
+ "/openejb/ejb");
-	    	System.setProperty("connect.tries","90");
-	    	System.setProperty("server.http.port", String.valueOf(configuration.getHttpPort()));
-	    	System.setProperty("server.shutdown.port", String.valueOf(configuration.getStopPort()));
-	    	System.setProperty("java.opts", "-Xmx512m -Xms256m -XX:PermSize=64m -XX:MaxPermSize=256m
-XX:ReservedCodeCacheSize=64m");
-	    	System.setProperty("openejb.home", openejbHome.getAbsolutePath());
-	
-	    	container = new RemoteServer();
-			container.start();
-    	} catch (Exception e) {
-    		throw new LifecycleException("Unable to start remote container", e);
-    	}
-    }
-
-	private File findOpenEJBHome(File directory) {
-		File conf = new File(directory, "conf");
-		File webapps = new File(directory, "webapps");
-		
-		if (conf.exists() && conf.isDirectory() && webapps.exists() &&
webapps.isDirectory()) {
-			return directory;
-		}
-		
-		for (File file : directory.listFiles()) {
-			if (".".equals(file.getName()) || "..".equals(file.getName())) continue;
-			
-			File found = findOpenEJBHome(file);
-			if (found != null) {
-				return found;
-			}
-		}
-		
-		return null;
-	}
-
-	protected void downloadTomEE(File catalinaDirectory) throws LifecycleException {
-		String artifactName;
-		if (configuration.isPlusContainer()) {
-			artifactName = "org.apache.openejb:apache-tomee:zip:plus:" + configuration.getOpenejbVersion();
-		} else {
-			artifactName = "org.apache.openejb:apache-tomee:zip:webprofile:" + configuration.getOpenejbVersion();
-		}
-            
+        // see if TomEE is already running by checking the http port
+        try {
+            connect(configuration.getHttpPort());
+        } catch (Exception e) {
+            needsStart = true;
+        }
+
+        if (!needsStart) {
+            return;
+        }
+
+        try {
+            final File workingDirectory = new File(configuration.getDir());
+            workingDirectory.mkdirs();
+            if (workingDirectory.exists()) {
+                FileUtils.deleteOnExit(workingDirectory);
+            }
+
+            File openejbHome;
+            if (DOWNLOADED != null && DOWNLOADED.getAbsolutePath().startsWith(workingDirectory.getAbsolutePath()))
{
+                openejbHome = findOpenEJBHome(workingDirectory);
+            } else if (configuration.getTomcatVersion() == null || configuration.getTomcatVersion().length()
== 0) {
+                downloadTomEE(workingDirectory);
+                openejbHome = findOpenEJBHome(workingDirectory);
+            } else {
+                downloadTomcat(workingDirectory, configuration.getTomcatVersion());
+                openejbHome = findOpenEJBHome(workingDirectory);
+                File webappsOpenEJB = new File(openejbHome, "webapps/openejb");
+                webappsOpenEJB.mkdirs();
+                downloadOpenEJBWebapp(webappsOpenEJB);
+
+                System.setProperty("catalina.home", openejbHome.getAbsolutePath());
+                System.setProperty("catalina.base", openejbHome.getAbsolutePath());
+                System.setProperty("openejb.deploymentId.format", "{appId}/{ejbJarId}/{ejbName}");
+                Paths paths = new Paths(new File(openejbHome.getAbsolutePath(), "/webapps/openejb"));
+                Installer installer = new Installer(paths, true);
+                installer.installAll();
+            }
+            DOWNLOADED = workingDirectory;
+
+            if (openejbHome == null || (!openejbHome.exists())) {
+                throw new LifecycleException("Error finding OPENEJB_HOME");
+            }
+
+            FileUtils.deleteOnExit(openejbHome);
+            Map<String, String> replacements = new HashMap<String, String>();
+            replacements.put("8080", String.valueOf(configuration.getHttpPort()));
+            replacements.put("8005", String.valueOf(configuration.getStopPort()));
+            replace(replacements, new File(openejbHome, "conf/server.xml"));
+
+            write(Thread.currentThread().getContextClassLoader().getResource("default.remote.logging.properties"),
new File(openejbHome, "conf/logging.properties"));
+
+            System.setProperty("tomee.http.port", String.valueOf(configuration.getHttpPort()));
+            System.setProperty("tomee.shutdown.port", String.valueOf(configuration.getStopPort()));
+            System.setProperty("java.naming.provider.url", "http://localhost:" + configuration.getHttpPort()
+ "/openejb/ejb");
+            System.setProperty("connect.tries", "90");
+            System.setProperty("server.http.port", String.valueOf(configuration.getHttpPort()));
+            System.setProperty("server.shutdown.port", String.valueOf(configuration.getStopPort()));
+            System.setProperty("java.opts", "-Xmx512m -Xms256m -XX:PermSize=64m -XX:MaxPermSize=256m
-XX:ReservedCodeCacheSize=64m");
+            System.setProperty("openejb.home", openejbHome.getAbsolutePath());
+
+            container = new RemoteServer();
+            container.start();
+        } catch (Exception e) {
+            throw new LifecycleException("Unable to start remote container", e);
+        }
+    }
+
+    private static void write(URL resource, File file) throws IOException {
+        if (file.exists()) {
+            FileUtils.delete(file);
+        }
+        InputStream is = resource.openStream();
+        OutputStream out = new FileOutputStream(file);
+        byte buf[] = new byte[1024];
+        int len;
+        while ((len = is.read(buf)) > 0) {
+            out.write(buf, 0, len);
+        }
+        out.close();
+        is.close();
+    }
+
+    private File findOpenEJBHome(File directory) {
+        File conf = new File(directory, "conf");
+        File webapps = new File(directory, "webapps");
+
+        if (conf.exists() && conf.isDirectory() && webapps.exists() &&
webapps.isDirectory()) {
+            return directory;
+        }
+
+        for (File file : directory.listFiles()) {
+            if (".".equals(file.getName()) || "..".equals(file.getName())) continue;
+
+            File found = findOpenEJBHome(file);
+            if (found != null) {
+                return found;
+            }
+        }
+
+        return null;
+    }
+
+    protected void downloadTomEE(File catalinaDirectory) throws LifecycleException {
+        String artifactName;
+        if (configuration.isPlusContainer()) {
+            artifactName = "org.apache.openejb:apache-tomee:zip:plus:" + configuration.getOpenejbVersion();
+        } else {
+            artifactName = "org.apache.openejb:apache-tomee:zip:webprofile:" + configuration.getOpenejbVersion();
+        }
+
         File zipFile = downloadFile(artifactName, null);
         ZipExtractor.unzip(zipFile, catalinaDirectory);
-	}
+    }
 
     protected File downloadFile(String artifactName, String altUrl) {
         Artifact artifact = new MavenCache().getArtifact(artifactName, altUrl);
         return artifact.getFile();
     }
 
-	protected void downloadOpenEJBWebapp(File targetDirectory) throws LifecycleException {
-		String artifactName;
-		if (configuration.isPlusContainer()) {
-			artifactName = "org.apache.openejb:openejb-tomcat-plus-webapp:war:" + configuration.getOpenejbVersion();
-		} else {
-			artifactName = "org.apache.openejb:openejb-tomcat-webapp:war:" + configuration.getOpenejbVersion();
-		}
+    protected void downloadOpenEJBWebapp(File targetDirectory) throws LifecycleException
{
+        String artifactName;
+        if (configuration.isPlusContainer()) {
+            artifactName = "org.apache.openejb:openejb-tomcat-plus-webapp:war:" + configuration.getOpenejbVersion();
+        } else {
+            artifactName = "org.apache.openejb:openejb-tomcat-webapp:war:" + configuration.getOpenejbVersion();
+        }
 
         File zipFile = downloadFile(artifactName, null);
         ZipExtractor.unzip(zipFile, targetDirectory);
     }
-	
-	protected void downloadTomcat(File catalinaDirectory, String tomcatVersion) throws LifecycleException
{
-		String source = null;
-
-		if (tomcatVersion.startsWith("7.")) {
-			source = "http://archive.apache.org/dist/tomcat/tomcat-7/v"	+ tomcatVersion + "/bin/apache-tomcat-"
+ tomcatVersion	+ ".zip";
-		}
-
-		if (tomcatVersion.startsWith("6.")) {
-			source = "http://archive.apache.org/dist/tomcat/tomcat-6/v"	+ tomcatVersion + "/bin/apache-tomcat-"
+ tomcatVersion	+ ".zip";
-		}
-
-		if (tomcatVersion.startsWith("5.5")) {
-			source = "http://archive.apache.org/dist/tomcat/tomcat-5/v"	+ tomcatVersion + "/bin/apache-tomcat-"
+ tomcatVersion	+ ".zip";
-		}
-
-		if (source == null) {
-			throw new LifecycleException("Unable to find URL for Tomcat " + tomcatVersion);
-		}
+
+    protected void downloadTomcat(File catalinaDirectory, String tomcatVersion) throws LifecycleException
{
+        String source = null;
+
+        if (tomcatVersion.startsWith("7.")) {
+            source = "http://archive.apache.org/dist/tomcat/tomcat-7/v" + tomcatVersion +
"/bin/apache-tomcat-" + tomcatVersion + ".zip";
+        }
+
+        if (tomcatVersion.startsWith("6.")) {
+            source = "http://archive.apache.org/dist/tomcat/tomcat-6/v" + tomcatVersion +
"/bin/apache-tomcat-" + tomcatVersion + ".zip";
+        }
+
+        if (tomcatVersion.startsWith("5.5")) {
+            source = "http://archive.apache.org/dist/tomcat/tomcat-5/v" + tomcatVersion +
"/bin/apache-tomcat-" + tomcatVersion + ".zip";
+        }
+
+        if (source == null) {
+            throw new LifecycleException("Unable to find URL for Tomcat " + tomcatVersion);
+        }
 
         File zipFile = downloadFile("org.apache.openejb:tomcat:zip:" + tomcatVersion, source);
         ZipExtractor.unzip(zipFile, catalinaDirectory);
-	}
+    }
 
     public void stop() throws LifecycleException {
-    	// only stop the container if we started it
-    	if (needsStart) {
-    		container.stop();
-            FileUtils.delete(new File(configuration.getDir()));
-    	}
+        // only stop the container if we started it
+        if (needsStart) {
+            container.stop();
+        }
     }
-    
+
     public void connect(int port) throws Exception {
-    	Socket socket = new Socket("localhost", port);
+        Socket socket = new Socket("localhost", port);
         OutputStream out = socket.getOutputStream();
         out.close();
     }
 
-	private void replace(Map<String, String> replacements, File file) throws IOException
{
-		BufferedReader reader = null;
-		PrintWriter writer = null;
-		
-		try {
-			File tmpFile = copyToTempFile(file);
-			reader = new BufferedReader(new FileReader(tmpFile));
-			writer = new PrintWriter(new FileWriter(file));
-			String line = null;
-			
-			while ((line = reader.readLine()) != null) {
-				Iterator<String> iterator = replacements.keySet().iterator();
-				while (iterator.hasNext()) {
-					String pattern = iterator.next();
-					String replacement = replacements.get(pattern);
-					
-					line = line.replaceAll(pattern, replacement);
-				}
-				
-				writer.println(line);
-			}
-		} catch (IOException e) {
-			throw e;
-		} finally {
-			if (reader != null) {
-				reader.close();
-			}
-			
-			if (writer != null) {
-				writer.close();
-			}
-		}
-	}
-
-	private File copyToTempFile(File file) throws IOException {
-		InputStream is = null;
-		OutputStream os = null;
-		
-		File tmpFile;
-		try {
-			tmpFile = File.createTempFile("oejb", ".fil");
-			tmpFile.deleteOnExit();
-			
-			is = new FileInputStream(file);
-			os = new FileOutputStream(tmpFile);
-			
-			Installer.copy(is, os);
-		} catch (IOException e) {
-			throw e;
-		} finally {
-			if (is != null) {
-				is.close();
-			}
-			
-			if (os != null) {
-				os.close();
-			}
-		}
-		
-		return tmpFile;
-	}
+    private void replace(Map<String, String> replacements, File file) throws IOException
{
+        BufferedReader reader = null;
+        PrintWriter writer = null;
+
+        try {
+            File tmpFile = copyToTempFile(file);
+            reader = new BufferedReader(new FileReader(tmpFile));
+            writer = new PrintWriter(new FileWriter(file));
+            String line;
+
+            while ((line = reader.readLine()) != null) {
+                Iterator<String> iterator = replacements.keySet().iterator();
+                while (iterator.hasNext()) {
+                    String pattern = iterator.next();
+                    String replacement = replacements.get(pattern);
+
+                    line = line.replaceAll(pattern, replacement);
+                }
+
+                writer.println(line);
+            }
+        } catch (IOException e) {
+            throw e;
+        } finally {
+            if (reader != null) {
+                reader.close();
+            }
+
+            if (writer != null) {
+                writer.close();
+            }
+        }
+    }
+
+    private File copyToTempFile(File file) throws IOException {
+        InputStream is = null;
+        OutputStream os = null;
+
+        File tmpFile;
+        try {
+            tmpFile = File.createTempFile("oejb", ".fil");
+            tmpFile.deleteOnExit();
+
+            is = new FileInputStream(file);
+            os = new FileOutputStream(tmpFile);
+
+            Installer.copy(is, os);
+        } catch (IOException e) {
+            throw e;
+        } finally {
+            if (is != null) {
+                is.close();
+            }
+
+            if (os != null) {
+                os.close();
+            }
+        }
+
+        return tmpFile;
+    }
 }

Added: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/resources/default.remote.logging.properties
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/resources/default.remote.logging.properties?rev=1196869&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/resources/default.remote.logging.properties
(added)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/resources/default.remote.logging.properties
Wed Nov  2 23:42:59 2011
@@ -0,0 +1,52 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+
+handlers = 1catalina.java.util.logging.ConsoleHandler, 2localhost.java.util.logging.ConsoleHandler,
3manager.java.util.logging.ConsoleHandler, 4host-manager.java.util.logging.ConsoleHandler,
java.util.logging.ConsoleHandler
+
+.handlers = 1catalina.java.util.logging.ConsoleHandler, java.util.logging.ConsoleHandler
+
+1catalina.java.util.logging.ConsoleHandler.level = FINE
+1catalina.java.util.logging.ConsoleHandler.directory = ${catalina.base}/logs
+1catalina.java.util.logging.ConsoleHandler.prefix = catalina.
+
+2localhost.java.util.logging.ConsoleHandler.level = FINE
+2localhost.java.util.logging.ConsoleHandler.directory = ${catalina.base}/logs
+2localhost.java.util.logging.ConsoleHandler.prefix = localhost.
+
+3manager.java.util.logging.ConsoleHandler.level = FINE
+3manager.java.util.logging.ConsoleHandler.directory = ${catalina.base}/logs
+3manager.java.util.logging.ConsoleHandler.prefix = manager.
+
+4host-manager.java.util.logging.ConsoleHandler.level = FINE
+4host-manager.java.util.logging.ConsoleHandler.directory = ${catalina.base}/logs
+4host-manager.java.util.logging.ConsoleHandler.prefix = host-manager.
+
+java.util.logging.ConsoleHandler.level = FINE
+java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
+
+org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
+org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.java.util.logging.ConsoleHandler
+
+org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
+org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.java.util.logging.ConsoleHandler
+
+org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO
+org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers =
4host-manager.java.util.logging.ConsoleHandler
+
+
+log4j.rootLogger                   = INFO,C
+log4j.appender.C                           = org.apache.log4j.ConsoleAppender
+log4j.appender.C.layout                    = org.apache.log4j.SimpleLayout
+

Added: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/session/PojoSessionScoped.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/session/PojoSessionScoped.java?rev=1196869&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/session/PojoSessionScoped.java
(added)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/session/PojoSessionScoped.java
Wed Nov  2 23:42:59 2011
@@ -0,0 +1,33 @@
+package org.apache.openejb.arquillian.session;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.SessionScoped;
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * @author rmannibucau
+ */
+@SessionScoped
+public class PojoSessionScoped implements Serializable {
+    private static AtomicInteger ID = new AtomicInteger();
+
+    private long ms;
+    private int id;
+
+    public PojoSessionScoped() {
+        ms = System.currentTimeMillis();
+    }
+
+    @PostConstruct public void initId() {
+        id = ID.incrementAndGet();
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public long getMs() {
+        return ms;
+    }
+}

Added: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/session/PojoSessionScopedServletWrapper.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/session/PojoSessionScopedServletWrapper.java?rev=1196869&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/session/PojoSessionScopedServletWrapper.java
(added)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/session/PojoSessionScopedServletWrapper.java
Wed Nov  2 23:42:59 2011
@@ -0,0 +1,22 @@
+package org.apache.openejb.arquillian.session;
+
+import javax.inject.Inject;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * @author rmannibucau
+ */
+public class PojoSessionScopedServletWrapper extends HttpServlet {
+   @Inject private PojoSessionScoped pojo;
+
+   @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException {
+      resp.setContentType("text/plain");
+      resp.getWriter().println("ms=" + pojo.getMs());
+      resp.getWriter().println("id=" + pojo.getId());
+   }
+
+}

Added: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/session/SessionScopeTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/session/SessionScopeTest.java?rev=1196869&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/session/SessionScopeTest.java
(added)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/session/SessionScopeTest.java
Wed Nov  2 23:42:59 2011
@@ -0,0 +1,72 @@
+package org.apache.openejb.arquillian.session;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.openejb.util.IOUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.descriptor.api.Descriptors;
+import org.jboss.shrinkwrap.descriptor.api.spec.servlet.web.WebAppDescriptor;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.File;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URL;
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+
+/**
+ * @author rmannibucau
+ */
+@RunWith(Arquillian.class)
+public class SessionScopeTest {
+    public static final String TEST_SESSION_URL = "http://127.0.0.1:9080/test/session";
+
+    @Deployment
+    public static WebArchive createDeployment() {
+        return ShrinkWrap.create(WebArchive.class, "test.war")
+            .addClass(PojoSessionScoped.class).addClass(PojoSessionScopedServletWrapper.class)
+            .addAsLibraries(new File("target/test-libs/commons-httpclient.jar"))
+            .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"))
+            .setWebXML(new StringAsset(Descriptors.create(WebAppDescriptor.class)
+                .version("3.0")
+                .servlet(PojoSessionScopedServletWrapper.class, "/session")
+                .exportAsString()));
+    }
+
+    @Test
+    public void testShouldBeAbleToAccessServletAndEjb() throws Exception {
+        String[] sessionResult = new String[2];
+        for (int i = 0; i < sessionResult.length; i++) {
+            HttpClient client = new HttpClient();
+            HttpMethod get = new GetMethod(TEST_SESSION_URL);
+            String[] contents = new String[2];
+            try {
+                for (int j = 0; j < contents.length; j++) {
+                    int out = client.executeMethod(get);
+                    if (out != 200) {
+                        throw new RuntimeException("get " + TEST_SESSION_URL + " returned
" + out);
+                    }
+                    contents[j] = get.getResponseBodyAsString();
+                }
+
+                assertEquals(contents[0], contents[1]);
+            } finally {
+                get.releaseConnection();
+            }
+            sessionResult[i] = contents[0];
+        }
+
+        assertNotSame(sessionResult[0], sessionResult[1]);
+    }
+}

Modified: openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappLoader.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappLoader.java?rev=1196869&r1=1196868&r2=1196869&view=diff
==============================================================================
--- openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappLoader.java
(original)
+++ openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappLoader.java
Wed Nov  2 23:42:59 2011
@@ -74,8 +74,12 @@ public class TomEEWebappLoader extends W
         }
 
         private static void add(Collection<URL> urls, Enumeration<URL> enumUrls)
{
-            while (enumUrls.hasMoreElements()) {
-                urls.add(enumUrls.nextElement());
+            try {
+                while (enumUrls.hasMoreElements()) {
+                    urls.add(enumUrls.nextElement());
+                }
+            } catch (IllegalStateException ese) {
+                // ignored: if jars are already closed...shutdown for instance
             }
         }
     }

Modified: openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java?rev=1196869&r1=1196868&r2=1196869&view=diff
==============================================================================
--- openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
(original)
+++ openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
Wed Nov  2 23:42:59 2011
@@ -582,6 +582,7 @@ public class TomcatWebAppBuilder impleme
                 } catch (Exception e) {
                     undeploy(standardContext, contextInfo);
                     logger.error("Unable to deploy collapsed ear in war " + standardContext.getPath()
+ ": Exception: " + e.getMessage(), e);
+                    return;
                 }
             }
         }



Mime
View raw message