java - Access ejb from web module (RESTful services) in ear application -


i have ear application consists of ejb.jar , web application (war). ejb.jar contains ejbs (beans , interfaces) , war contains rest web services. want access ejbs war module, possible? injecting ejbs doesn't work, null pointer exception.

i know has been asked many times can't seem working...

i using glassfish v2.1.1 (i know should upgrade, right difficult...)

here code fragment returns nullpointerexception: (i know not supposed validate user through get, example code trying check if can access ejb)

@path("/user") public class userws {     @ejb     sb_usrremote sb_usrremote;      @get     @produces(mediatype.text_plain)     public string checkloginattempt(string username, string password)     {         return sb_usrremote.checkloginattempt(username, password).tostring();     } } 

i didn't mention code works when include ejb.jar in ear application's lib folder war module can "see" it. there other way can access ejb classes? using intellij, application java ee application includes web module (for war).

edit

i couldn't avoid glassfish upgrade v2 v4. best decision made problems went away. ejb injection in code worked charm!

thank both suggestions! accepting hugh 's answer because jndi have worked, upgrading glassfish seemed more appropriate solution in long run.

edit 2

i managed proper ejb injection using code:

@path("/user") public class userws {     @ejb (lookup = "java:global/<ear-name>/<ejb-jar-name>/sb_usrremote")     sb_usrremote sb_usrremote;      @get     @produces(mediatype.text_plain)     public string checkloginattempt(string username, string password)     {         return sb_usrremote.checkloginattempt(username, password).tostring();     } } 

i found proper lookup path in glassfish log when deployed ear file.

the bean isn't getting injected because class isn't ejb. should able copy using jndi lookup:

sb_usrremote bean = (sb_usrremote) new initialcontext().lookup("sb_usrremote"); 

more on jndi lookups here: link

another possibility make bean managed bean - think that's possible in jsf, i'm afraid don't know that. [edit - jax-rs, not jsf, per bkail's answer]


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -