By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
InitialContext ctx = new InitialContext(); Object obj = ctx.lookup("com.borg.MyHome"); MyHome home = (MyHome) PortableRemoteObject.narrow(obj, MyHome.class);
The reason that the snippet of code you have provided works in a servlet environment, is because the context is local and "known" without any additional information and thus can be retrieved by simply calling the no-arg constructor of the InitialContext class. However, when retrieving the context from another box, you must supply additional information in the form of properties to the InitialContext class. This additional information is configured for a WebLogic environment, as follows:
Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.T3InitialContextFactory"); props.put(Context.PROVIDER_URL, "t3://somehostname:someportnumber"); InitialContext ctx = new InitialContext(props); Object obj = ctx.lookup("com.borg.MyHome"); MyHome home = (MyHome) PortableRemoteObject.narrow(obj, MyHome.class);
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.