users@glassfish.java.net

EJB client with DI - _at_EJB injection doesn't work

From: <glassfish_at_javadesktop.org>
Date: Mon, 06 Jul 2009 06:58:44 PDT

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 int he 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.&lt;init&gt;(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 sent by forum member 'rangalo' (rangalo)]

http://forums.java.net/jive/thread.jspa?messageID=354234