[jboss-svn-commits] JBoss Common SVN: r3993 - in shrinkwrap/trunk: extension-openejb and 16 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Feb 6 22:30:08 EST 2010


Author: ALRubinger
Date: 2010-02-06 22:30:07 -0500 (Sat, 06 Feb 2010)
New Revision: 3993

Added:
   shrinkwrap/trunk/extension-openejb/
   shrinkwrap/trunk/extension-openejb/pom.xml
   shrinkwrap/trunk/extension-openejb/src/
   shrinkwrap/trunk/extension-openejb/src/main/
   shrinkwrap/trunk/extension-openejb/src/main/java/
   shrinkwrap/trunk/extension-openejb/src/main/java/org/
   shrinkwrap/trunk/extension-openejb/src/main/java/org/jboss/
   shrinkwrap/trunk/extension-openejb/src/main/java/org/jboss/shrinkwrap/
   shrinkwrap/trunk/extension-openejb/src/main/java/org/jboss/shrinkwrap/openejb/
   shrinkwrap/trunk/extension-openejb/src/main/java/org/jboss/shrinkwrap/openejb/config/
   shrinkwrap/trunk/extension-openejb/src/main/java/org/jboss/shrinkwrap/openejb/config/ShrinkWrapConfigurationFactory.java
   shrinkwrap/trunk/extension-openejb/src/main/resources/
   shrinkwrap/trunk/extension-openejb/src/test/
   shrinkwrap/trunk/extension-openejb/src/test/java/
   shrinkwrap/trunk/extension-openejb/src/test/java/org/
   shrinkwrap/trunk/extension-openejb/src/test/java/org/jboss/
   shrinkwrap/trunk/extension-openejb/src/test/java/org/jboss/shrinkwrap/
   shrinkwrap/trunk/extension-openejb/src/test/java/org/jboss/shrinkwrap/openejb/
   shrinkwrap/trunk/extension-openejb/src/test/java/org/jboss/shrinkwrap/openejb/ejb/
   shrinkwrap/trunk/extension-openejb/src/test/java/org/jboss/shrinkwrap/openejb/ejb/EchoBean.java
   shrinkwrap/trunk/extension-openejb/src/test/java/org/jboss/shrinkwrap/openejb/ejb/EchoLocalBusiness.java
   shrinkwrap/trunk/extension-openejb/src/test/java/org/jboss/shrinkwrap/openejb/test/
   shrinkwrap/trunk/extension-openejb/src/test/java/org/jboss/shrinkwrap/openejb/test/ShrinkWrapArchiveDeploymentTest.java
   shrinkwrap/trunk/extension-openejb/src/test/resources/
Modified:
   shrinkwrap/trunk/pom.xml
Log:
[SHRINKWRAP-128] Commit (possibly) temporary OpenEJB integration, at least until OpenEJB houses this with a release themselves


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


Added: shrinkwrap/trunk/extension-openejb/pom.xml
===================================================================
--- shrinkwrap/trunk/extension-openejb/pom.xml	                        (rev 0)
+++ shrinkwrap/trunk/extension-openejb/pom.xml	2010-02-07 03:30:07 UTC (rev 3993)
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+  <!--
+  vi:ts=2:sw=2:expandtab:
+-->
+<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.shrinkwrap</groupId>
+    <artifactId>shrinkwrap-build</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <relativePath>../build/pom.xml</relativePath>
+  </parent>
+
+  <!-- Model Version -->
+  <modelVersion>4.0.0</modelVersion>
+
+  <!-- Artifact Configuration -->
+  <artifactId>shrinkwrap-extension-openejb</artifactId>
+  <name>ShrinkWrap OpenEJB Integration Extension</name>
+  <description>ShrinkWrap Integration Extension for the OpenEJB Project</description>
+
+
+  <!-- Properties -->
+  <properties>
+  
+    <!-- Versioning -->
+    <version.org.apache.openejb_openejb.core>3.1.2</version.org.apache.openejb_openejb.core>
+
+  </properties>
+
+  <!-- Dependencies -->
+  <dependencies>
+
+    <!-- 
+    org.jboss.shrinkwrap    
+     -->
+    <dependency>
+      <groupId>org.jboss.shrinkwrap</groupId>
+      <artifactId>shrinkwrap-api</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.shrinkwrap</groupId>
+      <artifactId>shrinkwrap-impl-base</artifactId>
+      <version>${project.version}</version>
+      <scope>test</scope>
+    </dependency>
+
+    <!-- 
+    External Projects
+     -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    
+    <!-- org.apache.openejb --> 
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-core</artifactId>
+      <version>${version.org.apache.openejb_openejb.core}</version>
+      <scope>provided</scope>
+    </dependency>
+    
+  </dependencies>
+
+  <!-- Build Configuration -->
+  <build>
+  
+    <plugins>
+
+    </plugins>
+    
+  </build>
+  
+</project>
+

Added: shrinkwrap/trunk/extension-openejb/src/main/java/org/jboss/shrinkwrap/openejb/config/ShrinkWrapConfigurationFactory.java
===================================================================
--- shrinkwrap/trunk/extension-openejb/src/main/java/org/jboss/shrinkwrap/openejb/config/ShrinkWrapConfigurationFactory.java	                        (rev 0)
+++ shrinkwrap/trunk/extension-openejb/src/main/java/org/jboss/shrinkwrap/openejb/config/ShrinkWrapConfigurationFactory.java	2010-02-07 03:30:07 UTC (rev 3993)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.shrinkwrap.openejb.config;
+
+import java.io.File;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.UUID;
+
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.config.ConfigurationFactory;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
+
+/**
+ * {@link ConfigurationFactory} extension which is capable of creating
+ * {@link AppInfo} metadata from a ShrinkWrap {@link Archive}.
+ * 
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ * @deprecated Until this becomes part of OpenEJB proper
+ */
+ at Deprecated
+public class ShrinkWrapConfigurationFactory extends ConfigurationFactory
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * System property denoting the location of the temp dir
+    */
+   private static final String SYS_PROP_TMP_DIR = "java.io.tmpdir";
+
+   //-------------------------------------------------------------------------------------||
+   // Functional Methods -----------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Creates a new {@link AppInfo} from the specified {@link Archive}
+    * 
+    * @param archive
+    * @return
+    * @throws OpenEJBException
+    * @throws IllegalArgumentException If the archive was not specified
+    */
+   public AppInfo configureApplication(final Archive<?> archive) throws OpenEJBException, IllegalArgumentException
+   {
+      // Precondition checks
+      if (archive == null)
+      {
+         throw new IllegalArgumentException("archive must be specified");
+      }
+
+      /*
+       * Make a temp file based on the ZIP output of the specified archive
+       */
+
+      // Get location for the new temp dir, and validate
+      final String tempDirLocation = AccessController.doPrivileged(GetTempDirAction.INSTANCE);
+      final File tmpDir = new File(tempDirLocation);
+      if (!tmpDir.exists())
+      {
+         throw new IllegalStateException("Could not obtain valid temp directory: " + tmpDir.getAbsolutePath());
+      }
+      if (!tmpDir.isDirectory())
+      {
+         throw new IllegalStateException("Temp location must be a directory: " + tmpDir.getAbsolutePath());
+      }
+
+      // Put each archive in a uniquely-namespaced directory
+      final UUID uuid = UUID.randomUUID();
+      final File namespace = new File(tmpDir, uuid.toString());
+      if (!namespace.mkdir())
+      {
+         throw new IllegalStateException("Could not create a unique namespace into which we'll deploy "
+               + archive.getName() + ": " + namespace.getAbsolutePath());
+      }
+
+      // Make the new temp file, set to delete on VM exit
+      final String name = archive.getName();
+      final File tmpFile = new File(namespace, name);
+      tmpFile.deleteOnExit();
+
+      // Write the ZIP to the temp file
+      archive.as(ZipExporter.class).exportZip(tmpFile);
+
+      // Delegate to the File-based configuration impl
+      return configureApplication(tmpFile);
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Inner Classes ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Privileged action to obtain the temp directory
+    */
+   private static enum GetTempDirAction implements PrivilegedAction<String> {
+      INSTANCE;
+      @Override
+      public String run()
+      {
+         return System.getProperty(SYS_PROP_TMP_DIR);
+      }
+   }
+}

Added: shrinkwrap/trunk/extension-openejb/src/test/java/org/jboss/shrinkwrap/openejb/ejb/EchoBean.java
===================================================================
--- shrinkwrap/trunk/extension-openejb/src/test/java/org/jboss/shrinkwrap/openejb/ejb/EchoBean.java	                        (rev 0)
+++ shrinkwrap/trunk/extension-openejb/src/test/java/org/jboss/shrinkwrap/openejb/ejb/EchoBean.java	2010-02-07 03:30:07 UTC (rev 3993)
@@ -0,0 +1,45 @@
+/**
+ * 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.
+ */
+package org.jboss.shrinkwrap.openejb.ejb;
+
+import javax.ejb.Local;
+import javax.ejb.Stateless;
+
+/**
+ * Implementation class of an EJB which returns request parameters
+ * 
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Local(EchoLocalBusiness.class)
+public class EchoBean implements EchoLocalBusiness
+{
+   //-------------------------------------------------------------------------------------||
+   // Required Implementations -----------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+   
+   /**
+    * {@inheritDoc}
+    * @see org.apache.openejb.assembler.classic.ejb.EchoLocalBusiness#echo(java.lang.String)
+    */
+   @Override
+   public String echo(final String value)
+   {
+      return value;
+   }
+}

Added: shrinkwrap/trunk/extension-openejb/src/test/java/org/jboss/shrinkwrap/openejb/ejb/EchoLocalBusiness.java
===================================================================
--- shrinkwrap/trunk/extension-openejb/src/test/java/org/jboss/shrinkwrap/openejb/ejb/EchoLocalBusiness.java	                        (rev 0)
+++ shrinkwrap/trunk/extension-openejb/src/test/java/org/jboss/shrinkwrap/openejb/ejb/EchoLocalBusiness.java	2010-02-07 03:30:07 UTC (rev 3993)
@@ -0,0 +1,33 @@
+/**
+ * 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.
+ */
+package org.jboss.shrinkwrap.openejb.ejb;
+
+/**
+ * Local business interface of an EJB which echos a sent message
+ * 
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface EchoLocalBusiness
+{
+   /**
+    * Returns the specified reference unaltered
+    * @param value
+    * @return
+    */
+   String echo(String value);
+}

Added: shrinkwrap/trunk/extension-openejb/src/test/java/org/jboss/shrinkwrap/openejb/test/ShrinkWrapArchiveDeploymentTest.java
===================================================================
--- shrinkwrap/trunk/extension-openejb/src/test/java/org/jboss/shrinkwrap/openejb/test/ShrinkWrapArchiveDeploymentTest.java	                        (rev 0)
+++ shrinkwrap/trunk/extension-openejb/src/test/java/org/jboss/shrinkwrap/openejb/test/ShrinkWrapArchiveDeploymentTest.java	2010-02-07 03:30:07 UTC (rev 3993)
@@ -0,0 +1,132 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.shrinkwrap.openejb.test;
+
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import junit.framework.TestCase;
+
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.SecurityServiceInfo;
+import org.apache.openejb.assembler.classic.TransactionServiceInfo;
+import org.apache.openejb.client.LocalInitialContextFactory;
+import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.util.LogCategory;
+import org.apache.openejb.util.Logger;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.openejb.config.ShrinkWrapConfigurationFactory;
+import org.jboss.shrinkwrap.openejb.ejb.EchoBean;
+import org.jboss.shrinkwrap.openejb.ejb.EchoLocalBusiness;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Ensures that {@link Archive} types may be deployed into 
+ * the container via an {@link AppInfo} descriptor created
+ * by the {@link ConfigurationFactory}
+ * 
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ShrinkWrapArchiveDeploymentTest
+{
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP_CONFIG,
+         ShrinkWrapArchiveDeploymentTest.class);
+
+   //-------------------------------------------------------------------------------------||
+   // Tests ------------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Ensures that an archive can be deployed, accessed, and undeployed
+    * @throws Exception
+    */
+   @Test
+   public void shrinkWrapDeployment() throws Exception
+   {
+
+      // Create archive to hold our test EJB
+      final String name = "echo.jar";
+      final JavaArchive archive = Archives.create(name, JavaArchive.class).addClasses(EchoBean.class,
+            EchoLocalBusiness.class);
+      logger.info("Created archive: " + archive.toString(true));
+
+      // These two objects pretty much encompass all the EJB Container
+      final ShrinkWrapConfigurationFactory config = new ShrinkWrapConfigurationFactory();
+      final Assembler assembler = new Assembler();
+      assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+      assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+
+      // Deploy as an archive
+      final AppInfo appInfo = config.configureApplication(archive);
+      assembler.createApplication(appInfo);
+
+      // Get a JNDI Context
+      final Properties properties = new Properties();
+      properties.put(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
+      final Context ctx = new InitialContext(properties);
+
+      // Lookup
+      final EchoLocalBusiness bean = (EchoLocalBusiness) ctx.lookup(EchoBean.class.getSimpleName() + "Local");
+
+      // Invoke and test
+      final String request = "Word up";
+      final String response = bean.echo(request);
+      logger.info("Sent: \"" + request + "\"; got: \"" + response + "\"");
+      TestCase.assertEquals("Response from EJB invocation not expected", request, response);
+      TestCase.assertTrue("Response from local EJB invocation is equal by value but not by reference",
+            request == response);
+
+      // Undeploy the archive
+      assembler.destroyApplication(appInfo.jarPath);
+
+      // Try and execute the bean after it's been undeployed -- should fail
+      try
+      {
+         bean.echo(request);
+         Assert.fail("Proxy should no longer be valid");
+      }
+      catch (final Exception e)
+      {
+         // this should happen
+      }
+
+      try
+      {
+         ctx.lookup(EchoBean.class.getSimpleName());
+         Assert.fail("JNDI References should have been cleaned up");
+      }
+      catch (NamingException e)
+      {
+         // this also should happen
+      }
+   }
+}

Modified: shrinkwrap/trunk/pom.xml
===================================================================
--- shrinkwrap/trunk/pom.xml	2010-02-05 23:53:17 UTC (rev 3992)
+++ shrinkwrap/trunk/pom.xml	2010-02-07 03:30:07 UTC (rev 3993)
@@ -71,6 +71,7 @@
     <module>spi</module>
     <module>extension-glassfish</module>
     <module>extension-jetty</module>
+    <module>extension-openejb</module>
   </modules>
 
 </project>



More information about the jboss-svn-commits mailing list