Skip to main content

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

5 replies [Last post]
rangalo
Offline
Joined: 2009-07-06

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:

<br />
package com.hardik.mejb;</p>
<p>import javax.ejb.EJB;</p>
<p>public class CountClientAcc {</p>
<p>	@EJB<br />
	public static Count count;</p>
<p>	public static void main(String[] args) {<br />
		try {<br />
			count.set(10);<br />
			System.out.println("Count is: "+ count.count());</p>
<p>		} catch (Exception e) {<br />
			e.printStackTrace();<br />
		}<br />
	}<br />
}

The bean is code is like following:

package com.hardik.mejb;</p>
<p>import javax.ejb.Remote;<br />
import javax.ejb.Remove;<br />
import javax.ejb.Stateful;<br />
import javax.interceptor.Interceptors;</p>
<p>@Stateful<br />
@Remote(Count.class)<br />
@Interceptors(CountCallBacks.class)<br />
public class CountBean implements Count {</p>
<p>	/**<br />
	 * Current counter is our conversational state<br />
	 */<br />
	private int val;</p>
<p>	@Override<br />
	public int count() {<br />
		System.out.println("count():");<br />
		return ++val;<br />
	}</p>
<p>	/**<br />
	 * The remove method is annotated so the container knows,<br />
	 * it can remove the bean after this method is called.<br />
	 */<br />
	@Override<br />
	@Remove<br />
	public void remove() {<br />
		System.out.println("remove():");<br />
	}</p>
<p>	@Override<br />
	public void set(int val) {<br />
		this.val = val;<br />
		System.out.println("set():");</p>
<p>	}</p>
<p>}</p>
<p>

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.

<br />
$ appclient -client count-client-acc.jar<br />
java.lang.IllegalArgumentException: URI scheme is not "file"<br />
        at java.io.File.<init>(File.java:366)<br />
        at com.sun.enterprise.deployment.util.ConnectorAnnotationDetector.hasAnnotationInArchive(ConnectorAnnotationDetector.java:65)<br />
        at com.sun.enterprise.deployment.archivist.ConnectorArchivist.postHandles(ConnectorArchivist.java:116)<br />
        at com.sun.enterprise.deployment.archivist.ArchivistFactory.getPrivateArchivistFor(ArchivistFactory.java:165)<br />
        at com.sun.enterprise.deployment.archivist.ArchivistFactory.getPrivateArchivistFor(ArchivistFactory.java:131)<br />
        at com.sun.enterprise.deployment.archivist.ArchivistFactory.getArchivist(ArchivistFactory.java:79)<br />
        at org.glassfish.appclient.client.acc.UndeployedLaunchable.newUndeployedLaunchable(UndeployedLaunchable.java:84)<br />
        at org.glassfish.appclient.client.acc.Launchable$LauchableUtil.newLaunchable(Launchable.java:114)<br />
        at org.glassfish.appclient.client.acc.AppClientContainerBuilder.newContainer(AppClientContainerBuilder.java:161)<br />
        at org.glassfish.appclient.client.acc.agent.AppClientContainerAgent.createContainerForAppClientArchiveOrDir(AppClientContainerAgent.java:407)<br />
        at org.glassfish.appclient.client.acc.agent.AppClientContainerAgent.createContainer(AppClientContainerAgent.java:377)<br />
        at org.glassfish.appclient.client.acc.agent.AppClientContainerAgent.premain(AppClientContainerAgent.java:225)<br />
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br />
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br />
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br />
        at java.lang.reflect.Method.invoke(Method.java:597)<br />
        at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:323)<br />
        at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:338)

2. This works for me when I run the jndi lookup client.

$ appclient -client -cp "../../CountBean/dist/count-bean.jar:count-client-acc.jar" com.hardik.mejb.CountClientAcc<br />
Jul 6, 2009 3:58:10 PM com.sun.enterprise.security.appclient.AppClientSecurityInfoImpl initializeSecurity<br />
INFO: acc.secmgroff<br />
java.lang.NullPointerException<br />
        at com.hardik.mejb.CountClientAcc.main(Unknown Source)</p>
<p>

Am I making some mistake ?

Message was edited by: rangalo

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rangalo
Offline
Joined: 2009-07-06

Now I can be sure that it is the bug. The same bean-client setup works with jboss installation.

Martin Gainty

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....

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_Tu...
[att1.html]

tjquinn
Offline
Joined: 2005-03-30

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

rangalo
Offline
Joined: 2009-07-06

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]

rangalo
Offline
Joined: 2009-07-06

Now I can be sure that it is the bug. The same bean-client setup works with jboss installation.