Javax.rmi.portableRemoteObject.narrow

Hi
Pls tell me why we narrow the instance of the object we looked up,
before type casting it to a home referance by using javax.rmi.portableRemoteObject.narrow(Object,Home.class)

In the early days of EJB this call was required to ensure portability due to some intracacies of how
RMI-IIOP and CORBA ORBs are implemented. Some implementations are able to directly return
the correctly typed object from the lookup, but in others the extra PortableRemoteObject.narrow
call is necessary, so always using it ensures portability.
Starting in Java EE 5, PortableRemoteObject.narrow is not needed if the code is either accessing
a Remote 3.0 Business Interface or if the code is accessing a 2.x style Home object using
@EJB or the new EJBContext.lookup method.
--ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • JNDI in ActiveX : javax.rmi.PortableRemoteObject.narrow() can't work ?

    Hi All,
    I got a big head ache of this problem for several days, much appreciated if
    I can get help from you.
    The problem is, I wrote an EJB and already deployed it into Weblogic5.1. I
    also wrote a java EJB client to access this EJB. Everything seemed ok at
    this moment.
    The problem occured after i convert this EJB client to ActiveX and test it
    with Microsoft ActiveX Control Test Container. I log each step in the
    ActiveX, and find the problem is caused by
    javax.rmi.PortableRemoteObject.narrow(). Below is my source code and log
    information. My environment is Server side(weblogic5.1),Client side(java
    run-time3.1 with plug-in).
    Source code:
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFacto
    ry");
    env.put(Context.PROVIDER_URL,"t3://"+ip+":"+port);
    try{
    Log("Init jndi ");
    InitialContext ctx = new InitialContext(env);
    Log("Search Home ");
    Object obj = ctx.lookup("ServiceManagerHome");
    Log("home is "+obj);
    Log("narrow from "+obj.getClass().getName());
    Log("narrow to "+ServiceManagerHome.class.getName());
    obj = PortableRemoteObject.narrow(obj,ServiceManagerHome.class);
    Log("narrow home is "+obj);
    serviceHome = (ServiceManagerHome)obj;
    Log("cast home"+serviceHome);
    serviceManager = serviceHome.create();
    Log("Create EJB bean "+serviceManager);
    } catch (Exception e){
    Log("Err-"+e);
    Log("Err-"+e.getLocalizedMessage());
    Log("Err-"+e.getMessage());
    Log information for ActiveX:
    Init jndi
    Search Home
    home is ServiceManagerHome [
    -4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/259]
    narrow from rm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub
    narrow to crm.service.ejbimpl.ServiceManagerHome
    Err-java.lang.ClassCastException
    Err-null
    Err-null
    Log information for java EJB Client:
    Init jndi
    Search Home
    home is
    crm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub@-4611900794319518
    045S155.161.96.26:[7001,7001,7002,7002,7001,-1] ServiceManagerHome [
    -4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/259
    narrow from crm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub
    narrow to crm.service.ejbimpl.ServiceManagerHome
    narrow home
    crm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub@-4611900794319518
    045S155.161.96.26:[7001,7001,7002,7002,7001,-1] ServiceManagerHome [
    -4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/259]
    cast
    homecrm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub@-461190079431
    9518045S155.161.96.26:[7001,7001,7002,7002,7001,-1] ServiceManagerHome [
    -4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/259
    Create serviceManager
    crm.service.ejbimpl.ServiceManagerBeanEOImpl_ServiceStub@-461190079431951804
    5S155.161.96.26:[7001,7001,7002,7002,7001,-1] ServiceManagerHome_EO [
    -4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/258

    Contact support.
    Yuan Ming Lei wrote:
    Hi All,
    I got a big head ache of this problem for several days, much appreciated if
    I can get help from you.
    The problem is, I wrote an EJB and already deployed it into Weblogic5.1. I
    also wrote a java EJB client to access this EJB. Everything seemed ok at
    this moment.
    The problem occured after i convert this EJB client to ActiveX and test it
    with Microsoft ActiveX Control Test Container. I log each step in the
    ActiveX, and find the problem is caused by
    javax.rmi.PortableRemoteObject.narrow(). Below is my source code and log
    information. My environment is Server side(weblogic5.1),Client side(java
    run-time3.1 with plug-in).
    Source code:
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFacto
    ry");
    env.put(Context.PROVIDER_URL,"t3://"+ip+":"+port);
    try{
    Log("Init jndi ");
    InitialContext ctx = new InitialContext(env);
    Log("Search Home ");
    Object obj = ctx.lookup("ServiceManagerHome");
    Log("home is "+obj);
    Log("narrow from "+obj.getClass().getName());
    Log("narrow to "+ServiceManagerHome.class.getName());
    obj = PortableRemoteObject.narrow(obj,ServiceManagerHome.class);
    Log("narrow home is "+obj);
    serviceHome = (ServiceManagerHome)obj;
    Log("cast home"+serviceHome);
    serviceManager = serviceHome.create();
    Log("Create EJB bean "+serviceManager);
    } catch (Exception e){
    Log("Err-"+e);
    Log("Err-"+e.getLocalizedMessage());
    Log("Err-"+e.getMessage());
    Log information for ActiveX:
    Init jndi
    Search Home
    home is ServiceManagerHome [
    -4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/259]
    narrow from rm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub
    narrow to crm.service.ejbimpl.ServiceManagerHome
    Err-java.lang.ClassCastException
    Err-null
    Err-null
    Log information for java EJB Client:
    Init jndi
    Search Home
    home is
    crm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub@-4611900794319518
    045S155.161.96.26:[7001,7001,7002,7002,7001,-1] ServiceManagerHome [
    -4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/259
    narrow from crm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub
    narrow to crm.service.ejbimpl.ServiceManagerHome
    narrow home
    crm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub@-4611900794319518
    045S155.161.96.26:[7001,7001,7002,7002,7001,-1] ServiceManagerHome [
    -4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/259]
    cast
    homecrm.service.ejbimpl.ServiceManagerBeanHomeImpl_ServiceStub@-461190079431
    9518045S155.161.96.26:[7001,7001,7002,7002,7001,-1] ServiceManagerHome [
    -4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/259
    Create serviceManager
    crm.service.ejbimpl.ServiceManagerBeanEOImpl_ServiceStub@-461190079431951804
    5S155.161.96.26:[7001,7001,7002,7002,7001,-1] ServiceManagerHome_EO [
    -4611900794319518045S155.161.96.26:[7001,7001,7002,7002,7001,-1]/258

  • A error from javax.rmi.PortableRemoteObject.narrow

    --run envrionment: jdk1.4.2_01 / oc4j9.0.4
    --source code
    import java.util.*;
    import java.io.IOException;
    import java.rmi.RemoteException;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.ejb.*;
    import javax.naming.*;
    import javax.rmi.PortableRemoteObject;
    import java.sql.*;
    public class ProductServlet extends HttpServlet
    server.ProductHome myProductHome;
    public void init() throws ServletException {
    try {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.evermind.server.rmi.RMIInitialContextFactory");
    env.put(Context.PROVIDER_URL, "ormi://localhost/JDBCEJB");
    env.put(Context.SECURITY_PRINCIPAL, "store_user");
    env.put(Context.SECURITY_CREDENTIALS, "store_password");
    Context myInitialContext = new InitialContext(env);
    Object homeObject = myInitialContext.lookup("ProductBean");
    myProductHome = (server.ProductHome)PortableRemoteObject.narrow(homeObject,server.ProductHome.class);
    } catch(NamingException e) {
    throw new ServletException("Error looking up home", e);
    public void doGet(
    HttpServletRequest request, HttpServletResponse response
    ) throws ServletException, IOException {
    response.setContentType("text/html;charset=BIG5");
    ServletOutputStream out = response.getOutputStream();
    out.println("<html>");
    out.println("<head><title>Product</title></head>");
    out.println("<body>");
    out.println("<table width=100% border=1>");
    out.println("<tr>");
    out.println("<th>Id</th>");
    out.println("<th>Name</th>");
    out.println("<th>Address</th>");
    out.println("<th>Bdate</th>");
    out.println("</tr>");
    try {
    server.ProductRemote myProductRemote = myProductHome.create();
    server.Product myProduct = myProductRemote.query(request.getParameter("guess"));
    if (myProduct != null) {
    out.println("<tr>");
    out.println("<td>" + myProduct.id + "</td>");
    out.println("<td>" + myProduct.name + "</td>");
    out.println("<td>" + myProduct.ads + "</td>");
    out.println("<td>" + myProduct.bdate + "</td>");
    out.println("</tr>");
    out.println("</table>");
    out.println("</body></html>");
    } catch(RemoteException e) {
    out.println("Error communicating with EJB-server: " +
    e.getMessage());
    } catch(CreateException e) {
    out.println("Error creating EJB: " + e.getMessage());
    } catch(SQLException e) {
    out.println("SQL Exception: " + e.getMessage());
    --My application client can run correctly, but my servlet code can't run.
    --If I start oc4j by follow statement:
    java -jar oc4j.jar
    --the error display:
    java.lang.ClassCastException
         at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
         at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
         at ProductServlet.init(ProductServlet.java:39)
         at javax.servlet.GenericServlet.init(GenericServlet.java:258)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.loadServlet(HttpApplication.java:2091)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.findServlet(HttpApplication.java:4507)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.getRequestDispatcher(HttpApplication.java:2410)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:629)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java:264)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java:107)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)
         at java.lang.Thread.run(Thread.java:534)
    --If I start oc4j by follow statement:
    java -jar -Djavax.rmi.CORBA.PortableRemoteObjectClass=com.sun.corba.se.internal.javax.rmi.PortableRemoteObject -Djavax.rmi.CORBA.UtilClass=com.sum.corba.se.internal.POA.ShutdownUtilDelegate oc4j.jar
    --the error is:
    java.lang.ExceptionInInitializerError
         at javax.rmi.PortableRemoteObject.createDelegateIfSpecified(PortableRemoteObject.java:179)
         at javax.rmi.PortableRemoteObject.<clinit>(PortableRemoteObject.java:58)
         at ProductServlet.init(ProductServlet.java:39)
         at javax.servlet.GenericServlet.init(GenericServlet.java:258)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.loadServlet(HttpApplication.java:2091)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.findServlet(HttpApplication.java:4507)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.getRequestDispatcher(HttpApplication.java:2410)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:629)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java:264)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java:107)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)
         at java.lang.Thread.run(Thread.java:534)
    Caused by: org.omg.CORBA.INITIALIZE: cannot instantiate com.sum.corba.se.internal.POA.ShutdownUtilDelegate vmcid: 0x0 minor code: 0 completed: No
         at javax.rmi.CORBA.Util.createDelegateIfSpecified(Util.java:341)
         at javax.rmi.CORBA.Util.<clinit>(Util.java:51)
         ... 12 more

    --run envrionment: jdk1.4.2_01 / oc4j9.0.4
    --source code
    import java.util.*;
    import java.io.IOException;
    import java.rmi.RemoteException;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.ejb.*;
    import javax.naming.*;
    import javax.rmi.PortableRemoteObject;
    import java.sql.*;
    public class ProductServlet extends HttpServlet
    server.ProductHome myProductHome;
    public void init() throws ServletException {
    try {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.evermind.server.rmi.RMIInitialContextFactory");
    env.put(Context.PROVIDER_URL, "ormi://localhost/JDBCEJB");
    env.put(Context.SECURITY_PRINCIPAL, "store_user");
    env.put(Context.SECURITY_CREDENTIALS, "store_password");
    Context myInitialContext = new InitialContext(env);
    Object homeObject = myInitialContext.lookup("ProductBean");
    myProductHome = (server.ProductHome)PortableRemoteObject.narrow(homeObject,server.ProductHome.class);
    } catch(NamingException e) {
    throw new ServletException("Error looking up home", e);
    public void doGet(
    HttpServletRequest request, HttpServletResponse response
    ) throws ServletException, IOException {
    response.setContentType("text/html;charset=BIG5");
    ServletOutputStream out = response.getOutputStream();
    out.println("<html>");
    out.println("<head><title>Product</title></head>");
    out.println("<body>");
    out.println("<table width=100% border=1>");
    out.println("<tr>");
    out.println("<th>Id</th>");
    out.println("<th>Name</th>");
    out.println("<th>Address</th>");
    out.println("<th>Bdate</th>");
    out.println("</tr>");
    try {
    server.ProductRemote myProductRemote = myProductHome.create();
    server.Product myProduct = myProductRemote.query(request.getParameter("guess"));
    if (myProduct != null) {
    out.println("<tr>");
    out.println("<td>" + myProduct.id + "</td>");
    out.println("<td>" + myProduct.name + "</td>");
    out.println("<td>" + myProduct.ads + "</td>");
    out.println("<td>" + myProduct.bdate + "</td>");
    out.println("</tr>");
    out.println("</table>");
    out.println("</body></html>");
    } catch(RemoteException e) {
    out.println("Error communicating with EJB-server: " +
    e.getMessage());
    } catch(CreateException e) {
    out.println("Error creating EJB: " + e.getMessage());
    } catch(SQLException e) {
    out.println("SQL Exception: " + e.getMessage());
    --My application client can run correctly, but my servlet code can't run.
    --If I start oc4j by follow statement:
    java -jar oc4j.jar
    --the error display:
    java.lang.ClassCastException
         at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
         at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
         at ProductServlet.init(ProductServlet.java:39)
         at javax.servlet.GenericServlet.init(GenericServlet.java:258)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.loadServlet(HttpApplication.java:2091)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.findServlet(HttpApplication.java:4507)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.getRequestDispatcher(HttpApplication.java:2410)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:629)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java:264)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java:107)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)
         at java.lang.Thread.run(Thread.java:534)
    --If I start oc4j by follow statement:
    java -jar -Djavax.rmi.CORBA.PortableRemoteObjectClass=com.sun.corba.se.internal.javax.rmi.PortableRemoteObject -Djavax.rmi.CORBA.UtilClass=com.sum.corba.se.internal.POA.ShutdownUtilDelegate oc4j.jar
    --the error is:
    java.lang.ExceptionInInitializerError
         at javax.rmi.PortableRemoteObject.createDelegateIfSpecified(PortableRemoteObject.java:179)
         at javax.rmi.PortableRemoteObject.<clinit>(PortableRemoteObject.java:58)
         at ProductServlet.init(ProductServlet.java:39)
         at javax.servlet.GenericServlet.init(GenericServlet.java:258)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.loadServlet(HttpApplication.java:2091)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.findServlet(HttpApplication.java:4507)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpApplication.getRequestDispatcher(HttpApplication.java:2410)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:629)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java:264)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java:107)
         at com.evermind[Oracle9iAS (9.0.4.0.0) Containers for J2EE].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)
         at java.lang.Thread.run(Thread.java:534)
    Caused by: org.omg.CORBA.INITIALIZE: cannot instantiate com.sum.corba.se.internal.POA.ShutdownUtilDelegate vmcid: 0x0 minor code: 0 completed: No
         at javax.rmi.CORBA.Util.createDelegateIfSpecified(Util.java:341)
         at javax.rmi.CORBA.Util.<clinit>(Util.java:51)
         ... 12 more

  • InitialContext and javax.rmi.PortableRemoteObject

    I've been trying to locate a very annoying problem that I get when I try to bind remote objects in JNDI. I have now located the problem but I have no idea why this causes a problem or how to fix it. It seems that creating an InitialContext has different effects depending whether I create an instance of javax.rmi.PortableRemoteObject before.
    Here's what I am doing...
    1:Context ctx = new InitialContext(); //Create Initial context
    2://Instantiate remote object (extends PortableRemoteObject and stubs gen with rmic with -iiop flag)
    3:Hello hello = new HelloImpl();
    4:ctx.rebind("hello", hello); //Bind to JNDI
    5:System.out.println("Object bound!!!!!");
    This code works fine. The problem occurs when I try to instantiate the remote object before creating the InitialContext for the first time (I.e. I move line 3 to the top) I then get the following exception:
    2007-aug-13 09:32:26 com.sun.corba.ee.impl.util.Utility autoConnect
    VARNING: "IOP00511403: (INV_OBJREF) Class rmi.HelloImpl not exported, or else is actually a JRMP stub"
    org.omg.CORBA.INV_OBJREF: vmcid: SUN minor code: 1403 completed: No
    at com.sun.corba.ee.impl.logging.UtilSystemException.objectNotExported(UtilSystemException.java:569)
    at com.sun.corba.ee.impl.logging.UtilSystemException.objectNotExported(UtilSystemException.java:592)
    at com.sun.corba.ee.impl.util.Utility.autoConnect(Utility.java:147)
    at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.writeAny(Util.java:323)
    at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$10.write(DynamicMethodMarshallerImpl.java:256)
    at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.writeArguments(DynamicMethodMarshallerImpl.java:407)
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:157)
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:119)
    at com.sun.corba.ee.impl.presentation.rmi.bcel.BCELStubBase.invoke(BCELStubBase.java:197)
    at com.sun.enterprise.naming._SerialContextProvider_DynamicStub.rebind(_SerialContextProvider_DynamicStub.java)
    at com.sun.enterprise.naming.SerialContext.rebind(SerialContext.java:403)
    at javax.naming.InitialContext.rebind(Unknown Source)
    at parlayxws.usecases.ejb.px_spec_v2_1.RunEjb.main(RunEjb.java:43)
    Exception in thread "main" javax.naming.CommunicationException: java.rmi.NoSuchObjectException: CORBA INV_OBJREF 1398080891 No; nested exception is:
    org.omg.CORBA.INV_OBJREF: vmcid: SUN minor code: 1403 completed: No
    at com.sun.enterprise.naming.SerialContext.rebind(SerialContext.java:405)
    at javax.naming.InitialContext.rebind(Unknown Source)
    at parlayxws.usecases.ejb.px_spec_v2_1.RunEjb.main(RunEjb.java:43)
    I assume the problem is in the javax.rmi.PortableRemoteObject's (HelloImpl's) constructor since that is the only code that's beeing executed. But how could that effect the instantiation of the InitialContext? I should also say that it seems that it is only the first time that an InitialContext is created that is critical. If I create on instance of it before instantiating the first PortableRemoteObject, all subsequently created instances of InitialContext succeed in binding remote (RMI-IIOP) objects.
    Can someone help me understand why this happens and how to avoid it? I don't want to have to create an InitialContext the first thing I do in the code. It seems the PortableRemoteObject constructor somehow changes the configuration in a way that makes the bindings fail... How? Why? Can I prevent it from happening?
    Any input appreciated!
    Kristofer

    my bean is running in my EJBServer, and I have it in the classpath of the RmiRegistry (which runs as part of my server). The RmiRegistry is an actual ".bat" file that starts an RMI Registry (I assume).
    The client is not a bean and is run like this:
    java com.titan.cabin.Client_1
    All it does is create a cabin and then read it back. It works, it not only gets the context, but also creates, persists and reads that cabin bean.
    Is it because java automatically finds all RmiRegistries running on the computer? This makes sense, but I read on java.sun.com that you need a stub class for your clients. And if it is true, then how does it get the context and remote/home interface of a bean on another server?

  • Class javax.rmi.PortableRemoteObject not found in import

    I have successfully tested test1.jsp calling stateful ejb test1ejb under JDEV9032. On deploying to standalone OC4J903, the following error occurred on accessing the jsp:
    500 Internal Server Error
    OracleJSP: oracle.jsp.provider.JspCompileException:
    Errors compiling:D:\O9IAS\j2ee\home\application-deployments\test\testWEB\persistence\_pages\\_test1.java
    Line # Error 10
    Class javax.rmi.PortableRemoteObject not found in import. import javax.rmi.PortableRemoteObject;
    Appreciate some pointers on how to troubleshoot this problem. Thanks. William Chew.

    This error is due to the c:\windows\system32\java.exe being first on the path instead of the d:\jdev9i\jdk\bin\java.exe being picked up.

  • Can javax.rmi.PortableRemoteObject be attribute of http session with in-memory replication?

    Hi:
              When the servlet server try to do the in memory replication, a Stub class
              not found exception throwed out.
              The rmi object is compiled with -iiop option, should I compile it without
              iiop option?
              Please help
              thanks
              andrew
              

    Hi don:
              Thanks for you reply.
              I can't get the stack trace right, I am not working today. but I'll get it
              later.
              All the machine has the IIOP tie and stub class.
              The jar file works fine on weblogic6.1 cluster.
              thanks again
              andrew
              "Don Ferguson" <[email protected]> wrote in message
              news:[email protected]..
              > What's the exact stack trace? Is the stub present on all machines in the
              > cluster?
              >
              > -Don
              >
              > Andrew wrote:
              >
              > > Hi:
              > > When the servlet server try to do the in memory replication, a Stub
              class
              > > not found exception throwed out.
              > > The rmi object is compiled with -iiop option, should I compile it
              without
              > > iiop option?
              > >
              > > Please help
              > > thanks
              > > andrew
              >
              

  • ClassCastException ; javax.rmi.Portable.Remote.Object. narrow(Unknown Sour

    Hi Guys,
    This is my First post, I am in a deep trouble with the following exception. Initially I was getting
    javax.naming.NoInitialContextException:
    Need to specify class name in
    environment or system property, or as an applet parameter
    I added few lines of code in the .java file. and set the classpath to j2ee.jar
    Hashtable env = new Hashtable();
    env.putContext.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
    env.put(Context.PROVIDER_URL, "iiop://localhost:3700");
    Context initctx = new InitialContext(env);
    I was able to get through that error. But then now i am stuck up with the new runtime error .
    java.lang.ClassCastException
    at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(Unknown Source)
    at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
    at AdviceClient.go(AdviceClient.java:24)
    at AdviceClient.main(AdviceClient.java:11)
    I have tried to figure out myself but with little vain. I am using
    Sun One App Server( j2sdkee 1.4 ) with Windows XP.
    I am waiting for a positive response.
    I am pasting the code of my Client
    AdviceClient.java
    import javax.naming.* ;
    import java.rmi.* ;
    import javax.rmi.* ;
    import HeadFirst.* ;
    import javax.ejb.* ;
    public class AdviceClient {
    public static void main( String[] args ) {
    new AdviceClient( ).go( ) ;
    public void go( ) {
    try {
    Hashtable env = new Hashtable();
    env.putContext.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
    env.put(Context.PROVIDER_URL, "iiop://localhost:3700");
    Context initctx = new InitialContext(env);
    Object o = ic.lookup("Advisor") ;
    AdviceHome home = ( AdviceHome ) javax.rmi.PortableRemoteObject.narrow( o, HeadFirst.AdviceHome.class ) ;
    Advice advisor = (Advice )home.create( ) ;
         System.out.println(advisor.getTheMessage( ) ) ;
    } catch( Exception ex ) {
         ex.printStackTrace( );
    I am starting the default server and deploying the session Stateless beans.

    Hi Shivakanth,
    Please follow the guidelines in our EJB FAQ for writing a stand-alone java cilent that accesses ejbs :
    https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html
    --ken                                                                                                                                                                                                                                                                                                                                                                               

  • Confusion in PortableRemoteObject.narrow() method

    In EJB 1.0 reference of home object is obtained through external casting as HelloHome home = (HelloHome)ctx.lookup("HelloHome")
    My question is that since IIOP has not been designed for Java, but for generic languages, and this means that there are some limitations. Some languages, in fact, do not have the concept of casting.
    Still why we have to cast the Object if we use PortableRemoteObject.narrow method for obtaining the home interface reference in EJB2.0.
    HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(object, HelloHome.class)

    If the client is built using Java, you can not explicitly cast from the Naming.lookup() function. Instead, you must use lookup() to return a generic java.lang.Object, and then cast to the specific object type with the PortableRemoteObject.Narrow(objectReference, interfaceName) method.

  • How to solve PortableRemoteObject.narrow exception

    Hi ,
    I am getting portableRemoteObject exception... when i tried to narrow the stub with home class.
    Please find my code:
    Object objRef = ctx.lookup("java:comp/env/ejb/ejbSchedularBean"
    TaskHandlerHome home = (TaskHandlerHome) javax.rmi.PortableRemoteObject.narrow(objRef,TaskHandlerHome.class);
    Please help me to solve.
    cannot cast class com.ibm.websphere.schedular._TaskHandlerHome_Stub to interface com.ibm.websphere.scheduler.TaskHandlerHome
         at com.ibm.rmi.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:396)
         at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:156)
         at com.ibm.websphere.schedular.CallBeanTask.getBeanClassInstance(CallBeanTask.java:66)
         at com.sched.servlet.SchedulerServlet.init(SchedulerServlet.java:25)
         at javax.servlet.GenericServlet.init(GenericServlet.java:256)
         at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:185)
         at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.init(ServletWrapper.java:316)
         at com.ibm.ws.webcontainer.servlet.ServletWrapper.initialize(ServletWrapper.java:1119)
         at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.initialize(ServletWrapper.java:149)
         at com.ibm.wsspi.webcontainer.extension.WebExtensionProcessor.createServletWrapper(WebExtensionProcessor.java:99)
         at com.ibm.ws.webcontainer.webapp.WebApp.getServletWrapper(WebApp.java:742)
         at com.ibm.ws.webcontainer.webapp.WebApp.initializeTargetMappings(WebApp.java:422)
         at com.ibm.ws.webcontainer.webapp.WebApp.commonInitializationFinish(WebApp.java:275)
         at com.ibm.ws.wswebcontainer.webapp.WebApp.initialize(WebApp.java:272)
         at com.ibm.ws.wswebcontainer.webapp.WebGroup.addWebApplication(WebGroup.java:88)
         at com.ibm.ws.wswebcontainer.VirtualHost.addWebApplication(VirtualHost.java:157)
         at com.ibm.ws.wswebcontainer.WebContainer.addWebApp(WebContainer.java:655)
         at com.ibm.ws.wswebcontainer.WebContainer.addWebApplication(WebContainer.java:608)
         at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:333)
    Regards.
    sur

    I have created a simple applet.
    import java.lang.*;
    import java.awt.*;
    public class jawtex3 extends java.applet.Applet
    public void init()
    add(new Button("One"));
    add(new Button("Two"));
    public Dimension preferredSize()
    return new Dimension(200, 100);
    public static void main(String [] args)
    Frame f = new Frame(" jawtex3");
    jawtex3 ex = new jawtex3();
    ex.init();
    f.add("Center", ex);
    f.pack();
    f.show();
    In this no compilation errors.
    I am getting runtime exception.as Exception in thread "main"java.lang.NoClassDefFound Error: jawtex
    reply me soon.
    thankyou.

  • Java.lang.ClassCastException PortableRemoteObject.narrow(PortableRemoteObje

    Hi,
    I have a problem with a JNDI -lookup() using the CORBA namig system.
    After looking up: System.out.println( lookup("jndi-name") );
    I get an IOR: IOR:0000000000000053524d493a...............
    ok
    then I print out the name and the package of this object:
    Object o = lookup("jndi-name");
    System.out.println("name of o : " + o.getClass().getName());
    System.out.println("package of o : " + o.getClass().getPackage());
    and get:
    name of o : com.sun.corba.ee.impl.corba.CORBAObjectImpl
    package of o : package com.sun.corba.ee.impl.corba
    I expected the type of a Home-Interface, so that i could narrow the object o:
    PortableRemoteObject.narrow( o , classname);
    and the result is a:
    java.lang.ClassCastException
    at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
    at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)........
    What's wrong

    The most likely reason is that the stubs for that home interface are not being found. Double-check your classpath to make sure they are available to the code at runtime.
    -ken

  • ClassCastException while PortableRemoteObject.narrow

    Hello,
    I am getting the ClassCastException when I am narrowing the looked up home object.
    Here is the exception:
    java.lang.ClassCastException
         at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
         at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
         at samples.ejb.client.HelloClient.main(HelloClient.java:50)
    Here is the code :
    try {
    System.out.println("Looking up greeter bean home interface");
    String JNDIName = "HelloGreet";
    System.out.println("Looking up: " + JNDIName);
    Object objref = initContext.lookup(JNDIName);
    System.out.println("Object from the look up -->"+objref);
    home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(objref, HelloHome.class);
    any help appreciated. Thanks in advance
    With Regards,
    J. P. Naidu

    Hi Pullaiah,
    I've same problem with Sun ONE AS (notice that I encounter same problem on J2EE Reference Implementation too).I looked up for a solution everywhere but I did't find it and I'd be very happy if someone could post one.
    Thanks ,
    Fil

  • ClassCastException with PortableRemoteObject.narrow call

    I want to call an ejb component located on a different machine and I can not get it to work. So I tried to deploy it under my version of jboss and try to invoke it. I was able to call it but when I added Context.PROVIDER_URL to my properties I get a classCastException.
    String host = "jnp://localhost:1099";
    props.setProperty(Context.PROVIDER_URL, host);
    I started getting the following exception
    2006-11-03 10:17:18,319 ERROR [STDERR] java.lang.ClassCastException
    2006-11-03 10:17:18,319 ERROR [STDERR]      at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narr
    ow(PortableRemoteObject.java:229)
    2006-11-03 10:17:18,319 ERROR [STDERR]      at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObjec
    t.java:137)
    As soon as I uncomment that props.setProperty(Context.PROVIDER_URL, host);
    line everything works fine.
    I have seen this type of exception before when I tried invoking the ejb on a different computer as well. When I inspect the object with reflection I see that it found the right interface.
    This is my code again:
    Properties props = new Properties();
    props.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.security.jndi.JndiLoginInitialContextFactory");
    props.setProperty(Context.SECURITY_PRINCIPAL, "admin");
    props.setProperty(Context.SECURITY_CREDENTIALS, "admin");
    props.put(javax.naming.Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
    String host = "jnp://localhost:1099";
    props.setProperty(Context.PROVIDER_URL, host);
    ctx = new InitialContext( props );
    Object object = ctx.lookup( "ejb/com/blah/Manager" );
    ManagerRemoteHome home = (ManagerRemoteHome)PortableRemoteObject.narrow ( object, ManagerRemoteHome.class);
    ManagerRemote manager = home.create();
    Thanks

    1099 is the RMI/JRMP Registry. You are using RMI/IIOP. Is this port number really correct?

  • Classcastexception on portableremoteobject narrow

    I was successfully connecting to an EJB on my WebLogic server from a Java
    IDL client using the iiop protocol, cosnaming initialcontextfactory. I'm at
    a loss as to what is different now that is causing this to fail. I'm sure
    it has something to do with how I'm generating the stubs and/or the
    client/server classpath, but can't see what I'm doing wrong now. My steps
    are as follows.
    1) Create the EJB jar (call it jar1) using weblogic.ejbc
    2) Run jar1 through weblogic.ejbc using -idl -iiop, creating jar2
    3) Deploy jar2 in the java client's classpath
    I get the initial context fine, but when I get to this line:
    _home = (myHome)(PortableRemoteObject.narrow(ctx, myHome.class));
    I get the following error:
    java.lang.ClassCastException
    at
    com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemo
    teObject.java:296)
    Can anyone give me some assistance?
    Thx!
    Sandy Barletta

    Ok, here's what's going on here. The problem happens when I use
    com.sun.jndi.cosnaming.CNCtxFactory as my initial context factory. After the
    lookup of the home interface, what I get back in my context object if I call
    getClass().getName() is the following:
    com.sun.jndi.cosnaming.CNCtx
    The class cast exception occurs when I try to narrow this to my home
    interface.
    If I use weblogic.jndi.WLInitialContextFactory instead of
    com.sun.jndi.cosnaming.CNCtxFactory, what I get back in my context object if
    I call getClass().getName() is
    com.sun.corba.se.internal.iiop.CDRInputStream$1 and the narrow succeeds.
    What gives? Do I have to use the weblogic context factory? I was hoping to
    avoid the need for weblogic packages on the client. Also, our whole reason
    for using IIOP was to avoid compatibility problems between weblogic servers
    running at different version levels. If I have to use the weblogic context
    factory, and we have a weblogic client running at a different version from
    the server, will there be problem?
    Sandy Barletta
    "Sandy Barletta" <[email protected]> wrote in message
    news:[email protected]...
    I was successfully connecting to an EJB on my WebLogic server from a Java
    IDL client using the iiop protocol, cosnaming initialcontextfactory. I'mat
    a loss as to what is different now that is causing this to fail. I'm sure
    it has something to do with how I'm generating the stubs and/or the
    client/server classpath, but can't see what I'm doing wrong now. My steps
    are as follows.
    1) Create the EJB jar (call it jar1) using weblogic.ejbc
    2) Run jar1 through weblogic.ejbc using -idl -iiop, creating jar2
    3) Deploy jar2 in the java client's classpath
    I get the initial context fine, but when I get to this line:
    _home = (myHome)(PortableRemoteObject.narrow(ctx, myHome.class));
    I get the following error:
    java.lang.ClassCastException
    at
    com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemo
    teObject.java:296)
    Can anyone give me some assistance?
    Thx!
    Sandy Barletta

  • Why PortableRemoteObject.narrow()

    Hello,
    Can any one please suggest me the difference in looking Up of the components in 2 ways..??
    1) HelloHome home = (HelloHome)ctx.lookup("HelloHome")
    2) Object ref = getInitialContext().lookup(eb/HelloBean);
    HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(ref, HelloHome.class)
    Why we need option 2 when we get a home object when we make a look up as in 1.
    why PortableRemoteObject.narrow()
    Please make ur suggestions.
    Thanks.

    Hi,
    From an article at http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/ejb-tier/ejb-tier9.html
    Type narrowing is needed because many application servers use RMI-IIOP as the communication protocol to access remote beans. However, some application servers do not use RMI-IIOP and hence allow the use of Java language typecasts as well. For portability you cannot rely on an application server allowing Java language typecasts; you should always use the PortableRemoteObject.narrow method. The overhead on this method call is usually quite small
    -Amol

  • PortableRemoteObject.narrow throws ClassCastException

    Hi Friends,
    I am trying to access home interface of a stateless session EJB from an Applet running in JRE 1.3.1 in IE. My EJB is running in WebLogic Server 6.1. I am getting a cast error while narrowing the remote home interface. My server and client are running on the same machine though they are in different JVMs. I was able to access this remote home interface in a simple test program running from command line.
    This session bean accesses other entity beans deployed in the same WebLogic server, if that has anything to do with it.
    Following is the error callstack:
    java.lang.ClassCastException
         at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:296)
         at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
    Any help in resolving this issue will be greatly appreciated.
    Thanks,
    Krishna.

    Hello
    I have same problem in Java Web Start.
    This Situation is same.
    I report the result of my investigation.
    I'm having a problem in lookup remote object when using JWS.
    My application runs normally in Java Application without JWS.
    I'm using BEA WebLogic Server 6.1.
    My application acts in EJB client application.
    But my application runs normally in WebLogic Server 6.0 and JWS.
    When I cast remote object to my interface, I encountered this kind of error.
    java.lang.ClassCastException
    at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow
    at javax.rmi.PortableRemoteObject.narrow
    While using WebLogic Server 6.0, I include stub classes in my jar file.
    But in WebLogic Server 6.1, ejbc does not generate stub classes.
    WebLogic uses Dynamic proxy technology in JDK 1.3 for this purpose.
    So, EJB client conflict with sand box security policy...
    When I add the following line to javaws.policy file,
    my application runs without problem.
    permission java.io.SerializablePermission "enableSubstitution";
    Is everyone suffering from this kind of problem?
    Is this problem improved in the future?
    I need more information about this problem.
    I am not sure, this is specification.
    Thanks in advance
    Hiroki

Maybe you are looking for

  • Lost photos while updating to iOS 5

    First I updated itunes to 10.5, and then I downloaded and installed iOS5 on my iphone 4. Nothing was automatically synced before iOS5 installation, but itunes showed that it was backing up data. After installation, when itunes restored the backup, I

  • Dvd+r burned on a dvd-r imac

    I bought some +r dvds. burned one on my new imac w/the -r burner. seems to work cause i played the dvd in another mac. is this kosher? will this work elsewhere in other dvd players.? what is the basic difference between -r and +r dvds???

  • Cannot find SCANPST.EXE anywhere on my Computer

    Hi, I have two computers one running Windows 7 Ultimate, the other running Windows 8.1 Pro.  I have Office Professional Plus 2013 installed on both. On both compters I an unable to locate the SCANPST.EXE file.  I can find the DLL files in the expecte

  • Cannot run system after enabling SSFS

    Hello, I followed note 1639578 when setting SSFS. I would like to install EHP7 and SSFS connection is prerequisite. Everything went according to steps, but after I set environment variable rsdb_ssfs_connect=1 and profile parameter rsdb/ssfs_connect =

  • Forms9i- Why base on applet?

    Hi every body, Why Forms 9i base on applet? Any one know applet is very slow, could migrate fastly from application developed with Forms9i to application developed with J2EE? Thanks in advanced,