• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting EJB 3.0 to work  RSS feed

 
Rashid Darvesh
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i am one of the many people who are trying their hand on writing ejb3.0 on sun app server. As guessed, my context is not able to find the local interface. Here is my ejb code
@Stateless
public class CalculatorBean implements com.cal.CalculatorLocal {
/** Creates a new instance of CalculatorBean */
public CalculatorBean() {
}
public int add(int a , int b){
System.out.println("Came in the add method of the Calculator bean");
return a+b;
}
}
My interface is
@Local
public interface CalculatorLocal {
public int add(int a,int b);
}

On the client side i am using
try{
InitialContext ctx = new InitialContext();
cal = (CalculatorLocal)ctx.lookup(CalculatorLocal.class.getName());
}catch(javax.naming.NamingException e){ }
if (cal == null){
System.out.println("Calculator Object is null");
}else{
System.out.println("The value of add is " + cal.add(3,8));
}

Here are the all important jar files which are packaged inmy war file. war file structure is as follows
.jsp files (all jsp files)
WEB-INF
---->classes
-------->all class files
---->lib
-------->appserv-rt.jar
-------->Calculator.jar (This my packaged ejb)
-------->all other jar files.
Both the ejb and the war file are deployed through the sun app server admin console.
Please let me know what i am doing wrong why cant i load the stub for CalculatorLocal interface.

Thanks
Rashid
 
Andreas Schaefer
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First you should have posted the exception you get on the client.

You cannot use a Local Interface on the client side because it is only available to an EJB within its application otherwise a local interface would have made sense.
Just make sure that you use a Remote Interface and look that one up from the client.

-Andy

(Sorry Andy, had to do a small little clean up on aisle 5. Lunch on Friday talk to Matt - Mark)
[ July 20, 2006: Message edited by: Mark Spritzler ]
 
Rashid Darvesh
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Andrea.
It works now, i reinstalled the sun app server and created a new EJB
HelloBean
HelloRemote
HelloLocal

and my client was able to grab hold of the remote interface using the context look up method soething like this
try{
InitialContext ctx = new InitialContext();
helloremote = (com.test.HelloRemote)ctx.lookup(com.test.HelloRemote.class.getName());
}catch(javax.naming.NamingException e)
{
e.printStackTrace();
}
but when i when i tried to use using the injector method it failed.,
This is how i am trying to grab the remote interface using the injector method
@EJB com.test.HelloRemote helloremote;
and use the helloremote object it always comes null. To use @EJB annotation i imported package import javax.ejb.EJB;

Please let me know what i am doing wrong.

Thanks
Rashid
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't it the responsibility of the container to do the injection? And this code is on the client side, not in a container, with nothing to do the injection for you.

Mark
 
susarla bhaskar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will work when you change it to remote,because your client is outside your EJB container.
You call local interface when you are inside the container for example from a session bean.

Thanks,
Bhaskar
 
Rashid Darvesh
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct me if i am wrong. i thought the @EJB is used at the client side and that will automatically search for you the remote interface. BTW, if i am tryig to look for the remote interface. since my ejb is deployed as a standalone EJB and is not a part of an ear file.
But my client webapp and the ejb are deployed on the sun one app container. Finding the remote interface using context lookup method works without any issue, but when i try to use injector it doesn't find it. Any suggestions or opinions.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!