Skip to main content

@EJB annotation nightmare

7 replies [Last post]
glesiak
Offline
Joined: 2010-05-10

Hi I am working on Glassfish v3 and cannot inject my ejb into some object.
I tried many times and changed code but no use.
I give you my netbeans enterprise project.
There are two beans RSSVersion which holds version of some RSS and TimerService which is invoked periodically and prints rss version.
For this to work I must inject RSSVersion object into TimerService singleton..
Please tell me what I am doing wrong.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
glesiak
Offline
Joined: 2010-05-10

I cleared one more time my application and this time is working fine without any errors.
I wonder why I had to remove my interfaces to stay without any error.
What if I needed to add some interface. ?

Martin Gainty

sounds as if you might be plagued by version-mismatch on interfaces you are implementing

i would use a version-specific build environment such as maven

http://maven.apache.org/
2.2.1 is the stable release

Bon Chance/Viel Gluck
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: Tue, 15 Jun 2010 02:34:12 -0700
> From: glassfish@javadesktop.org
> To: users@glassfish.dev.java.net
> Subject: Re: @EJB annotation nightmare
>
> I cleared one more time my application and this time is working fine without any errors.
> I wonder why I had to remove my interfaces to stay without any error.
> What if I needed to add some interface. ?
> [Message sent by forum member 'glesiak']
>
> http://forums.java.net/jive/thread.jspa?messageID=474304
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

_________________________________________________________________
The New Busy is not the old busy. Search, chat and e-mail from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:...
[att1.html]

Alexis Moussine-Pouchkine

I'm not sure why you want to decouple RSSVersion and TimerService.
Both are singletons and you could simply place the updateReportBase() method in RSSVersion.java

Even when keeping them separate, you can do without the local interfaces and the "name" attribute of the @EJB annotation.
Here's a simplified version :

package pl.brag.beans;

import javax.ejb.Singleton;

@Singleton
public class RSSVersion {
private long rssVersion = 0L;

public String getCurrentVersion() {
return String.valueOf( rssVersion );
}

public void setCurrentVersion(long newVersion) {
if( newVersion > rssVersion ) {
rssVersion = newVersion;
}
}
}

-----

package pl.brag.beans;

import javax.ejb.*;

@Singleton
public class TimerService {
@EJB
private RSSVersion rssVersion;

@Schedule( minute="*/1", hour="*" )
public void updateReportBase() {
System.out.println( "Timer called" );
System.out.println( rssVersion.getCurrentVersion() );
}
}

-----

public class HelloServlet extends HttpServlet {

@EJB RSSVersion rssVersion;

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("");
out.println("");
out.println("Servlet HelloServlet");
out.println("");
out.println("");
out.println("Current version = " + rssVersion.getCurrentVersion() );
rssVersion.setCurrentVersion(...);
...

-----

All packaged into a single WAR archive :
WEB-INF/classes/pl/brag/beans/RSSVersion.class
WEB-INF/classes/pl/brag/beans/TimerService.class
WEB-INF/classes/servlets/HelloServlet.class

-Alexis

On 15 juin 2010, at 09:52, glassfish@javadesktop.org wrote:

> Hi I am working on Glassfish v3 and cannot inject my ejb into some object.
> I tried many times and changed code but no use.
> I give you my netbeans enterprise project.
> There are two beans RSSVersion which holds version of some RSS and TimerService which is invoked periodically and prints rss version.
> For this to work I must inject RSSVersion object into TimerService singleton..
> Please tell me what I am doing wrong.
> [Message sent by forum member 'glesiak']
>
> http://forums.java.net/jive/thread.jspa?messageID=474293
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

glesiak
Offline
Joined: 2010-05-10

I would like to have them separate because it would be better model division. RssVersion will be accessed by TimerService but also by other components like web services. It will be updated only by TimerService.
Main issue here is with EJB injection which seems not to work correctly. I get some errors http://pastebin.com/4z2CkftU and I don't know how to handle them. I don't have much experience with EJB that is why I am asking more experienced users for a help :-)

Alexis Moussine-Pouchkine

the proposed code keeps them separate... does it work for you?

On 15 juin 2010, at 10:35, glassfish@javadesktop.org wrote:

> I would like to have them separate because it would be better model division. RssVersion will be accessed by TimerService but also by other components like web services. It will be updated only by TimerService.
> Main issue here is with EJB injection which seems not to work correctly. I get some errors http://pastebin.com/4z2CkftU and I don't know how to handle them. I don't have much experience with EJB that is why I am asking more experienced users for a help :-)
> [Message sent by forum member 'glesiak']
>
> http://forums.java.net/jive/thread.jspa?messageID=474300
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

glesiak
Offline
Joined: 2010-05-10

I deleted my Local and/or Remote interfaces.
Now i get something like http://pastebin.com/Si76CCKZ
Look especially at "Client not authorized":

Failed Permission Check, context(EAOne/EAOne-ejb_jar)- permission((javax.security.jacc.EJBMethodPermission RSSVersion getCurrentVersion,Local,))

I debugged code and I see that the field rssVersion is not of type long as I declared it. instead the type i named something like __EJB31_Generated__RSSVersion__Intf____Bean__
and thus I cannot get my verson value from it. :(

glesiak
Offline
Joined: 2010-05-10

This is server stack trace: http://pastebin.com/4z2CkftU