5 Replies Latest reply on Jul 7, 2009 12:43 PM by rangalo

    EJB client with DI - @EJB injection doesn't work

    rangalo
      I am using glassfish V3 container. I have deployed a very simple stateful EJB which is accessible by a client which uses global jndi lookup. But it is not accessible using the @EJB (DI) method. Also the commandline described in glassfish documentation and other books is also not working for running the client in the ACC (Application client container). Here the Client code: [code] package com.hardik.mejb; import javax.ejb.EJB; public class CountClientAcc {            @EJB      public static Count count;            public static void main(String[] args) {           try {                count.set(10);                System.out.println("Count is: "+ count.count());                           } catch (Exception e) {                e.printStackTrace();           }      } }[/code] The bean is code is like following: [code]package com.hardik.mejb; import javax.ejb.Remote; import javax.ejb.Remove; import javax.ejb.Stateful; import javax.interceptor.Interceptors; @Stateful @Remote(Count.class) @Interceptors(CountCallBacks.class) public class CountBean implements Count {            /**       * Current counter is our conversational state       */      private int val;      @Override      public int count() {           System.out.println("count():");           return ++val;      }      /**       * The remove method is annotated so the container knows,       * it can remove the bean after this method is called.       */      @Override      @Remove      public void remove() {           System.out.println("remove():");      }      @Override      public void set(int val) {           this.val = val;           System.out.println("set():");      } } [/code] After deploying the bean in the container. I tried following commandlines to run the client. 1. This is described in  glassfish documentation and other online material. [code] $ appclient -client count-client-acc.jar java.lang.IllegalArgumentException: URI scheme is not "file"         at java.io.File.<init>(File.java:366)         at com.sun.enterprise.deployment.util.ConnectorAnnotationDetector.hasAnnotationInArchive(ConnectorAnnotationDetector.java:65)         at com.sun.enterprise.deployment.archivist.ConnectorArchivist.postHandles(ConnectorArchivist.java:116)         at com.sun.enterprise.deployment.archivist.ArchivistFactory.getPrivateArchivistFor(ArchivistFactory.java:165)         at com.sun.enterprise.deployment.archivist.ArchivistFactory.getPrivateArchivistFor(ArchivistFactory.java:131)         at com.sun.enterprise.deployment.archivist.ArchivistFactory.getArchivist(ArchivistFactory.java:79)         at org.glassfish.appclient.client.acc.UndeployedLaunchable.newUndeployedLaunchable(UndeployedLaunchable.java:84)         at org.glassfish.appclient.client.acc.Launchable$LauchableUtil.newLaunchable(Launchable.java:114)         at org.glassfish.appclient.client.acc.AppClientContainerBuilder.newContainer(AppClientContainerBuilder.java:161)         at org.glassfish.appclient.client.acc.agent.AppClientContainerAgent.createContainerForAppClientArchiveOrDir(AppClientContainerAgent.java:407)         at org.glassfish.appclient.client.acc.agent.AppClientContainerAgent.createContainer(AppClientContainerAgent.java:377)         at org.glassfish.appclient.client.acc.agent.AppClientContainerAgent.premain(AppClientContainerAgent.java:225)         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)         at java.lang.reflect.Method.invoke(Method.java:597)         at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:323)         at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:338)[/code] 2.  This works for me when I run the jndi lookup client. [code]$ appclient -client -cp "../../CountBean/dist/count-bean.jar:count-client-acc.jar" com.hardik.mejb.CountClientAcc Jul 6, 2009 3:58:10 PM com.sun.enterprise.security.appclient.AppClientSecurityInfoImpl initializeSecurity INFO: acc.secmgroff java.lang.NullPointerException         at com.hardik.mejb.CountClientAcc.main(Unknown Source) [/code] Am I making some mistake ? Message was edited by: rangalo
        • 1. Re: EJB client with DI - @EJB injection doesn't work
          Tim Quinn-Oracle
          What build of GlassFish v3 are you using? You are probably running into Issue 8631. https://glassfish.dev.java.net/issues/show_bug.cgi?id=8631 If you think it's something else please let us know. It should not be necessary, but you could deploy your app client and retrieve the generated artifacts and run those instead: mkdir download asadmin deploy --retrieve download count-client-acc.jar appclient -client download/count-client-accClient.jar Note carefully the name of the file you'd launch - it has an extra "Client" inserted, a carryover for compatibility with v2. I know it's cumbersome to deploy the client if you don't need to otherwise, but until the issue is fixed this might be an annoying but effective workaround for you. Please let us know what you find. - Tim
          • 2. RE: EJB client with DI - @EJB injection doesn't work
            392 Guest
            Any reason why you would'nt want to deploy as EAR with EJBDeployer? Here is a quick primer on creating EAR (with EJBDeployer) for Glassfish http://weblogs.java.net/blog/bleonard/archive/2006/06/running_jboss_s_1.html Regards Martin ______________________________________________ Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen. Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni. > Date: Mon, 6 Jul 2009 07:16:41 -0700 > From: glassfish@javadesktop.org > To: users@glassfish.dev.java.net > Subject: Re: EJB client with DI - @EJB injection doesn't work > > What build of GlassFish v3 are you using? > > You are probably running into Issue 8631. > > https://glassfish.dev.java.net/issues/show_bug.cgi?id=8631 > > If you think it's something else please let us know. > > It should not be necessary, but you could deploy your app client and retrieve the generated artifacts and run those instead: > > mkdir download > asadmin deploy --retrieve download count-client-acc.jar > appclient -client download/count-client-accClient.jar > > Note carefully the name of the file you'd launch - it has an extra "Client" inserted, a carryover for compatibility with v2. > > I know it's cumbersome to deploy the client if you don't need to otherwise, but until the issue is fixed this might be an annoying but effective workaround for you. > > Please let us know what you find. > > - Tim > [Message sent by forum member 'tjquinn' (tjquinn)] > > http://forums.java.net/jive/thread.jspa?messageID=354238 > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net > For additional commands, e-mail: users-help@glassfish.dev.java.net > _________________________________________________________________ Insert movie times and more without leaving Hotmail®. http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tutorial_QuickAdd_062009 [att1.html]
            • 3. Re: EJB client with DI - @EJB injection doesn't work
              rangalo
              Thanks for the reply. I tried the retrieve command. I could retrieve the jar file in the download folder, but while executing  I get following exception. It cannot find the Count interface. [code] $ appclient -client download/count-client-accClient.jar Jul 7, 2009 10:46:17 AM com.sun.enterprise.security.appclient.AppClientSecurityInfoImpl initializeSecurity INFO: acc.secmgroff java.lang.reflect.InvocationTargetException         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)         at java.lang.reflect.Method.invoke(Method.java:597)         at org.glassfish.appclient.client.acc.AppClientContainer.launch(AppClientContainer.java:360)         at org.glassfish.appclient.client.AppClientFacade.main(AppClientFacade.java:59) Caused by: java.lang.NoClassDefFoundError: com/hardik/mejb/Count         at com.hardik.mejb.CountClientAcc.main(Unknown Source)         ... 6 more Caused by: java.lang.ClassNotFoundException: com.hardik.mejb.Count         at java.net.URLClassLoader$1.run(URLClassLoader.java:200)         at java.security.AccessController.doPrivileged(Native Method)         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)         at java.lang.ClassLoader.loadClass(ClassLoader.java:307)         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)         at java.lang.ClassLoader.loadClass(ClassLoader.java:252)         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)         ... 7 more [/code] Moreover, the error for  the non-retrieved class has also been changed now. The problem was that I was not including the application-client.xml file, after including this file, I get the same exception saying that the Count interface is not found.  Btw, how do I find which build I am using to make sure the bug is not affecting me. [code] $ appclient -cp   -client dist/count-client-acc.jar  Jul 7, 2009 10:50:36 AM com.sun.enterprise.security.appclient.AppClientSecurityInfoImpl initializeSecurity INFO: acc.secmgroff Exception in thread "main" java.lang.NoClassDefFoundError: com/hardik/mejb/Count         at com.hardik.mejb.CountClientAcc.main(Unknown Source) Caused by: java.lang.ClassNotFoundException: com.hardik.mejb.Count         at java.net.URLClassLoader$1.run(URLClassLoader.java:200)         at java.security.AccessController.doPrivileged(Native Method)         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)         at java.lang.ClassLoader.loadClass(ClassLoader.java:307)         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)         at java.lang.ClassLoader.loadClass(ClassLoader.java:252)         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)         ... 1 more [/code]
              • 4. Re: EJB client with DI - @EJB injection doesn't work
                rangalo
                Now I can be sure that it is the bug. The same bean-client setup works with jboss installation.
                • 5. Re: EJB client with DI - @EJB injection doesn't work
                  rangalo
                  Now I can be sure that it is the bug. The same bean-client setup works with jboss installation.