This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Unable to Access Stateles Session bean from Client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Unable to Access Stateles Session bean from Client" Watch "Unable to Access Stateles Session bean from Client" New topic
Author

Unable to Access Stateles Session bean from Client

Rohit Malhotra
Greenhorn

Joined: Jan 29, 2006
Posts: 21
Hi,

I am pretty new to EJB TEchnology. I am trying to create a simple stateless Session bean and trying to access through a Client program. I Am using BEA Weblogic Server 8.1.

This is my ejb-jar.xml


<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems,
Inc.//DTD Enterprise JavaBeans 2.0//EN"
"http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd">

<ejb-jar>
<description></description>
<enterprise-beans>
<session>
<display-name>Converter</display-name>
<ejb-name>Converter</ejb-name>
<home>bean.ConverterHome</home>
<remote>bean.Converter</remote>
<ejb-class>bean.ConverterBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>

And this is my weblogic-ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>

<!--
** This file was automatically generated by EJBGen 9.0
** Build: 20040513-1205
-->
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>Converter</ejb-name>
<jndi-name>Converter</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>



My Client program is somehting like this :-
import bean.ConverterHome;
import bean.Converter;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.util.*;
public class ConverterClient
{
public static void main(String args[]) throws Exception
{
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
prop.put(Context.PROVIDER_URL,"t3://localhost:7001");

Context initialContext = new InitialContext(prop);

ConverterHome home = (ConverterHome) initialContext.lookup("java:comp/env/Converter");
Converter currencyConverter = home.create();
System.out.println(currencyConverter.displayMessage());
}

}

However i keep on getting this expcetion
Exception in thread "main" javax.naming.NameNotFoundException: While trying to lookup 'java:comp.env/Converter' didn't find subcontext 'java:comp'. Resolved ''
[Root exception is javax.naming.NameNotFoundException: While trying to lookup 'j
ava:comp.env/Converter' didn't find subcontext 'java:comp'. Resolved '']; remain
ing name 'java:comp/env/Converter'


Any Suggesiton would be welcomed. Thanking in advance,

Regards,
Balazs Borbely
Ranch Hand

Joined: Oct 11, 2004
Posts: 33
Go to the weblogic administration console and check if your bean is deployed and under what JNDI path.

The URL for the console should look like this.

http://hostname: port/console
[ January 29, 2006: Message edited by: Balazs Borbely ]

'Make everything as simple as possible, but not simpler.' --Albert Einstein
Reid M. Pinchback
Ranch Hand

Joined: Jan 25, 2002
Posts: 775
I think you'll find that java:comp/env as a JNDI prefix is only relevant for code inside the container (ejb or web app), not remote clients. Doesn't matter if you are using a local interface or a remote interface, it is determined by where the client is.


Reid - SCJP2 (April 2002)
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
The home interface is bound into the global JNDI tree. So, you'll need this lookup.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Rohit Malhotra
Greenhorn

Joined: Jan 29, 2006
Posts: 21
Hi,

When i goto the Weblogic console, under the deployments i am unable to see my Bean.
My Folder structure is something like this

FIRSTEJB
|-META-INF
ejb-jar.xml
weblogic-ejb-jar.xml
CLASSES
bean
Converter.class
ConverterBean.class
ConverterHome.class

And i have made the .ear of the folder and deployed it inot the Autodeploy folder. Still i am unable to see the Bean. Do i need to put some additonal file? Please help me out.
Maarten de Heus
Greenhorn

Joined: Jan 30, 2006
Posts: 9
>And i have made the .ear of the folder and deployed it inot the Autodeploy >folder.

1) ear file? I would think you need a jar file.
2) what does the WLS log say? When you copy something to the autodeploy folder, WLS tries to deploy it and will tell you if something goes wrong.
Rohit Malhotra
Greenhorn

Joined: Jan 29, 2006
Posts: 21
Hi.. sorry for my mistake.

Yes i have deployed the .jar in the AutoDeploy Folder. There is no message posted on the Weblogic. So i guess the deployment should have been fine.
If the deployment isnt fine then is ther anything else that needs to be added here?

Thanking in advance,
Maarten de Heus
Greenhorn

Joined: Jan 30, 2006
Posts: 9
Rohit,

WLS will put something in the log when it performs a deploy. When the deploy goes fine it will say something like; deployed Converter. When the deploy goes bad it will write an error messages.

When the log doesn't say anything, probably nothing has hapened. Make sure the autodeploy facility is on and your not running in production mode.

An other solution is to deploy the bean via the console; open de deployments section en then the beans section. Click on configure new EJB. Then select configure new EJB. Select your converter.jar and deploy it.

good luck !
Rohit Malhotra
Greenhorn

Joined: Jan 29, 2006
Posts: 21
Hi,
I am now trying to deploy the same Bean through Admin Console. However i keep on getting the same error : Unable to load a class specified in your ejb-jar.xml: bean.ConverterBean

Even though the class is very much present in my .jar file Please help me out.

Thanking in advance,
Maarten de Heus
Greenhorn

Joined: Jan 30, 2006
Posts: 9
From the description of your jar file I understand that you have a CLASSES folder containing a subfolder bean containing the classes. Is that correct?

You don't need the CLASSES folder (that's for wars).

greetz,
Maarten
Rohit Malhotra
Greenhorn

Joined: Jan 29, 2006
Posts: 21
Hi,

Thanks a lot.. for your patience. Finally i was able to deploy and Access my First EJB .
 
GeeCON Prague 2014
 
subject: Unable to Access Stateles Session bean from Client