Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess remote objects with an RMI client by creating an initial context and performing a lookup
    text
    copied!<p>I'm trying to look up the PublicRepository class from an EJB on a Weblogic 10 server. This is the piece of code:</p> <pre><code>/** * RMI/IIOP clients should use this narrow function */ private static Object narrow(Object ref, Class c) { return PortableRemoteObject.narrow(ref, c); } /** * Lookup the EJBs home in the JNDI tree */ private static PublicRepository lookupHome() throws NamingException { // Lookup the beans home using JNDI Context ctx = getInitialContext(); try { Object home = ctx.lookup("cea"); return (PublicRepository) narrow(home, PublicRepository.class); } catch(NamingException ne) { System.out.println("The client was unable to lookup the EJBHome. Please make sure "); System.out.println("that you have deployed the ejb with the JNDI name " + "cea" + " on the WebLogic server at " + "iiop://localhost:7001"); throw ne; } } private static Context getInitialContext() throws NamingException { try { // Get an InitialContext Properties h = new Properties(); h.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); h.put(Context.PROVIDER_URL, "iiop://localhost:7001"); return new InitialContext(h); } catch(NamingException ne) { System.out.println("We were unable to get a connection to the WebLogic server at " + "iiop://localhost:7001"); System.out.println("Please make sure that the server is running."); throw ne; } } </code></pre> <p>I'm however getting Cast Exception:</p> <pre><code>Exception in thread "main" java.lang.ClassCastException at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(Unknown Source) at javax.rmi.PortableRemoteObject.narrow(Unknown Source) at vrd.narrow(vrd.java:67) at vrd.lookupHome(vrd.java:80) at vrd.main(vrd.java:34) Caused by: java.lang.ClassCastException: weblogic.corba.j2ee.naming.ContextImpl ... 5 more </code></pre> <p>Am I correct when I'm using the above code to retrive a certain class to be used in my client application? How could I get rid of the cast exception?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload