[jboss-cvs] JBossAS SVN: r57585 - in branches/JEE5_TCK/ejb3: . src/main/org/jboss/ejb3/client src/main/org/jboss/ejb3/deployment src/main/org/jboss/ejb3/metamodel src/main/org/jboss/injection src/resources/test src/resources/test/appclient src/resources/test/dd src/test/org/jboss/ejb3/test src/test/org/jboss/ejb3/test/appclient src/test/org/jboss/ejb3/test/appclient/client src/test/org/jboss/ejb3/test/appclient/unit src/test/org/jboss/ejb3/test/dd/unit

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Oct 12 09:51:13 EDT 2006


Author: wolfc
Date: 2006-10-12 09:50:41 -0400 (Thu, 12 Oct 2006)
New Revision: 57585

Added:
   branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/metamodel/JBossClientDDObjectFactory.java
   branches/JEE5_TCK/ejb3/src/resources/test/appclient/
   branches/JEE5_TCK/ejb3/src/resources/test/appclient/Manifest
   branches/JEE5_TCK/ejb3/src/resources/test/appclient/application-client.xml
   branches/JEE5_TCK/ejb3/src/resources/test/appclient/application.xml
   branches/JEE5_TCK/ejb3/src/resources/test/appclient/jboss-client.xml
   branches/JEE5_TCK/ejb3/src/resources/test/dd/jboss-client-test1.xml
   branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/
   branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/HelloWorldBean.java
   branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/HelloWorldService.java
   branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/MessageReplierBean.java
   branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/client/
   branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/client/HelloWorldClient.java
   branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/unit/
   branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/unit/AppClientUnitTestCase.java
Modified:
   branches/JEE5_TCK/ejb3/build-test.xml
   branches/JEE5_TCK/ejb3/build.xml
   branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/client/ClientLauncher.java
   branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/deployment/EJB3ClientDeployer.java
   branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/metamodel/ApplicationClientDDObjectFactory.java
   branches/JEE5_TCK/ejb3/src/main/org/jboss/injection/InjectionUtil.java
   branches/JEE5_TCK/ejb3/src/main/org/jboss/injection/JndiFieldInjector.java
   branches/JEE5_TCK/ejb3/src/main/org/jboss/injection/ResourceHandler.java
   branches/JEE5_TCK/ejb3/src/resources/test/dd/application-client-test1.xml
   branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/dd/unit/ApplicationClientXmlTestCase.java
Log:
JBCTS-329: @Resource and jndi-name in jboss-client.xml

Modified: branches/JEE5_TCK/ejb3/build-test.xml
===================================================================
--- branches/JEE5_TCK/ejb3/build-test.xml	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/build-test.xml	2006-10-12 13:50:41 UTC (rev 57585)
@@ -706,6 +706,37 @@
       </jar>
    </target>
 
+   <target name="appclient"
+      description="Builds appclient-test.ear."
+      depends="compile-classes">
+      
+      <mkdir dir="${build.lib}"/>
+      
+      <jar jarfile="${build.lib}/appclient-test-client.jar" manifest="${resources}/test/appclient/Manifest">
+         <zipfileset prefix="META-INF" dir="${resources}/test/appclient">
+            <include name="application-client.xml"/>
+            <include name="jboss-client.xml"/>
+         </zipfileset>
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/ejb3/test/appclient/HelloWorldService.class"/>
+            <include name="org/jboss/ejb3/test/appclient/client/HelloWorldClient.class"/>
+         </fileset>
+      </jar>
+      
+      <jar jarfile="${build.lib}/appclient-test.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/ejb3/test/appclient/*.class"/>
+         </fileset>
+      </jar>
+      
+      <ear appxml="${resources}/test/appclient/application.xml" earfile="${build.lib}/appclient-test.ear">
+         <fileset dir="${build.lib}">
+            <include name="appclient-test-client.jar"/>
+            <include name="appclient-test.jar"/>
+         </fileset>
+      </ear>
+   </target>
+   
    <target name="asynchronous"
       description="Builds all jar files."
       depends="compile-classes">

Modified: branches/JEE5_TCK/ejb3/build.xml
===================================================================
--- branches/JEE5_TCK/ejb3/build.xml	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/build.xml	2006-10-12 13:50:41 UTC (rev 57585)
@@ -401,7 +401,9 @@
             <include name="org/jboss/ejb3/naming/client/**/*.class"/>
             <include name="org/jboss/ejb3/naming/BrainlessContext.class"/>
          	
+            <!-- EJBTHREE-718: client container -->
          	<include name="org/jboss/ejb3/client/**/*.class"/>
+         	<include name="org/jboss/ejb3/metamodel/**/*.class"/>
          	<include name="org/jboss/injection/**/*.class"/>
          	<include name="org/jboss/ejb3/ThreadLocalENCFactory.class"/>
          </fileset>

Modified: branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/client/ClientLauncher.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/client/ClientLauncher.java	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/client/ClientLauncher.java	2006-10-12 13:50:41 UTC (rev 57585)
@@ -21,38 +21,53 @@
  */
 package org.jboss.ejb3.client;
 
+import java.io.IOException;
 import java.net.URL;
+import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.List;
 
 import org.jboss.ejb3.metamodel.ApplicationClientDD;
 import org.jboss.ejb3.metamodel.ApplicationClientDDObjectFactory;
+import org.jboss.ejb3.metamodel.JBossClientDDObjectFactory;
+import org.jboss.xb.binding.JBossXBException;
 
 /**
  * This class launches a JavaEE 5 application client.
  * 
- * The first argument is either a jar file containing the client deployment files or a the application client class name.
+ * The first argument is either a jar file containing the client deployment files or the application client class name.
  * The manifest file Main-Class attribute must point to the application client class.
- * It may also contain an application client deployment descriptor file (META-INF/application-client.xml).
+ * It must also contain an application client deployment descriptor file (META-INF/application-client.xml).
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
  * @version $Revision: $
  */
 public class ClientLauncher
 {
+   private static URL findResource(String resourceName)
+   {
+      URL url;
+      if(Thread.currentThread().getContextClassLoader() instanceof URLClassLoader)
+         url = ((URLClassLoader) Thread.currentThread().getContextClassLoader()).findResource("META-INF/application-client.xml");
+      else
+         url = Thread.currentThread().getContextClassLoader().getResource("META-INF/application-client.xml");
+      return url;
+   }
+   
    /**
     * Convenience method for launching a client container.
     * 
+    * @param xml
     * @param mainClassName
     * @param applicationClientName
     * @param args
     * @throws Exception
     */
-   public static void launch(String mainClassName, String applicationClientName, String args[]) throws Exception
+   public static void launch(ApplicationClientDD xml, String mainClassName, String applicationClientName, String args[]) throws Exception
    {
       Class mainClass = Class.forName(mainClassName);
       
-      ClientContainer container = new ClientContainer(mainClass, applicationClientName);
+      ClientContainer container = new ClientContainer(xml, mainClass, applicationClientName);
       
       // TODO: postContruct
       
@@ -62,6 +77,50 @@
    }
    
    /**
+    * Convenience method for launching a client container.
+    * 
+    * @param mainClassName
+    * @param applicationClientName
+    * @param args
+    * @throws Exception
+    */
+   public static void launch(String mainClassName, String applicationClientName, String args[]) throws Exception
+   {
+      ApplicationClientDD xml = loadXML();
+      launch(xml, mainClassName, applicationClientName, args);
+   }
+   
+   /**
+    * Convenience method to load the XML descriptor.
+    * 
+    * @return
+    * @throws IOException 
+    * @throws JBossXBException 
+    */
+   public static ApplicationClientDD loadXML() throws JBossXBException, IOException
+   {
+      URL url = findResource("META-INF/application-client.xml");
+      URL jbossClientURL = findResource("META-INF/jboss-client.xml");
+      return loadXML(url, jbossClientURL);
+   }
+   
+   @Deprecated
+   public static ApplicationClientDD loadXML(String urlSpec) throws JBossXBException, IOException
+   {
+      URL url = new URL(urlSpec);
+      return loadXML(url, null);
+   }
+   
+   public static ApplicationClientDD loadXML(URL url, URL jbossClientURL) throws JBossXBException, IOException
+   {
+      ApplicationClientDD dd = ApplicationClientDDObjectFactory.parse(url);
+      dd = JBossClientDDObjectFactory.parse(jbossClientURL, dd);
+      return dd;
+   }
+   
+   /**
+    * Work in progress.
+    * 
     * @param args   the arguments for the launcher
     */
    public static void main(String[] args)
@@ -92,7 +151,6 @@
          ApplicationClientDD xml = ApplicationClientDDObjectFactory.parse(appXmlURL);
          
          // FIXME: j2ee.clientName
-         ClientContainer container = new ClientContainer(xml, mainClass, "FIXME");
          
          List<String> newArgs = new ArrayList<String>();
          for(int i = 1; i < args.length; i++)
@@ -101,11 +159,9 @@
          }
          args = newArgs.toArray(args);
          
-         // TODO: postContruct
-         
-         container.invokeMain(args);
-         
-         // TODO: preDestroy
+         // FIXME: when jar gets implemented this won't work anymore
+         String mainClassName = name;
+         launch(xml, mainClassName, "FIXME", args);
       }
       catch (Exception e)
       {

Modified: branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/deployment/EJB3ClientDeployer.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/deployment/EJB3ClientDeployer.java	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/deployment/EJB3ClientDeployer.java	2006-10-12 13:50:41 UTC (rev 57585)
@@ -40,7 +40,7 @@
 import org.jboss.ejb3.clientmodule.ClientENCInjectionContainer;
 import org.jboss.ejb3.metamodel.ApplicationClientDD;
 import org.jboss.ejb3.metamodel.ApplicationClientDDObjectFactory;
-import org.jboss.metadata.MetaData;
+import org.jboss.ejb3.metamodel.JBossClientDDObjectFactory;
 import org.jboss.metadata.XmlFileLoader;
 import org.jboss.naming.Util;
 import org.w3c.dom.Element;
@@ -201,22 +201,23 @@
          
          // Look for a jboss-client.xml descriptor
          URL jbossClientURL = di.localCl.findResource("META-INF/jboss-client.xml");
-         if(jbossClientURL != null)
-         {
-            InputStream in = jbossClientURL.openStream();
-            try
-            {
-               XmlFileLoader xfl = new XmlFileLoader(true);
-               Element jbossClient = xfl.getDocument(in, "META-INF/jboss-client.xml").getDocumentElement();
-               
-               String jndiName = MetaData.getOptionalChildContent(jbossClient, "jndi-name");
-               xml.setJndiName(jndiName);
-            }
-            finally
-            {
-               in.close();
-            }
-         }
+         xml = JBossClientDDObjectFactory.parse(jbossClientURL, xml);
+//         if(jbossClientURL != null)
+//         {
+//            InputStream in = jbossClientURL.openStream();
+//            try
+//            {
+//               XmlFileLoader xfl = new XmlFileLoader(true);
+//               Element jbossClient = xfl.getDocument(in, "META-INF/jboss-client.xml").getDocumentElement();
+//               
+//               String jndiName = MetaData.getOptionalChildContent(jbossClient, "jndi-name");
+//               xml.setJndiName(jndiName);
+//            }
+//            finally
+//            {
+//               in.close();
+//            }
+//         }
          
          di.metaData = xml;
          

Modified: branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/metamodel/ApplicationClientDDObjectFactory.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/metamodel/ApplicationClientDDObjectFactory.java	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/metamodel/ApplicationClientDDObjectFactory.java	2006-10-12 13:50:41 UTC (rev 57585)
@@ -26,7 +26,12 @@
 
 import org.jboss.logging.Logger;
 import org.jboss.metamodel.descriptor.DDObjectFactory;
+import org.jboss.metamodel.descriptor.EjbRef;
 import org.jboss.metamodel.descriptor.EnvEntry;
+import org.jboss.metamodel.descriptor.MessageDestinationRef;
+import org.jboss.metamodel.descriptor.PersistenceUnitRef;
+import org.jboss.metamodel.descriptor.ResourceEnvRef;
+import org.jboss.metamodel.descriptor.ResourceRef;
 import org.jboss.util.xml.JBossEntityResolver;
 import org.jboss.xb.binding.JBossXBException;
 import org.jboss.xb.binding.Unmarshaller;
@@ -70,9 +75,11 @@
       return dd;
    }
    
-   /**
-    * Called when parsing character is complete.
-    */
+   public void addChild(ApplicationClientDD parent, EjbRef ref, UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEjbRef(ref);
+   }
+   
    public void addChild(ApplicationClientDD parent, EnvEntry entry, UnmarshallingContext navigator, String namespaceURI, String localName)
    {
       parent.addEnvEntry(entry);
@@ -88,6 +95,26 @@
          throw new IllegalArgumentException(localName);
    }
    
+   public void addChild(ApplicationClientDD parent, MessageDestinationRef ref, UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addMessageDestinationRef(ref);
+   }
+
+   public void addChild(ApplicationClientDD parent, PersistenceUnitRef ref, UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addPersistenceUnitRef(ref);
+   }
+
+   public void addChild(ApplicationClientDD parent, ResourceEnvRef envRef, UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addResourceEnvRef(envRef);
+   }
+   
+   public void addChild(ApplicationClientDD parent, ResourceRef ref, UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addResourceRef(ref);
+   }
+
    public Object completeRoot(Object root, UnmarshallingContext ctx, String uri, String name)
    {
       throw new RuntimeException("NYI");

Added: branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/metamodel/JBossClientDDObjectFactory.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/metamodel/JBossClientDDObjectFactory.java	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/metamodel/JBossClientDDObjectFactory.java	2006-10-12 13:50:41 UTC (rev 57585)
@@ -0,0 +1,127 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.ejb3.metamodel;
+
+import java.io.IOException;
+import java.net.URL;
+
+import org.jboss.logging.Logger;
+import org.jboss.metamodel.descriptor.DDObjectFactory;
+import org.jboss.metamodel.descriptor.EjbRef;
+import org.jboss.metamodel.descriptor.MessageDestinationRef;
+import org.jboss.metamodel.descriptor.ResourceEnvRef;
+import org.jboss.metamodel.descriptor.ResourceRef;
+import org.jboss.util.xml.JBossEntityResolver;
+import org.jboss.xb.binding.JBossXBException;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.UnmarshallingContext;
+import org.xml.sax.Attributes;
+
+/**
+ * A JBossXB object factory for parsing JBoss application client descriptor files.
+ * 
+ * http://www.jboss.org/j2ee/dtd/jboss-client_5_0.dtd
+ * 
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class JBossClientDDObjectFactory extends DDObjectFactory
+{
+   private static final Logger log = Logger.getLogger(JBossClientDDObjectFactory.class);
+   
+   private ApplicationClientDD dd;
+   
+   public static ApplicationClientDD parse(URL ddResource, ApplicationClientDD dd)
+      throws JBossXBException, IOException
+   {
+      if(ddResource == null)
+         return dd;
+      
+      log.debug("found jboss-client.xml " + ddResource);
+      
+      JBossClientDDObjectFactory factory = new JBossClientDDObjectFactory(dd);
+      UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance();
+      unmarshallerFactory.setFeature(Unmarshaller.SCHEMA_VALIDATION, true);
+      Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
+      JBossEntityResolver entityResolver = new JBossEntityResolver();
+      unmarshaller.setEntityResolver(entityResolver);
+
+      dd = (ApplicationClientDD) unmarshaller.unmarshal(ddResource.openStream(), factory, null);
+      
+      return dd;
+   }
+   
+   private JBossClientDDObjectFactory(ApplicationClientDD dd)
+   {
+      this.dd = dd;
+   }
+   
+   public void addChild(ApplicationClientDD parent, EjbRef ref, UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      dd.updateEjbRef(ref);
+   }
+   
+   public void addChild(ApplicationClientDD parent, MessageDestinationRef ref, UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      dd.updateMessageDestinationRef(ref);
+   }
+
+   public void addChild(ApplicationClientDD dd, ResourceEnvRef envRef, UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      dd.updateResourceEnvRef(envRef);
+   }
+   
+   public void addChild(ApplicationClientDD parent, ResourceRef ref, UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      dd.updateResourceRef(ref);
+   }
+   
+   public Object completeRoot(Object root, UnmarshallingContext navigator, String uri, String name)
+   {
+      return root;
+   }
+
+   public Object newChild(ApplicationClientDD dd, UnmarshallingContext navigator, String namespaceURI, String localName, Attributes attrs)
+   {
+      Object child = null;
+      
+      child = newEnvRefGroupChild(localName);
+      if(child != null)
+         return child;
+      
+      // space for more
+      
+      return child;
+   }
+   
+   public Object newRoot(Object root, UnmarshallingContext navigator, String namespaceURI, String localName, Attributes attrs)
+   {
+      return dd;
+   }
+
+   public void setValue(ApplicationClientDD dd, UnmarshallingContext navigator, String namespaceURI, String localName, String value)
+   {
+      if(localName.equals("jndi-name"))
+         dd.setJndiName(value);
+   }
+}

Modified: branches/JEE5_TCK/ejb3/src/main/org/jboss/injection/InjectionUtil.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/injection/InjectionUtil.java	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/injection/InjectionUtil.java	2006-10-12 13:50:41 UTC (rev 57585)
@@ -131,6 +131,7 @@
          Field[] fields = clazz.getDeclaredFields();
          for (Field field : fields)
          {
+            log.trace("process field annotation for " + field.toGenericString());
             for (InjectionHandler handler : handlers)
             {
                handler.handleFieldAnnotations(field, container, classInjectors);

Modified: branches/JEE5_TCK/ejb3/src/main/org/jboss/injection/JndiFieldInjector.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/injection/JndiFieldInjector.java	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/injection/JndiFieldInjector.java	2006-10-12 13:50:41 UTC (rev 57585)
@@ -139,4 +139,9 @@
          throw new RuntimeException(e);
       }
    }
+   
+   public String toString()
+   {
+      return super.toString() + "{field=" + field + ",jndiName=" + jndiName + "}";
+   }
 }

Modified: branches/JEE5_TCK/ejb3/src/main/org/jboss/injection/ResourceHandler.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/injection/ResourceHandler.java	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/injection/ResourceHandler.java	2006-10-12 13:50:41 UTC (rev 57585)
@@ -57,6 +57,7 @@
          String encName = "env/" + envEntry.getEnvEntryName();
          InjectionUtil.injectionTarget(encName, envEntry, container, container.getEncInjections());
          if (container.getEncInjectors().containsKey(encName)) continue;
+         log.trace("adding env-entry injector " + encName);
          container.getEncInjectors().put(encName, new EnvEntryEncInjector(encName, envEntry.getEnvEntryType(), envEntry.getEnvEntryValue()));
       }
    }
@@ -245,6 +246,8 @@
       Resource ref = field.getAnnotation(Resource.class);
       if (ref == null) return;
 
+      log.trace("field " + field + " has @Resource");
+      
       String encName = ref.name();
       if (encName == null || encName.equals(""))
       {
@@ -288,10 +291,15 @@
       {
 
          // don't add an injector if no XML <env-entry is present as there will be no value to inject
+         // Wolf: Why? I've said @Resource, so I want an injection
          if (container.getEncInjectors().containsKey(encName))
          {
             injectors.put(field, new JndiFieldInjector(field, encName, container.getEnc()));
          }
+         else
+         {
+            log.warn("Not injecting " + field.getName() + ", no matching enc injector " + encName + " found");
+         }
       }
       else
       {
@@ -300,7 +308,7 @@
             String mappedName = ref.mappedName();
             if (mappedName == null || mappedName.equals(""))
             {
-              throw new RuntimeException("You did not specify a @Resource.mappedName() on " + field + " and there is no binding for that enc name in XML");
+              throw new RuntimeException("You did not specify a @Resource.mappedName() on " + field + " and there is no binding for enc name " + encName + " in XML");
             }
             container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, ref.mappedName(), "@Resource"));
          }

Added: branches/JEE5_TCK/ejb3/src/resources/test/appclient/Manifest
===================================================================
--- branches/JEE5_TCK/ejb3/src/resources/test/appclient/Manifest	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/src/resources/test/appclient/Manifest	2006-10-12 13:50:41 UTC (rev 57585)
@@ -0,0 +1 @@
+Main-Class: org.jboss.ejb3.test.appclient.client.HelloWorldClient
\ No newline at end of file

Added: branches/JEE5_TCK/ejb3/src/resources/test/appclient/application-client.xml
===================================================================
--- branches/JEE5_TCK/ejb3/src/resources/test/appclient/application-client.xml	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/src/resources/test/appclient/application-client.xml	2006-10-12 13:50:41 UTC (rev 57585)
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<application-client 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/j2ee
+                    http://java.sun.com/xml/ns/javaee/application-client_5.xsd"
+                    version="5">
+	<display-name>appclient-test-client</display-name>
+	<description>application client unit test</description>
+
+	<env-entry>
+		<env-entry-name>msg</env-entry-name>
+		<env-entry-type>java.lang.String</env-entry-type>
+		<env-entry-value>how are you?</env-entry-value>
+	</env-entry>
+	
+	<resource-env-ref>
+		<resource-env-ref-name>messageReplier</resource-env-ref-name>
+		<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
+	</resource-env-ref>
+	
+	<post-construct>
+		<lifecycle-callback-method>postConstruct</lifecycle-callback-method>
+	</post-construct>
+	
+	<pre-destroy>
+		<lifecycle-callback-method>preDestroy</lifecycle-callback-method>
+	</pre-destroy>
+	
+	<callback-handler>org.jboss.ejb3.test.applicationclient.client.TestCallbackHandler</callback-handler>
+</application-client>

Added: branches/JEE5_TCK/ejb3/src/resources/test/appclient/application.xml
===================================================================
--- branches/JEE5_TCK/ejb3/src/resources/test/appclient/application.xml	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/src/resources/test/appclient/application.xml	2006-10-12 13:50:41 UTC (rev 57585)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE application PUBLIC
+   "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
+   "http://java.sun.com/dtd/application_1_3.dtd">
+
+<application>
+   <display-name>EJB3 appclient test</display-name>
+
+   <module>
+      <ejb>appclient-test.jar</ejb>
+   </module>
+   <module>
+      <java>appclient-test-client.jar</java>
+   </module>
+</application>

Added: branches/JEE5_TCK/ejb3/src/resources/test/appclient/jboss-client.xml
===================================================================
--- branches/JEE5_TCK/ejb3/src/resources/test/appclient/jboss-client.xml	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/src/resources/test/appclient/jboss-client.xml	2006-10-12 13:50:41 UTC (rev 57585)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE jboss-client PUBLIC "-//JBoss//DTD Application Client 5.0//EN" "http://www.jboss.org/j2ee/dtd/jboss-client_5_0.dtd">
+
+<jboss-client>
+   <jndi-name>applicationclient_test</jndi-name>
+   
+   <resource-env-ref>
+      <resource-env-ref-name>messageReplier</resource-env-ref-name>
+      <jndi-name>queue/messageReplier</jndi-name>
+   </resource-env-ref>
+</jboss-client>

Modified: branches/JEE5_TCK/ejb3/src/resources/test/dd/application-client-test1.xml
===================================================================
--- branches/JEE5_TCK/ejb3/src/resources/test/dd/application-client-test1.xml	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/src/resources/test/dd/application-client-test1.xml	2006-10-12 13:50:41 UTC (rev 57585)
@@ -13,6 +13,11 @@
 		<env-entry-value>Hello world</env-entry-value>
 	</env-entry>
 	
+	<resource-env-ref>
+		<resource-env-ref-name>messageReplier</resource-env-ref-name>
+		<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
+	</resource-env-ref>
+	
 	<post-construct>
 		<lifecycle-callback-method>postConstruct</lifecycle-callback-method>
 	</post-construct>

Added: branches/JEE5_TCK/ejb3/src/resources/test/dd/jboss-client-test1.xml
===================================================================
--- branches/JEE5_TCK/ejb3/src/resources/test/dd/jboss-client-test1.xml	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/src/resources/test/dd/jboss-client-test1.xml	2006-10-12 13:50:41 UTC (rev 57585)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE jboss-client PUBLIC "-//JBoss//DTD Application Client 5.0//EN" "http://www.jboss.org/j2ee/dtd/jboss-client_5_0.dtd">
+
+<jboss-client>
+   <jndi-name>dd_test</jndi-name>
+   
+   <resource-env-ref>
+      <resource-env-ref-name>messageReplier</resource-env-ref-name>
+      <jndi-name>queue/messageReplier</jndi-name>
+   </resource-env-ref>
+</jboss-client>

Added: branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/HelloWorldBean.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/HelloWorldBean.java	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/HelloWorldBean.java	2006-10-12 13:50:41 UTC (rev 57585)
@@ -0,0 +1,41 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.ejb3.test.appclient;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Remote(HelloWorldService.class)
+public class HelloWorldBean implements HelloWorldService
+{
+   public String sayHelloTo(String name)
+   {
+      return "Hi " + name;
+   }
+}

Added: branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/HelloWorldService.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/HelloWorldService.java	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/HelloWorldService.java	2006-10-12 13:50:41 UTC (rev 57585)
@@ -0,0 +1,33 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.ejb3.test.appclient;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface HelloWorldService
+{
+   String sayHelloTo(String name);
+}

Added: branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/MessageReplierBean.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/MessageReplierBean.java	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/MessageReplierBean.java	2006-10-12 13:50:41 UTC (rev 57585)
@@ -0,0 +1,86 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.ejb3.test.appclient;
+
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.EJBException;
+import javax.ejb.MessageDriven;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+
+import org.jboss.logging.Logger;
+
+/**
+ * This message bean will just reply the message.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at MessageDriven(activationConfig = {
+   @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
+   @ActivationConfigProperty(propertyName="destination", propertyValue="queue/messageReplier")
+})
+public class MessageReplierBean implements MessageListener
+{
+   private static final Logger log = Logger.getLogger(MessageReplierBean.class);
+   
+   @Resource(mappedName="java:ConnectionFactory")
+   private ConnectionFactory connectionFactory;
+   
+   public void onMessage(Message message)
+   {
+      try
+      {
+         if(message.getJMSReplyTo() != null)
+         {
+            Destination destination = message.getJMSReplyTo();
+            
+            Connection conn = connectionFactory.createConnection();
+            try
+            {
+               Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+               MessageProducer producer = session.createProducer(destination);
+               producer.send(destination, message);
+               producer.close();
+               session.close();
+            }
+            finally
+            {
+               conn.close();
+            }
+         }
+         else
+            log.info("no reply to specified");
+      }
+      catch(JMSException e)
+      {
+         throw new EJBException(e);
+      }
+   }
+}

Added: branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/client/HelloWorldClient.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/client/HelloWorldClient.java	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/client/HelloWorldClient.java	2006-10-12 13:50:41 UTC (rev 57585)
@@ -0,0 +1,117 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.ejb3.test.appclient.client;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.jboss.ejb3.test.appclient.HelloWorldService;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class HelloWorldClient
+{
+   @EJB
+   private static HelloWorldService helloWorldService;
+   
+   @Resource(name="msg")
+   private static String msg;
+   
+   private static String result;
+   
+   @Resource(mappedName="ConnectionFactory")
+   private static ConnectionFactory connectionFactory;
+   
+   @Resource(name="messageReplier")
+   private static Destination destination;
+   
+   public static String getResult()
+   {
+      return result;
+   }
+   
+   public static void main(String args[])
+   {
+      String name = "unspecified";
+      if(args.length > 0)
+         name = args[0];
+      
+      if(helloWorldService == null)
+         throw new NullPointerException("helloWorldService is null");
+      
+      if(msg == null)
+         throw new NullPointerException("msg is null");
+      
+      result = helloWorldService.sayHelloTo(name) + ", " + msg;
+      
+      testMDB();
+   }
+   
+   public static void testMDB()
+   {
+      if(connectionFactory == null)
+         throw new NullPointerException("connectionFactory is null");
+      
+      if(destination == null)
+         throw new NullPointerException("destination is null");
+      
+      try
+      {
+         Connection conn = connectionFactory.createConnection();
+         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         
+         Queue replyTo = session.createTemporaryQueue();
+         TextMessage msg = session.createTextMessage("Hello world");
+         msg.setJMSReplyTo(replyTo);
+         
+         MessageConsumer consumer = session.createConsumer(replyTo);
+         conn.start();
+         
+         MessageProducer producer = session.createProducer(destination);
+         producer.send(destination, msg);
+         
+         TextMessage reply = (TextMessage) consumer.receive(2000);
+         System.out.println("reply = " + reply.getText());
+         
+         producer.close();
+         conn.stop();
+         consumer.close();
+         session.close();
+      }
+      catch(Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+}

Added: branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/unit/AppClientUnitTestCase.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/unit/AppClientUnitTestCase.java	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/appclient/unit/AppClientUnitTestCase.java	2006-10-12 13:50:41 UTC (rev 57585)
@@ -0,0 +1,69 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.ejb3.test.appclient.unit;
+
+import java.net.URL;
+import java.util.Date;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.client.ClientLauncher;
+import org.jboss.ejb3.metamodel.ApplicationClientDD;
+import org.jboss.ejb3.test.appclient.client.HelloWorldClient;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class AppClientUnitTestCase extends JBossTestCase
+{
+   public AppClientUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void test1() throws Exception
+   {
+      URL url = Thread.currentThread().getContextClassLoader().getResource("appclient/application-client.xml");
+      URL jbossClientURL = Thread.currentThread().getContextClassLoader().getResource("appclient/jboss-client.xml");
+      ApplicationClientDD xml = ClientLauncher.loadXML(url, jbossClientURL);
+      
+      String mainClassName = HelloWorldClient.class.getName();
+      String applicationClientName = "applicationclient_test"; // must match JNDI name in jboss-client.xml or display-name in application-client.xml
+      String name = new Date().toString();
+      String args[] = { name };
+      
+      ClientLauncher.launch(xml, mainClassName, applicationClientName, args);
+      
+      String actual = HelloWorldClient.getResult();
+      String expected = "Hi " + name + ", how are you?";
+      assertEquals(expected, actual);
+   }
+   
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(AppClientUnitTestCase.class, "appclient-test.ear");
+   }
+}

Modified: branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/dd/unit/ApplicationClientXmlTestCase.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/dd/unit/ApplicationClientXmlTestCase.java	2006-10-12 13:50:24 UTC (rev 57584)
+++ branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/dd/unit/ApplicationClientXmlTestCase.java	2006-10-12 13:50:41 UTC (rev 57585)
@@ -30,8 +30,10 @@
 
 import org.jboss.ejb3.metamodel.ApplicationClientDD;
 import org.jboss.ejb3.metamodel.ApplicationClientDDObjectFactory;
+import org.jboss.ejb3.metamodel.JBossClientDDObjectFactory;
 import org.jboss.ejb3.metamodel.LifecycleCallback;
 import org.jboss.metamodel.descriptor.EnvEntry;
+import org.jboss.metamodel.descriptor.ResourceEnvRef;
 
 /**
  * Comment
@@ -48,6 +50,10 @@
       ApplicationClientDD dd = ApplicationClientDDObjectFactory.parse(xmlUrl);
       assertNotNull(dd);
       
+      URL jbossClientURL = getResourceUrl("dd/jboss-client-test1.xml");
+      assertNotNull(jbossClientURL);
+      dd = JBossClientDDObjectFactory.parse(jbossClientURL, dd);
+      
       assertEquals("Test1", dd.getDisplayName());
       //assertEquals("application client dd test", dd.getDescription());
       
@@ -62,6 +68,15 @@
          assertEquals("Hello world", ee.getEnvEntryValue());
       }
       
+      assertEquals(1, dd.getResourceEnvRefs().size());
+      
+      {
+         Iterator<ResourceEnvRef> i = dd.getResourceEnvRefs().iterator();
+         
+         ResourceEnvRef rer = i.next();
+         System.out.println(rer);
+      }
+      
       assertEquals(1, dd.getPostConstructs().size());
       
       {




More information about the jboss-cvs-commits mailing list