• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

@EJB annotation from servlet and JBoss

 
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have just begun reading Manning's book: EJB 3 In Action. I am currently on chapter 2 and have downloaded the examples.

I tried the code samples for the first chapter and they are working fine. However, after reading the second chapter, I wanted to try replacing the client code for a servlet.

This is what I have:







And the Web Application's DD (web.xml):


Now whenever I run it, I get a NullPointerException: an that is because "helloUser" refers to null. It looks like DI isn't working by simply using the @EJB annotation.

The client application that came with the samples works fine:


Using this jndi.properties file:


As you can see the client application is using JNDI.

FYI, the whole project is packet in file "example1.ear", which has "META-INF" directory, "chapter1-ejb.jar" (which contains the EJB) and "chapter1-web.war" (which contains the web application).

Just in case this info might be usuful, the "application.xml" inside the ear's META-INF is:


What am I missing? Is it a problem with JBoss' configuration?
Any help will be highly appreciated. Thanks in advance.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sergio,

I guess, you are using JBoss-4.x which does not support EJB injection in servlets or application clients. The later version JBoss-5.x (which is still in Beta) supports injecting the EJB in servlets and application clients.
 
Sergio Tridente
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Jaikiran. I am using version 4.2.2 GA, that explains everything.
 
Sergio Tridente
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have installed JBoss beta 4 and tried again: now it works fine.

BTW, is it me or JBoss 5.x runs slower than 4.2.2 GA?
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sergio Tridente:

BTW, is it me or JBoss 5.x runs slower than 4.2.2 GA?



You are right JBoss 5.x is slower compared to JBoss-4.2.2 GA. However, JBoss-5 is still in Beta. The performances changes usually happen after a candidate release, before a GA.

And by the way, since you seem to be using JBoss for certification purpose, i would recommend that you stick with JBoss-4.2.2 GA, instead of JBoss-5.0 Beta which has some known issues even in deployment. You wouldn't want to spend time trying to debug those
 
Sergio Tridente
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jaikiran Pai:

And by the way, since you seem to be using JBoss for certification purpose, i would recommend that you stick with JBoss-4.2.2 GA, instead of JBoss-5.0 Beta which has some known issues even in deployment. You wouldn't want to spend time trying to debug those



I have had the same thought before trying it. The thing is that I went to JBoss' forums and I found some post explaining that JBoss 4.2.2 GA is NOT a JEE 5.0 AS but rather J2EE 1.4 with an EJB 3.0 plugin. And the fact that some annotations are not supported, like for example @EJB, got me thinking. Now I am really confused. What do you think? Should I stick with 4.2.2 GA anyway? What about those options not yet implemented? Won't it be an issue for the exam preparation? Should I go to Glassfish instead?
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sergio Tridente:
I have had the same thought before trying it. The thing is that I went to JBoss' forums and I found some post explaining that JBoss 4.2.2 GA is NOT a JEE 5.0 AS but rather J2EE 1.4 with an EJB 3.0 plugin. And the fact that some annotations are not supported, like for example @EJB, got me thinking.


That's right, JBoss-4.2.2 GA is not a JEE 5.0 server. The @EJB annotation is supported only in the EJB layer (and not in web or application client).

Originally posted by Sergio Tridente:
Now I am really confused. What do you think? Should I stick with 4.2.2 GA anyway? What about those options not yet implemented? Won't it be an issue for the exam preparation? Should I go to Glassfish instead?



Sergio,

Between JBoss-4.2.2 GA and JBoss-5 Beta, i would definitely recommend JBoss-4.2.2 GA. I personally have no idea of what's covered as part of the exam, so i can't say how that's going to be affected. You will have a smooth sailing with JBoss-4.2.2 GA but *might* not be able to try out a few things like injection in servlets (if that's covered as part of the exam). If you have an option of using Glassfish (and it doesn't have these issues?) then that definitely is the best option.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jaikiran Pai:
Sergio,

I guess, you are using JBoss-4.x which does not support EJB injection in servlets or application clients. The later version JBoss-5.x (which is still in Beta) supports injecting the EJB in servlets and application clients.



Hi i have a similar problem. Im using JBoss-4.2.2, and i have been tried to make an @EJB injection in a Message Driven Bean, but i get a runtime error in deploy time.

I get this error: "java.lang.RuntimeException: Failed to populate ENC: env/MyMDBean/MySessionBean global jndi name was null"

the code is someting like that:
-------------------------------------------------------------------
@Stateless(name = "MySessionBean")
public class MySessionBean implements IMySessionBeanRemote {

public void doSometing(String a) {
try {
System.out.println("in doSometing!! :"+a);
}cath(Exception e){
e.printStackTrace();
}

}
-------------------------------------------------------------------
@MessageDriven(name="MyMDBean", activationConfig = {
@ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
@ActivationConfigProperty(propertyName="destination", propertyValue="queue/TestQueue")

})
public class MyMDBean implements MessageListener {

@Resource
private MessageDrivenContext context;

@EJB(beanName = "MySessionBean")
private MySessionBean myBean;

public void onMessage(Message message) {
try {
...
} catch (Exception t) {
...
}
}
}

Any ideas?, Jboss 4.2.2 supports @EJB injection?

Thanks for your help.
[ July 04, 2008: Message edited by: Manuel Jimenez ]
 
Sergio Tridente
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have just tried your code on JBoss 4.2.2GA and I am getting the same results. However, after changing the code it works. Here's my modification:



This might be a problem with JBoss. I am going to install Glassfish and try it again. I will post the results back.
[ July 05, 2008: Message edited by: Sergio Tridente ]
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In JNDI lookup if you use
context.lookup("example1/HelloUserBean/remote");
then it will work for JBOSS4.XX also.

If ejb is in ear use this earName/ejbImpBean/local((or /remote)).
If ejb is in jar then use this ejbImpBean/local((or /remote)).


I used this with 4.2.2 GA and it worked.
 
Sergio Tridente
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Same problem with Glassfish. This is the message I get: Warning : Unable to determine local business vs. remote business designation for EJB 3.0 ref Unresolved Ejb-Ref com.business.MyMDBean/myBean@jndi: @[email protected]@Session@MySessionBean
 
Manuel Jimenez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tanks for your help!
 
Sergio Tridente
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also tried the following modification on both JBoss and Glassffish:



It worked fine on Glassfish but it did not work on JBoss.
 
Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic