?
Solved

Problem to call EJB from Servlet

Posted on 2005-05-11
14
Medium Priority
?
500 Views
Last Modified: 2013-11-24
Hi everybody,

Below is my problem:

I'm using Borland Enterprise Server AppServer Edition 5.2.1 and trying to call ejb object (ClientManager - Stateless Bean) from the servlet. This is how i'm doing it:

private ClientManagerHome clManagerHome;

Context ctx = new InitialContext();
           
clManagerHome = (ClientManagerHome)ctx.lookup("ClientManagerHome");

ClientManager clManager = clManagerHome.create();

and i'm getting the following error:

javax.naming.NameNotFoundException [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]

then i tried another way to call ejb:

private ClientManagerHome clManagerHome;

Context ctx = new InitialContext();

Object obj = ctx.lookup("ClientManager");
           
clManagerHome =  (ClientManagerHome)PortableRemoteObject.narrow(obj, ClientManagerHome.class);

ClientManager clManager = clManagerHome.create();

and i got the following error:

java.lang.ClassCastException: Cannot narrow without a stub class: secommerce._ClientManagerHome_Stub

i have checked this file _ClientManagerHome_Stub and it's there.

Does anyone know what's wrong and how to solve my problem??

Thq in advance.



0
Comment
Question by:worldserga
  • 5
  • 3
  • 3
  • +2
13 Comments
 
LVL 16

Expert Comment

by:suprapto45
ID: 13975734
Hi,

>>"javax.naming.NameNotFoundException"

Are you sure that you have bind your Stateless Bean into ClientManagerHome. It is normally configured in .xml file.

clManagerHome = (ClientManagerHome)ctx.lookup("ClientManagerHome");

Regards
Dave
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 13975738
0
 
LVL 2

Expert Comment

by:patbin
ID: 13975838

try this one  


 InitialContext initContext = null;
initContext = new javax.naming.InitialContext();
     
   String JNDIName = "java:comp/env/ejb/ClientManager";
     
                  Object objref = initContext.lookup(JNDIName);

clManagerHome = (ClientManagerHome)PortableRemoteObject.narrow(objref,
ClientManagerHome.class);

ClientManager clManager=  clManagerHome.create();

hope this will solve ur problem    
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:worldserga
ID: 13976238
Hi guys,

Thanks for the quick response.

patbin thanks but i did try it ("java:comp/env/ejb/ClientManager") before. It didn't help.

suprapto45 thanks but your link didn't help me.

I think something wrong with the AppServer. Somehow EJB 2.0 doesn't want to work on this server, i'm not sure why. I just tested EJB 1.1 and it is working fine.

Anyway thanks guys.
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13977964
Do you use ant to generate the jar?
I am not familure with Borland app server but you might need to include in the jar generated stubs (from your ejb) by applying some sort
of ejbc (ejb compiler) utility.
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13978012
Also, once you call with ClientManagerHome and once you call with ClientManager (which one the ejb home is bound)
You can probably list your jndi tree to validate it (also see what is the value in the borland specific ejb xml file related to jndi).
Also Did you try:
Context ctx = new InitialContext();
clManagerHome = (ClientManagerHome)ctx.lookup("ClientManager"); // as the other method seemd to find it
ClientManager clManager = clManagerHome.create();


0
 
LVL 1

Author Comment

by:worldserga
ID: 13978213
Hi aozarov,

I have actually resolved all my problems.

Thanks.
0
 
LVL 1

Author Comment

by:worldserga
ID: 13978273
Sorry guys,

Regarding the points. I don't really think that i should award anybody because eventually i have resolved my problem myself.

Any objections from you??

0
 
LVL 1

Author Comment

by:worldserga
ID: 13978612
It's me again.

Guys i want to close this question and i would like to explain what was the problem. As I already mentioned the problem was with my AppServer which is Borland Enterprise Server Edition 5.2.1. Somehow EJB 2.0 doesn't want to work with it. Now I don't really want to know why is that because it was not the topic of the question. I have tested EJB 1.1 and it's working fine which is good enough for me. Initially i thought that something wrong with my code but after testing with EJB 1.1 i realized that there is nothing wrong with my code.

That's it.

0
 
LVL 15

Expert Comment

by:aozarov
ID: 13979123
>> Any objections from you??
None from me :-)
Did you try "clManagerHome = (ClientManagerHome)ctx.lookup("ClientManager");" though? because it seems that  ClientManagerHome is not bound (jndi exception) but
"ClientManager" is bound  (as you get narrowed exception - after jndi).
0
 
LVL 1

Author Comment

by:worldserga
ID: 13983496
Yes I did try clManagerHome = (ClientManagerHome)ctx.lookup("ClientManager"). It didn't help.

I think that my AppServer supports EJB2.0 but because of the configuration or whatever i have this kind of problems. It's ok, as i mentioned EJB1.1 is good enough for me.

Thanks to all of you.
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 13983879
Hi,

>> Any objections from you??
No...you solved it by yourself :).

Glad to know that you solve it.

Regards
Dave
0
 

Accepted Solution

by:
PAQ_Man earned 0 total points
ID: 14016003
Question Closed, 250 points refunded.
PAQ_Man
Community Support Moderator
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question