You have to store a Serializable object in JNDI in order for it to get over to the
client.
The ExternalContext class won't help with this as it does not store a Serializable
representation. It shouldn't be too hard to change this to support a Serializable form
that allows the client to reconstitute the foreign InitialContext.
----- Original Message -----
From: Lennart Petersson
To: JBoss-User
Sent: Friday, March 09, 2001 3:29 AM
Subject: [jBoss-User] JBoss ejb looking up ejb in other non-jboss server
Ok, now i can have a jboss ejb bean to lookup and work with a ejb bean deploy in other
ejb server (in this case Ejipt). But i can't
figure out how to look it up from the client... I can see the problem, the reference
to the ejipt ejb bean is only available in
jboss vm. What i hope for is that someone knows how to get it over to the jboss
client. Will ExternalContext help me in anyway, or
does it have the same problem?
Why we are doing this? We are going from Ejipt to JBoss, but until all ejb beans have
been converted it would be nice to be able to
call the still unconverted ejb beans running in Ejipt during testing of the converted
beans running in JBoss.
What i have done:
1) I have an mbean, ECSProperties, which among other things binds a reference to an
Ejipt context. Code snippet:
public void startService()
throws Exception
{
... snip ...
/* Bind a ctx to Ejipt */
final Properties properties = new Properties();
Context context = null;
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"com.valto.ejipt.ContextFactory");
properties.setProperty(Context.PROVIDER_URL, "ejipt://" + getServer() + ":" +
getPort());
properties.setProperty(Context.SECURITY_PRINCIPAL, getUser());
properties.setProperty(Context.SECURITY_CREDENTIALS, getPassword());
System.setProperty("ejipt.sessionScope", "vm");
try
{
context = new InitialContext(properties);
}catch(Exception e)
{
log.error(e.getMessage());
log.exception(e);
}
try
{
NonSerializableWrapper.add(context);
String className = "javax.naming.Context";
String factory = NonSerializableWrapper.class.getName();
Reference memoryRef = new Reference(className, factory, null);
ctx.bind("ejipt", memoryRef);
/* Test it */
_ejiptCtx = (Context)ctx.lookup("ejipt");
System.out.println("Found ctx:"+_ejiptCtx);
}catch(NamingException e)
{
log.error("Failed to bind EjiptContext into JNDI");
log.exception(e);
}catch(Exception e)
{
log.error(e.getMessage());
log.exception(e);
}
... snip ...
}
public static class NonSerializableWrapper implements ObjectFactory
{
private static Context _ctx;
public static void add(Context ctx)
{
System.out.println("adding:"+ctx);
_ctx = ctx;
}
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable
env)
{
System.out.println("getObjectInstance, returning:"+_ctx);
return _ctx;
}
}
2) Code in jboss ejb bean that works ok:
Context ctx = new InitialContext();
/* ejb bean bound in ejipt with name Ecs.Checkout.CheckoutRegisterHome
se.benefit.rita.checkout.CheckoutRegisterHome home =
(se.benefit.rita.checkout.CheckoutRegisterHome)ctx.lookup("ejipt/Ecs.Checkout.CheckoutRegisterHome");
se.benefit.rita.checkout.CheckoutRegister remote;
System.out.println("home:"+home);
Collection c = home.findBySite(600,"129");
System.out.println(c.size());
Iterator it = c.iterator();
while(it.hasNext())
{
remote = (se.benefit.rita.checkout.CheckoutRegister)it.next();
System.out.println("remote:"+remote.getDescription());
}
3) Code in jbocc client that do not work:
InitialContext ctx = new InitialContext();
Context ejiptCtx =
(Context)ctx.lookup("ejipt/Ecs.Checkout.CheckoutRegisterHome");
clip from console:
getObjectInstance, returning:null
Exception in thread "main" javax.naming.NamingException: Could not dereference o
bject. Root exception is java.lang.NullPointerException
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:345)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:282)
at javax.naming.InitialContext.lookup(Unknown Source)
at MainLogger.<init>(MainLogger.java:156)
at MainLogger.main(MainLogger.java:351)
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]