[jboss-svn-commits] JBoss Common SVN: r3801 - in arquillian/trunk: container-jboss-remote-60 and 11 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Nov 25 10:25:49 EST 2009


Author: aslak
Date: 2009-11-25 10:25:49 -0500 (Wed, 25 Nov 2009)
New Revision: 3801

Added:
   arquillian/trunk/container-jboss-remote-60/
   arquillian/trunk/container-jboss-remote-60/pom.xml
   arquillian/trunk/container-jboss-remote-60/src/
   arquillian/trunk/container-jboss-remote-60/src/main/
   arquillian/trunk/container-jboss-remote-60/src/main/java/
   arquillian/trunk/container-jboss-remote-60/src/main/java/org/
   arquillian/trunk/container-jboss-remote-60/src/main/java/org/jboss/
   arquillian/trunk/container-jboss-remote-60/src/main/java/org/jboss/arquillian/
   arquillian/trunk/container-jboss-remote-60/src/main/java/org/jboss/arquillian/jboss/
   arquillian/trunk/container-jboss-remote-60/src/main/java/org/jboss/arquillian/jboss/InjectionEnricher.java
   arquillian/trunk/container-jboss-remote-60/src/main/java/org/jboss/arquillian/jboss/JbossDeploymentAppender.java
   arquillian/trunk/container-jboss-remote-60/src/main/java/org/jboss/arquillian/jboss/JbossRemoteContainer.java
   arquillian/trunk/container-jboss-remote-60/src/main/resources/
   arquillian/trunk/container-jboss-remote-60/src/main/resources/META-INF/
   arquillian/trunk/container-jboss-remote-60/src/main/resources/META-INF/services/
   arquillian/trunk/container-jboss-remote-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer
   arquillian/trunk/container-jboss-remote-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeploymentAppender
   arquillian/trunk/container-jboss-remote-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher
   arquillian/trunk/container-jboss-remote-60/src/test/
   arquillian/trunk/container-jboss-remote-60/src/test/java/
   arquillian/trunk/container-jboss-remote-60/src/test/resources/
Modified:
   arquillian/trunk/pom.xml
Log:
ARQ-32 Jboss Remote 6.0 Deployable Container. Equal to 5.1, only 6.0 deps. 



Property changes on: arquillian/trunk/container-jboss-remote-60
___________________________________________________________________
Name: svn:ignore
   + .classpath
.project
.settings
target


Added: arquillian/trunk/container-jboss-remote-60/pom.xml
===================================================================
--- arquillian/trunk/container-jboss-remote-60/pom.xml	                        (rev 0)
+++ arquillian/trunk/container-jboss-remote-60/pom.xml	2009-11-25 15:25:49 UTC (rev 3801)
@@ -0,0 +1,70 @@
+<?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 -->
+   <parent>
+      <groupId>org.jboss.arquillian</groupId>
+      <artifactId>arquillian-build</artifactId>
+      <version>1.0.0-SNAPSHOT</version>
+      <relativePath>../build/pom.xml</relativePath>
+   </parent>
+
+   <!-- Model Version -->
+   <modelVersion>4.0.0</modelVersion>
+
+   <!-- Artifact Configuration -->
+   <artifactId>arquillian-jboss-remote-60</artifactId>
+   <name>Arquillian Container Jboss AS Remote 6.0</name>
+   <description>Jboss AS 5.1 Remote Container integration for the Arquillian Project</description>
+
+
+   <!-- Properties -->
+   <properties>
+
+      <!-- Versioning -->
+
+   </properties>
+
+   <!-- Dependencies -->
+   <dependencies>
+
+      <!-- 
+    org.jboss.arquillian
+     -->
+      <dependency>
+         <groupId>org.jboss.arquillian</groupId>
+         <artifactId>arquillian-spi</artifactId>
+         <version>${project.version}</version>
+      </dependency>
+      <dependency>
+         <groupId>org.jboss.arquillian</groupId>
+         <artifactId>arquillian-protocol-servlet</artifactId>
+         <version>${project.version}</version>
+      </dependency>
+
+      <!-- 
+    org.jboss
+     -->
+
+      <dependency>
+         <groupId>org.jboss.jbossas</groupId>
+         <artifactId>jboss-as-client</artifactId>
+         <type>pom</type>
+         <version>6.0.0.M1-SNAPSHOT</version>
+      </dependency>
+      <!--
+         <dependency> <groupId>org.jboss.jbossas</groupId>
+         <artifactId>jboss-as-profileservice</artifactId>
+         <version>5.1.0.GA</version> <scope>compile</scope>
+         </dependency> <dependency> <groupId>org.jboss.jbossas</groupId>
+         <artifactId>jboss-as-system</artifactId>
+         <version>5.1.0.GA</version> <scope>compile</scope>
+         </dependency> <dependency> <groupId>org.jboss.jbossas</groupId>
+         <artifactId>jboss-as-server</artifactId>
+         <version>5.1.0.GA</version> <scope>compile</scope>
+         </dependency>
+      -->
+   </dependencies>
+</project>
+

Added: arquillian/trunk/container-jboss-remote-60/src/main/java/org/jboss/arquillian/jboss/InjectionEnricher.java
===================================================================
--- arquillian/trunk/container-jboss-remote-60/src/main/java/org/jboss/arquillian/jboss/InjectionEnricher.java	                        (rev 0)
+++ arquillian/trunk/container-jboss-remote-60/src/main/java/org/jboss/arquillian/jboss/InjectionEnricher.java	2009-11-25 15:25:49 UTC (rev 3801)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.arquillian.jboss;
+
+import java.lang.reflect.Field;
+
+import javax.ejb.EJB;
+import javax.naming.InitialContext;
+
+import org.jboss.arquillian.spi.TestEnricher;
+
+/**
+ * InjectionEnricher
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class InjectionEnricher implements TestEnricher
+{
+   private static final long serialVersionUID = 1L;
+
+   @Override
+   public void enrich(Object testCase)
+   {
+      injectClass(testCase);
+   }
+
+   void injectClass(Object testCase) 
+   {
+      try 
+      {
+         for(Field field : testCase.getClass().getDeclaredFields()) 
+         {
+            if(field.isAnnotationPresent(EJB.class)) 
+            {
+               Object ejb = lookupEJB(field);
+               field.setAccessible(true);
+               field.set(testCase, ejb);
+            }
+         }
+      } 
+      catch (Exception e) 
+      {
+         throw new RuntimeException("Could not inject members", e);
+      }
+   }
+
+   private Object lookupEJB(Field field) throws Exception 
+   {
+      // TODO: figure out test context ? 
+      InitialContext context = new InitialContext();
+      return context.lookup("test/" + field.getType().getSimpleName() + "Bean/local");
+   }
+}

Added: arquillian/trunk/container-jboss-remote-60/src/main/java/org/jboss/arquillian/jboss/JbossDeploymentAppender.java
===================================================================
--- arquillian/trunk/container-jboss-remote-60/src/main/java/org/jboss/arquillian/jboss/JbossDeploymentAppender.java	                        (rev 0)
+++ arquillian/trunk/container-jboss-remote-60/src/main/java/org/jboss/arquillian/jboss/JbossDeploymentAppender.java	2009-11-25 15:25:49 UTC (rev 3801)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.arquillian.jboss;
+
+import org.jboss.arquillian.spi.DeploymentAppender;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+
+/**
+ * EmbeddedDeploymentAppender
+ * 
+ * Package the required dependencies needed by the Jboss Embedded Container plugin 
+ * to run in container. 
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class JbossDeploymentAppender implements DeploymentAppender
+{
+
+   /* (non-Javadoc)
+    * @see org.jboss.arquillian.spi.DeploymentAppender#createArchive()
+    */
+   @Override
+   public Archive<?> createArchive()
+   {
+      JavaArchive archive = Archives.create("jboss-embedded-container.jar", JavaArchive.class)
+                        .addPackages(
+                              true, 
+                              Package.getPackage("org.jboss.arquillian.jboss"))
+                        .addManifestResource(
+                              "META-INF/services/org.jboss.arquillian.spi.TestEnricher",
+                              "services/org.jboss.arquillian.spi.TestEnricher");
+      return archive;
+   }
+
+}

Added: arquillian/trunk/container-jboss-remote-60/src/main/java/org/jboss/arquillian/jboss/JbossRemoteContainer.java
===================================================================
--- arquillian/trunk/container-jboss-remote-60/src/main/java/org/jboss/arquillian/jboss/JbossRemoteContainer.java	                        (rev 0)
+++ arquillian/trunk/container-jboss-remote-60/src/main/java/org/jboss/arquillian/jboss/JbossRemoteContainer.java	2009-11-25 15:25:49 UTC (rev 3801)
@@ -0,0 +1,302 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.arquillian.jboss;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.InitialContext;
+
+import org.jboss.arquillian.protocol.servlet.ServletMethodExecutor;
+import org.jboss.arquillian.spi.ContainerMethodExecutor;
+import org.jboss.arquillian.spi.DeployableContainer;
+import org.jboss.arquillian.spi.DeploymentException;
+import org.jboss.arquillian.spi.LifecycleException;
+import org.jboss.deployers.spi.management.deploy.DeploymentManager;
+import org.jboss.deployers.spi.management.deploy.DeploymentProgress;
+import org.jboss.deployers.spi.management.deploy.DeploymentStatus;
+import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.ProfileService;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
+import org.jboss.virtual.VFS;
+
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+import com.sun.net.httpserver.HttpServer;
+
+/**
+ * JbossRemoteContainer
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class JbossRemoteContainer implements DeployableContainer
+{
+   // TODO: replace by configuration
+   private static final String HOST_ADDRESS = "localhost";
+   
+   //private static final Logger log = Logger.getLogger(JbossRemoteContainer.class.getName());
+   
+   private final List<String> failedUndeployments = new ArrayList<String>();
+   private DeploymentManager deploymentManager;
+
+   private HttpServer httpFileServer;
+   
+   public JbossRemoteContainer()
+   {
+   }
+   
+   @Override
+   public void start() throws LifecycleException
+   {
+      try 
+      {
+         // TODO: configure http bind address
+         httpFileServer = HttpServer.create();
+         httpFileServer.bind(new InetSocketAddress(InetAddress.getByName(HOST_ADDRESS), 9000), -1);
+         httpFileServer.start();
+         initDeploymentManager();
+      } 
+      catch (Exception e) 
+      {
+         throw new LifecycleException("Could not connect to container", e);
+      }
+   }
+   
+   @Override
+   public void stop() throws LifecycleException
+   {
+      try 
+      {
+         httpFileServer.stop(0);
+         removeFailedUnDeployments();
+      } 
+      catch (Exception e) 
+      {
+         throw new LifecycleException("Could not clean up", e);
+      }
+   }
+
+   @Override
+   public ContainerMethodExecutor deploy(final Archive<?> archive) throws DeploymentException
+   {
+      if(archive == null) 
+      {
+         throw new IllegalArgumentException("Archive must be specified");
+      }
+      if (deploymentManager == null)
+      {
+         throw new IllegalStateException("start has not been called!");
+      }
+      String deploymentName = archive.getName();
+      
+      Exception failure = null;
+      try
+      {
+         httpFileServer.createContext("/" + deploymentName, new HttpHandler()
+         {
+            @Override
+            public void handle(HttpExchange exchange) throws IOException
+            {
+               InputStream zip = archive.as(ZipExporter.class).exportZip();
+               ByteArrayOutputStream zipStream = new ByteArrayOutputStream();
+               JbossRemoteContainer.copy(zip, zipStream);
+               zip.close();
+
+               byte[] zipArray = zipStream.toByteArray();
+               exchange.sendResponseHeaders(200, zipArray.length);
+
+               OutputStream out = exchange.getResponseBody();
+               out.write(zipArray);
+               out.close();
+
+            }
+         });
+         URL fileServerUrl = createFileServerURL(deploymentName);
+         
+         DeploymentProgress distribute = deploymentManager.distribute(deploymentName, fileServerUrl, true);
+         distribute.run();
+         DeploymentStatus uploadStatus = distribute.getDeploymentStatus(); 
+         if(uploadStatus.isFailed()) 
+         {
+            failure = uploadStatus.getFailure();
+            undeploy(deploymentName);
+         } 
+         else 
+         {
+            DeploymentProgress progress = deploymentManager.start(deploymentName);
+            progress.run();
+            DeploymentStatus status = progress.getDeploymentStatus();
+            if (status.isFailed())
+            {
+               failure = status.getFailure();
+               undeploy(deploymentName);
+            }
+         }
+      }
+      catch (Exception e)
+      {
+         throw new DeploymentException("Could not deploy " + deploymentName, e);
+      }
+      if (failure != null)
+      {
+         throw new DeploymentException("Failed to deply " + deploymentName, failure);
+      }
+      try 
+      {
+         return new ServletMethodExecutor(
+               new URL(
+                     "http",
+                     findRemoteServerHostAddress(),
+                     8080, 
+                     "/")
+               );
+      } 
+      catch (Exception e) 
+      {
+         throw new RuntimeException("Could not create ContianerMethodExecutor", e);
+      }
+   }
+
+   @Override
+   public void undeploy(Archive<?> archive) throws DeploymentException
+   {
+      if(archive == null) 
+      {
+         throw new IllegalArgumentException("Archive must be specified");
+      }
+      undeploy(archive.getName());
+   }
+
+   private void undeploy(String name) throws DeploymentException
+   {
+      try
+      {
+         DeploymentProgress stopProgress = deploymentManager.stop(name);
+         stopProgress.run();
+
+         DeploymentProgress undeployProgress = deploymentManager.remove(name);
+         undeployProgress.run();
+         if (undeployProgress.getDeploymentStatus().isFailed())
+         {
+            failedUndeployments.add(name);
+         }
+         httpFileServer.removeContext("/" + name);
+      }
+      catch (Exception e)
+      {
+         throw new DeploymentException("Could not undeploy " + name, e);
+      }
+   }
+
+   private void initDeploymentManager() throws Exception 
+   {
+      String profileName = "default";
+      InitialContext ctx = new InitialContext();
+      ProfileService ps = (ProfileService) ctx.lookup("ProfileService");
+      deploymentManager = ps.getDeploymentManager();
+      ProfileKey defaultKey = new ProfileKey(profileName);
+      deploymentManager.loadProfile(defaultKey);
+      VFS.init();
+   }
+   
+   private URL createFileServerURL(String archiveName) 
+   {
+      try 
+      {
+         InetSocketAddress address = httpFileServer.getAddress();
+         return new URL(
+               "http", 
+               address.getHostName(), 
+               address.getPort(), 
+               "/" + archiveName);
+      }
+      catch (MalformedURLException e) 
+      {
+         throw new RuntimeException("Could not create fileserver url", e);
+      }
+   }
+   
+   private void removeFailedUnDeployments() throws IOException
+   {
+      List<String> remainingDeployments = new ArrayList<String>();
+      for (String name : failedUndeployments)
+      {
+         try
+         {
+            DeploymentProgress undeployProgress = deploymentManager.remove(name);
+            undeployProgress.run();
+            if (undeployProgress.getDeploymentStatus().isFailed())
+            {
+               remainingDeployments.add(name);
+            }
+         }
+         catch (Exception e)
+         {
+            IOException ioe = new IOException();
+            ioe.initCause(e);
+            throw ioe;
+         }
+      }
+      if (remainingDeployments.size() > 0)
+      {
+         //log.error("Failed to undeploy these artifacts: " + remainingDeployments);
+      }
+      failedUndeployments.clear();
+   }
+
+   private String findRemoteServerHostAddress() {
+      try 
+      {
+         String providerURL = (String)new InitialContext().getEnvironment().get(
+               InitialContext.PROVIDER_URL);
+         
+         return providerURL.substring(0, providerURL.indexOf(":"));
+      } 
+      catch (Exception e) 
+      {
+         throw new RuntimeException("Could not determine host address", e);
+      }
+   }
+   
+   private static void copy(InputStream source, OutputStream destination) throws IOException
+   {
+      if (source == null)
+      {
+         throw new IllegalArgumentException("source cannot be null");
+      }
+      if (destination == null)
+      {
+         throw new IllegalArgumentException("destination cannot be null");
+      }
+      byte[] readBuffer = new byte[2156]; 
+      int bytesIn = 0; 
+      while((bytesIn = source.read(readBuffer)) != -1) 
+      { 
+         destination.write(readBuffer, 0, bytesIn); 
+      }
+   }
+}

Added: arquillian/trunk/container-jboss-remote-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer
===================================================================
--- arquillian/trunk/container-jboss-remote-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer	                        (rev 0)
+++ arquillian/trunk/container-jboss-remote-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer	2009-11-25 15:25:49 UTC (rev 3801)
@@ -0,0 +1 @@
+org.jboss.arquillian.jboss.JbossRemoteContainer
\ No newline at end of file

Added: arquillian/trunk/container-jboss-remote-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeploymentAppender
===================================================================
--- arquillian/trunk/container-jboss-remote-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeploymentAppender	                        (rev 0)
+++ arquillian/trunk/container-jboss-remote-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeploymentAppender	2009-11-25 15:25:49 UTC (rev 3801)
@@ -0,0 +1 @@
+org.jboss.arquillian.jboss.JbossDeploymentAppender
\ No newline at end of file

Added: arquillian/trunk/container-jboss-remote-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher
===================================================================
--- arquillian/trunk/container-jboss-remote-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher	                        (rev 0)
+++ arquillian/trunk/container-jboss-remote-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher	2009-11-25 15:25:49 UTC (rev 3801)
@@ -0,0 +1 @@
+org.jboss.arquillian.jboss.InjectionEnricher
\ No newline at end of file

Modified: arquillian/trunk/pom.xml
===================================================================
--- arquillian/trunk/pom.xml	2009-11-25 15:06:06 UTC (rev 3800)
+++ arquillian/trunk/pom.xml	2009-11-25 15:25:49 UTC (rev 3801)
@@ -50,6 +50,7 @@
     <module>protocol-servlet</module>
     <module>container-jboss-embedded</module>
     <module>container-jboss-remote-51</module>
+    <module>container-jboss-remote-60</module>
 </modules>
 
 </project>



More information about the jboss-svn-commits mailing list