Hi All
I am facing a problem while trying to get the Initial Context. I am using
OpenEJB as a local server i.e the
org.openejb.client.LocalInitialContextFactory class to get the Initial
Context but i get this exception. Stack Trace follows
Exception Caught in InitialContext
Javax.naming.NamingException: Attempted to load OpenEJB. Cannot embed
OpenEJB. Exception: java.lang.Exception Cannot initialize OpenEJB. OpenEJB
has encountered a fatal error and cannot be started: The Assembler
encountered an unexpected error while attempting to initialize:
org/exolab/castor/xml/ValidationExeption
at
org.openejb.client.LocalInitialContextFactory.getInitialContext(LocalInitial
ContextFactory.java : 67)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java :
662)
at javax.naming.NamingContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.(init)(InitialContext.java: 195)
at com.niit.ClientForHelloWorld.main(ClientForHelloWorld.java:38)
The code for ClientForHelloWorld.java File is:
package com.niit;
import javax.rmi.*;
import javax.naming.*;
import java.util.*;
public class ClientForHelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello World!");
try
{
Properties p= new Properties();
// p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.openejb.client.LocalInitialContextFactory");
//i had tried both the above commented statement and
the next on uncommented statement
p.put("java.naming.factory.initial","org.openejb.client.LocalInitialContextF
actory");
//i had even tried to specify the openejb.home
parameter in diffrent ways: Using System.setProperty and by specifing it in
Properties object
//
p.put("openejb.home","c:\\openejb\\openejb-0.9.2");
Context ctx=null;
try
{
ctx = new InitialContext(p);
//Here i stuck in the exception
}catch(Exception e)
{
System.out.println("Exception caught
in Initial Context");
e.printStackTrace();
}
//Lookup the bean using it's deployment id
Object obj = ctx.lookup("HelloWorld");
System.out.println("After Context Lookup");
//Be good and use RMI remote object narrowing
//as required by the EJB specification.
HelloWorldHome ejbHome = (HelloWorldHome)
PortableRemoteObject.narrow(obj,HelloWorldHome.class);
//Use the HelloHome to create a HelloObject
HelloWorld ejbObject = ejbHome.create();
//The part we've all been wainting for...
String message = ejbObject.helloWorld();
//A drum roll please.
System.out.println( message );
} catch (Exception e)
{
e.printStackTrace();
}
}
}
The code for my Bean Class is:
package com.niit;
public class HelloWorldBean implements javax.ejb.SessionBean
{
private javax.ejb.SessionContext cntxt;
public void setSessionContext(javax.ejb.SessionContext ctx)
{
cntxt=ctx;
}
public javax.ejb.SessionContext getSessionContext()
{
return cntxt;
}
public void ejbCreate() throws javax.ejb.CreateException
{
}
public void ejbActivate()
{
}
public void ejbPassivate()
{
}
public void ejbRemove()
{
}
public String helloWorld()
{
return "Hello World!!";
}
}
Please help me out of this exception......
Thanks and Regards
Swet Batra
The world knows you by what you are and not by what you are capable of doing
----------------------------------------------------------- NOTICE
------------------------------------------------------------
This email and any files transmitted with it are confidential and are solely
for the use of the individual or entity to which it is addressed. Any use,
distribution, copying or disclosure by any other person is strictly
prohibited. If you receive this transmission in error, please notify the
sender by reply email and then destroy the message. Opinions, conclusions
and other information in this message that do not relate to official
business of NIIT shall be understood to be neither given nor endorsed by
NIIT. Any information contained in this email, when addressed to NIIT
Clients is subject to the terms and conditions in governing client contract.