EJB + ClassCastException

what does this error mean
java.lang.ClassCastException: org.apache.tomcat.core.HttpServletRequestFacade?
I get it when I run my custom EJB.
the class files are as follows
Remote Interface:
     package ejbdotone;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
import java.io.PrintWriter;
import java.util.Iterator;
public interface PrintForm extends EJBObject {
     public PrintFormWrapper createForm( HttpServletRequest req )
                                           throws RemoteException;
}Home Interface:
package ejbdotone;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface PrintFormHome extends EJBHome {
                  PrintForm create() throws CreateException, RemoteException;
}Bean Implementation:
package ejbdotone;
import javax.servlet.*;
import javax.servlet.http.*;
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import java.util.Iterator;
import java.io.PrintWriter;
public class PrintFormBean implements SessionBean {
          public PrintFormWrapper createForm( HttpServletRequest req ) {
               String nameStr = req.getParameter("$1");
               String phoneStr = req.getParameter("$2");
               String addStr = req.getParameter("$3");
               PrintFormWrapper wrapper =
                    new PrintFormWrapper(nameStr, phoneStr, addStr);
               return wrapper;
                  public void ejbCreate() { }
                  public void setSessionContext(SessionContext ctx) { }
                  public void ejbRemove() { }
                  public void ejbActivate() { }
                  public void ejbPassivate() { }
                  public void ejbLoad() { }
                  public void ejbStore() { }
}Serialized Wrapper:
package ejbdotone;
import java.io.Serializable;
public class PrintFormWrapper implements Serializable {
     public String name, phone, address;
     public PrintFormWrapper( String name, String phone, String address ) {
          this.name=name;
          this.phone=phone;
          this.address=address;
}Servlet Class:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import ejbdotone.*;
public class PrintFormServlet extends HttpServlet {
     PrintFormHome printHome;
     public void init(ServletConfig config)
               throws ServletException{
          try{
               InitialContext ctx = new InitialContext();
               Object objref = ctx.lookup("formprinter");
               System.out.println("REF: "+objref.getClass());
               printHome =
                    (PrintFormHome)PortableRemoteObject.narrow(
                                        objref, PrintFormHome.class);
               System.out.println("HOME: "+printHome.getClass());
          } catch (Exception NamingException) {
               System.out.println("INIT: "+ NamingException );
        public void doGet ( HttpServletRequest request,
                                      HttpServletResponse response)
                                      throws ServletException, IOException {
          PrintWriter out;
          response.setContentType("text/html");
          out = response.getWriter();
          try{
               PrintForm printer;
               printer = (PrintForm)printHome.create();
               System.out.println("REMOTE: "+printer.getClass());
               PrintFormWrapper wrapper =
                    (PrintFormWrapper)printer.createForm( request );
               System.out.println("WRAPPER: "+wrapper.getClass());
               out.println(wrapper.name);
               out.println(wrapper.phone);
               out.println(wrapper.address);
          } catch(Exception CreateException){
               System.out.println("doGet: "+CreateException);
          } finally {
               if(out != null) {
                    out.close();
          if(out != null) {
               out.close();
     public void destroy() {                 
          System.out.println("Destroy");
}When I run it it prints out the following to stderr:
REF: class ejbdotone._PrintFormHome_Stub
HOME: class ejbdotone._PrintFormHome_Stub
REMOTE: class ejbdotone._PrintForm_Stub
and then the class-cast error message from above.
This is my first EJB away from the tutorial. It is a stateless session bean. It verifies and deploys with no errors through the deploytool.
Any help will be much appreciated.
Thank you,
Ian

Here it is:
java.lang.ClassCastException: org.apache.tomcat.core.HttpServletRequestFacade
     at ejbdotone._PrintForm_Stub.createForm(Unknown Source)
     at PrintFormServlet.doGet(PrintFormServlet.java:40)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
     at org.apache.tomcat.core.ServiceInvocationHandler.method(ServletWrapper.java:626)
     at org.apache.tomcat.core.ServletWrapper.handleInvocation(ServletWrapper.java:534)
     at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:378)
     at org.apache.tomcat.core.Context.handleRequest(Context.java:644)
     at org.apache.tomcat.core.ContextManager.service(ContextManager.java:440)
     at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:144)
     at org.apache.tomcat.service.TcpConnectionThread.run(TcpEndpoint.java:310)
     at java.lang.Thread.run(Thread.java:484)

Similar Messages

  • EJB ClassCastException Retrieving from Collection in same AppServer

    I am experiencing a weired Problem.
    I am passing a Collection of IdNameTO Transfer Object from My EJB Client(JSP) to EJB.
    At Server Side EJB is able to get the Object From Collection but when it does a Cast to convert the Object back to IdNameTO I get ClassCastException on IdNameTO.
    This problem happend only when Both Client and Server(EJB) are deployed on Same Application Server(WebSphere) i.e. same Virtual Machine. If Both Client and EJB are deployed on separate Servers then I don;t get any Exception.
    If I form a collection of IdNameTO in EJB and pass it to EJB Client then even on same Server I don't get any exception.

    I am experiencing a weired Problem.
    I am passing a Collection of IdNameTO Transfer Object from My EJB Client(JSP) to EJB.
    At Server Side EJB is able to get the Object From Collection but when it does a Cast to convert the Object back to IdNameTO I get ClassCastException on IdNameTO.
    This problem happend only when Both Client and Server(EJB) are deployed on Same Application Server(WebSphere) i.e. same Virtual Machine. If Both Client and EJB are deployed on separate Servers then I don;t get any Exception.
    If I form a collection of IdNameTO in EJB and pass it to EJB Client then even on same Server I don't get any exception.

  • Urgente!!  EJB, ClassCastException and ClassLoaders

    Hi,
    I'm using Jboss3.2.2RC4. My project has ear1 and ear2 applications. The servlet from ear1 has to use ejbs from ear2. The ejb-client.jar is setted in Manifes file. All works fine if i deploy ear1 and ear2 simultaneously. But if i redeploy ear2 without redeploy ear1, i get ClassCastException on PortableRemoteObject.narrow.
    I think this is a classloader problem because of the j2ee classloader architecture. I read many topics about this. But i suppose there is an alternative solution for this type of project. I don't believe I need to redeploy two ears always i change my ejbs. This is not a good solution.
    I'm searching for people who solved this problem in some way.
    Can someone help me with urgence?
    Thanks in advance!!

    Many thanks for your reply! Let me try to explain better how is my project.
    My ear1 application has:
    - CoreEJB.jar (some ejbs that don't use external classes)
    - Core.war
    - some jsp files
    - web.xml
    - jboss-web.xml
    - WEB-INF
    - classes
    - MainServlet (it uses the external ejbs from ear2)
    - lib
    - my-util.jar (it is used only by the servlet)
    - standard.jar (tag library for jsp pages)
    My ear2 has:
    - UserEJB.jar
    - UserEJBean.class (the ejb class - no interface)
    - ejb-jar.xml
    - jboss.xml
    - MANIFEST.MF (here i put : Class-Path: lib/UserEJB-Client.jar)
    - UserModule.war
    - some jsp files
    - jboss-web.xml
    - web.xml
    - lib
    - UserEJB-Client.jar (interfaces only)
    - UserEJB.class
    - UserEJBHome.class
    - application.xml
    My Servlet try to access ejb as following (method service):
         InitialContext jndiContext = new InitialContext();
         Object ref = jndiContext.lookup("UserEJB");
         Object x = PortableRemoteObject.narrow (ref,UserEJBHome.class);
         UserEJBHome home = (UserEJBHome) x;
         UserEJB user = home.create();
         String resp = user.getName();
    If i deploy ear1 and ear2, it works. If i redeploy ear2 without redeploy ear1, i get the following exception:
    Deployed package: file:/usr/local/jboss-3.2.2RC4/server/default/deploy/User.ear
    14:08:26,941 ERROR [STDERR] java.lang.ClassCastException
    14:08:26,942 ERROR [STDERR] at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
    14:08:26,943 ERROR [STDERR] at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
    14:08:26,943 ERROR [STDERR] at framework.web.servlet.MainServlet.service(MainServlet.java:79)
    14:08:26,943 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    14:08:26,943 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
    14:08:26,943 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
    14:08:26,943 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
    14:08:26,943 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    But, if after the exception i redeploy ear1, the exception doesn't occurr again.
    I'm not sure if the manifest entry is correct. I used the instructions in http://jboss.sourceforge.net/doc-24/ch11s72.html to create it.
    Did the above description clarify my project and my problem?
    Thanks!

  • EJB called via JNDI in a Repository Service :: ClassCastException

    Hi SDN,
    I've got a problem in calling an EJB from a Repository Service...
    Here the steps I've follow:
      -  An EJB has been created with some Business Methods in it; it has been packaged in an EAR and deployed;
      -  This EJB is looked up succesfully via JNDI in a WDJ application and also in an Abstract Portal Component; I use the following guides:
    [Accessing EJB Apps using JNDI|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/0736159e-0301-0010- 9ea4-c63d83d0797b?QuickLink=index&overridelayout=true]
    [Referencing an EJB in an Abstract Portal Component|http://wiki.sdn.sap.com/wiki/display/HOME/ConnectingEJBUsing ExternalJars]
      -  A Repository Service has been created and registered on "CREATE_CHILD_TEMPLATE" ResourceEvent; I can see from logs that this service works correctly;
       -  I've copied in the PAR lib and private/lib folders two jars (ejb20.jar and the JAR created building the EJB) and they are added to the build path;
      -  If I try to look up the EJB via JNDI in the received service method, I get a ClassCastException...
    Here some code:
    try {
         //I use System.err to see log in the Default Trace
         System.err.println("Initialize EJB");
         //TestJNDIHome class seems to be visible at runtime, following instruction does not throw any exception
         System.err.println("ToString TestJNDIHome: " + TestJNDIHome.class.toString());
         //EJB and PAR are on the same J2EE engine, so no InitialContext parameters, I'm right?
         InitialContext context = new InitialContext();
         Object jndiobj = context.lookup("altevie.com/testear/TestJNDIBean");
         System.err.println("Classe oggetto recuperato da lookup: " + jndiobj.getClass());
         TestJNDIHome home = (TestJNDIHome) javax.rmi.PortableRemoteObject.narrow(jndiobj, TestJNDIHome.class);
         testJNDI = home.create();
    } catch (NamingException ex) {
         System.err.println("NamingException :: " + ex.getLocalizedMessage());
    } catch (RemoteException ex) {
         System.err.println("RemoteException :: " + ex.getLocalizedMessage());
    } catch (CreateException ex) {
         System.err.println("CreateException :: " + ex.getLocalizedMessage());          
    Here the portalapp.xml (in the same PAR there are two objects, the Repository Service and an Abstract Portal Component, but I've got the same problem also removing the Abstract Portal Component...):
    <application>
      <application-config>
        <property name="com.sap.engine.interfaces.cross.ObjectReferenceImpl" value="SAPJ2EE::altevie.com/testEAR"/>
        <property name="SharingReference" value="usermanagement, knowledgemanagement, landscape, htmlb, exportalJCOclient, exportal"/>
        <property name="PrivateSharingReference" value="SAPJ2EE::altevie.com/testEAR"/>
      </application-config>
      <components>
        <component name="TestJSP">
          <component-config>
            <property name="ClassName" value="com.comer.eps.epcomp.TestJSP"/>
          </component-config>
          <component-profile/>
        </component>
      </components>
      <services>
        <service name="RFServiceWrapper">
          <service-config>
            <property name="className" value="com.sap.netweaver.rf.wrapper.RFServiceWrapper"/>
            <property name="startup" value="true"/>
          </service-config>
        </service>
      </services>
    </application>
    javax.rmi.PortableRemoteObject.narrow method call throws a ClassCastException...
    From the previous println I can see the lookup method returns a com.sap.engine.interfaces.cross.ObjectReferenceImpl object, I do not know if it is correct...
    I've tried to lookup the Local (localejbs/altevie.com/testear/TestJNDIBean) and Remote (altevie.com/testear/TestJNDIBean) JNDI Bean name, but I get the same error...
    I'm sure the JNDI name is correct (it works with WDJ and Abstract Portal Component... I've also tested via LOOKUP command using telnet to connect to J2EE AS and I've checked JNDI Registry and EJB Container services in Visual Admin)...
    Here the stack trace of the error:
    java.lang.ClassCastException: com.comer.eps.ejb.AccessiEJBHome
         at com.sap.engine.services.cross.PortableRemoteObjectContainer.narrow(PortableRemoteObjectContainer.java:179)
         at com.sap.engine.system.PortableRemoteObjectProxy.narrow(PortableRemoteObjectProxy.java:24)
         at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
         at com.comer.eps.repsrv.onsave.RipubblicaByDE.initializeEJB(RipubblicaByDE.java:145)
    Can you help me? Why JNDI lookup works in an Abstract Portal Application and doesn't in a Repository Service (same code...)?
    Thank you so much and best regards,
    Manuel
    Text Formatted: Manuel Xiccato on Sep 27, 2011 12:29 PM

    Hi SDN,
    I've got a problem in calling an EJB from a Repository Service...
    Here the steps I've follow:
      -  An EJB has been created with some Business Methods in it; it has been packaged in an EAR and deployed;
      -  This EJB is looked up succesfully via JNDI in a WDJ application and also in an Abstract Portal Component; I use the following guides:
    [Accessing EJB Apps using JNDI|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/0736159e-0301-0010- 9ea4-c63d83d0797b?QuickLink=index&overridelayout=true]
    [Referencing an EJB in an Abstract Portal Component|http://wiki.sdn.sap.com/wiki/display/HOME/ConnectingEJBUsing ExternalJars]
      -  A Repository Service has been created and registered on "CREATE_CHILD_TEMPLATE" ResourceEvent; I can see from logs that this service works correctly;
       -  I've copied in the PAR lib and private/lib folders two jars (ejb20.jar and the JAR created building the EJB) and they are added to the build path;
      -  If I try to look up the EJB via JNDI in the received service method, I get a ClassCastException...
    Here some code:
    try {
         //I use System.err to see log in the Default Trace
         System.err.println("Initialize EJB");
         //TestJNDIHome class seems to be visible at runtime, following instruction does not throw any exception
         System.err.println("ToString TestJNDIHome: " + TestJNDIHome.class.toString());
         //EJB and PAR are on the same J2EE engine, so no InitialContext parameters, I'm right?
         InitialContext context = new InitialContext();
         Object jndiobj = context.lookup("altevie.com/testear/TestJNDIBean");
         System.err.println("Classe oggetto recuperato da lookup: " + jndiobj.getClass());
         TestJNDIHome home = (TestJNDIHome) javax.rmi.PortableRemoteObject.narrow(jndiobj, TestJNDIHome.class);
         testJNDI = home.create();
    } catch (NamingException ex) {
         System.err.println("NamingException :: " + ex.getLocalizedMessage());
    } catch (RemoteException ex) {
         System.err.println("RemoteException :: " + ex.getLocalizedMessage());
    } catch (CreateException ex) {
         System.err.println("CreateException :: " + ex.getLocalizedMessage());          
    Here the portalapp.xml (in the same PAR there are two objects, the Repository Service and an Abstract Portal Component, but I've got the same problem also removing the Abstract Portal Component...):
    <application>
      <application-config>
        <property name="com.sap.engine.interfaces.cross.ObjectReferenceImpl" value="SAPJ2EE::altevie.com/testEAR"/>
        <property name="SharingReference" value="usermanagement, knowledgemanagement, landscape, htmlb, exportalJCOclient, exportal"/>
        <property name="PrivateSharingReference" value="SAPJ2EE::altevie.com/testEAR"/>
      </application-config>
      <components>
        <component name="TestJSP">
          <component-config>
            <property name="ClassName" value="com.comer.eps.epcomp.TestJSP"/>
          </component-config>
          <component-profile/>
        </component>
      </components>
      <services>
        <service name="RFServiceWrapper">
          <service-config>
            <property name="className" value="com.sap.netweaver.rf.wrapper.RFServiceWrapper"/>
            <property name="startup" value="true"/>
          </service-config>
        </service>
      </services>
    </application>
    javax.rmi.PortableRemoteObject.narrow method call throws a ClassCastException...
    From the previous println I can see the lookup method returns a com.sap.engine.interfaces.cross.ObjectReferenceImpl object, I do not know if it is correct...
    I've tried to lookup the Local (localejbs/altevie.com/testear/TestJNDIBean) and Remote (altevie.com/testear/TestJNDIBean) JNDI Bean name, but I get the same error...
    I'm sure the JNDI name is correct (it works with WDJ and Abstract Portal Component... I've also tested via LOOKUP command using telnet to connect to J2EE AS and I've checked JNDI Registry and EJB Container services in Visual Admin)...
    Here the stack trace of the error:
    java.lang.ClassCastException: com.comer.eps.ejb.AccessiEJBHome
         at com.sap.engine.services.cross.PortableRemoteObjectContainer.narrow(PortableRemoteObjectContainer.java:179)
         at com.sap.engine.system.PortableRemoteObjectProxy.narrow(PortableRemoteObjectProxy.java:24)
         at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
         at com.comer.eps.repsrv.onsave.RipubblicaByDE.initializeEJB(RipubblicaByDE.java:145)
    Can you help me? Why JNDI lookup works in an Abstract Portal Application and doesn't in a Repository Service (same code...)?
    Thank you so much and best regards,
    Manuel
    Text Formatted: Manuel Xiccato on Sep 27, 2011 12:29 PM

  • Tutorial "Using EJBs in Web Dynpro Applications" ClassCastException

    Hi,
    I went through the tutorial "Using EJBS in WebDynpro Applications" step-by-step.
    If I run the application I always get the following error message:
    java.lang.ClassCastException:com.sap.engine.interfaces.cross.ObjectReferenceImpl
    if I try to make a lookup to the SessionBean.
    I use the following code:
    InitialContext ctx = new InitialContext();
    facadeHome = (FacadeHome) ctx.lookup("FacadeBean"); <- the error is related to this line
    facade = facadeHome.create();
    I have nothing more to provide to be more specifiv.
    What did I forget to specify or to define?
    Thanks for any help.

    Hi holger,
    try to do it like this
    InitialContext ctx = new InitialContext();
    Object obj = ctx.lookup("FacadeBean");//where FacadeBean                  is your jndi name
    facadeHome = (FacadeHome)PortableRemoteObject.narrow                                                 (obj,FacadeHome.class);
    facade = facadeHome.create();
    hope this helps,
    regards,
    rahul.

  • ClassCastException when I access an EJB from a remote EJB in WL 8.1

    I am using WebLogic 8.1 and am trying to lookup the home interface for an EJB (_ejbRemote_)
    from another EJB (_ejbCurrent_). They are deployed in seperate EARs. When I bundle
    the home and remote interfaces for ejbRemote in the EAR file that ejbCurrent
    is deployed in, everything works fine. But I need to be able to configure ejbRemote
    at run time and my customers don't want to have to bundle their classes in my
    EAR. So I invoke a custom classloader (of type java.net.URLClassLoader) that will
    load the home and remote interface classes for ejbRemote from a configurable
    location at runtime. This finds the classes no problem, and the InitialContext.lookup()
    returns a stub, but I get a 'java.lang.ClassCastException: Cannot narrow remote
    object' error when I call PortableRemoteObject.narrow(home, homeClass);
    The code looks like:
    // Assume EJBHomeStr = "com.foo.TestHome" in this case
    // Load the home interface class. This works.
    Class homeClass = urlClassLoader.loadClass(EJBHomeStr);
    // Lookup the home interface. This works.
    Object lookedUpHomeObject = initialContext.lookup(JNDIName);
    // This fails.
    Object homeObject = PortableRemoteObject.narrow(lookedUpHomeObject, homeClass);
    And the weblogic error looks like
    ... ; nested exception is:
    java.lang.ClassCastException: Cannot narrow remote object to com.foo.TestHome
    at weblogic.iiop.PortableRemoteObjectDelegateImpl.narrow(PortableRemoteO
    bjectDelegateImpl.java:219)
    at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
    at ...[the rest is just my application code stack...]
    When I log the ClassLoaders for the affected objects, using getClass().getClassLoader(),
    I get:
    <snippet from log follows>
    getClass().getClassLoader(): weblogic.utils.classloaders.GenericClassLoader@667da1
    finder:
    weblogic.utils.classloaders.MultiClassFinder@db9199 annotation: myEJBApp@
    homeClass.getName(): com.foo.TestHome classloader = java.net.URLClassLoader@4f1707
    lookedUpHomeObject.getClass().getName(): com.foo.Test_EJB_kx82zy_HomeImpl_810_WLStub
    classloader = weblogic.utils.classloaders.GenericClassLoader@667da1
    finder: weblogic.utils.classloaders.MultiClassFinder@db9199 annotation: myEJBApp@
    <end snippet from log>
    So it appears that since the looked up Stub was loaded by the WebLogic classloader
    and the actual Home class was loaded by my URLClassLoader, the narrow() can't
    reconcile the two. I have tried both rmic and the Weblogic appc command to pre-generate
    the stubs, which I put in the same JAR as my home and remote interface classes
    and load with my custom classloader. But the standard stub (generated by either
    rmic or appc) is named TestHomeStub.class and Weblogic is ignoring those and
    making a class with the name Test_EJB_kx82zy_HomeImpl_810_WLStub, as shown above.
    I have also tried to put the remote interface classes and stubs in the System
    classpath using the -classpath option when I start WebLogic, but same result.
    The question is, Is there a way in WebLogic to communicate with a remote EJB in
    a seperate EAR without bundling anything about that remote EAR in my EAR? Or is
    there something I've missed? I need to keep my application J2EE compliant, meaning
    I can't hardcode any AppServer-specific code in my application.
    Thanks.

    Hi Jon,
    Glad to hear that.
    Regards,
    Slava Imeshev
    "Jon Sutula" <[email protected]> wrote in message news:[email protected]...
    >
    I fixed the problem. It turns out I didn't need to use a custom classloader at
    all, I just use Reflection directly on the classes ruturned from my JNDI lookup.
    So when I lookup the home class, I don't need to narrow or cast it, I just use
    Reflection to invoke the "create" method. Then I use the object that I get from
    create and directly invoke whatever method on it I need, again using Reflection.
    And that works.
    "Slava Imeshev" <[email protected]> wrote:
    Hi Jon,
    The problem is, this class is not available for the classloader
    running your "main code".
    You can try to hack the into the thread context class loader:
    Thread thread = Thread.currentThread();
    ContextClassLoader originalClassLoader = thread.getContextClassLoader();
    try {
    YourURLClassloader yourClassLoader = new
    YourURLClassloader(originalClassLoader);
    thread.setContextClassLoader(yourClassLoader );
    // your code goes here
    } finally {
    // Don't forget to restore it !!!
    thread.setContextClassLoader(originalClassLoader);
    Be very cautious. If you fail to restore the original context class loader,
    you will likely have to restart the server.
    Hope this helps.
    Regards,
    Slava Imeshev
    "Jon Sutula" <[email protected]> wrote in message news:[email protected]...
    I am using WebLogic 8.1 and am trying to lookup the home interfacefor an EJB (_ejbRemote_)
    from another EJB (_ejbCurrent_). They are deployed in seperate EARs.When I bundle
    the home and remote interfaces for ejbRemote in the EAR file that
    ejbCurrent
    is deployed in, everything works fine. But I need to be able to configure
    ejbRemote
    at run time and my customers don't want to have to bundle their classesin my
    EAR. So I invoke a custom classloader (of type java.net.URLClassLoader)that will
    load the home and remote interface classes for ejbRemote from a configurable
    location at runtime. This finds the classes no problem, and the InitialContext.lookup()
    returns a stub, but I get a 'java.lang.ClassCastException: Cannot narrowremote
    object' error when I call PortableRemoteObject.narrow(home, homeClass);
    The code looks like:
    // Assume EJBHomeStr = "com.foo.TestHome" in this case
    // Load the home interface class. This works.
    Class homeClass = urlClassLoader.loadClass(EJBHomeStr);
    // Lookup the home interface. This works.
    Object lookedUpHomeObject = initialContext.lookup(JNDIName);
    // This fails.
    Object homeObject = PortableRemoteObject.narrow(lookedUpHomeObject,homeClass);
    And the weblogic error looks like
    ... ; nested exception is:
    java.lang.ClassCastException: Cannot narrow remote object tocom.foo.TestHome
    at weblogic.iiop.PortableRemoteObjectDelegateImpl.narrow(PortableRemoteO
    bjectDelegateImpl.java:219)
    at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
    at ...[the rest is just my application code stack...]
    When I log the ClassLoaders for the affected objects, using getClass().getClassLoader(),
    I get:
    <snippet from log follows>
    getClass().getClassLoader(): weblogic.utils.classloaders.GenericClassLoader@667da1
    finder:
    weblogic.utils.classloaders.MultiClassFinder@db9199 annotation: myEJBApp@
    homeClass.getName(): com.foo.TestHome classloader = java.net.URLClassLoader@4f1707
    lookedUpHomeObject.getClass().getName(): com.foo.Test_EJB_kx82zy_HomeImpl_810_WLStub
    classloader = weblogic.utils.classloaders.GenericClassLoader@667da1
    finder: weblogic.utils.classloaders.MultiClassFinder@db9199 annotation:myEJBApp@
    <end snippet from log>
    So it appears that since the looked up Stub was loaded by the WebLogicclassloader
    and the actual Home class was loaded by my URLClassLoader, the narrow()can't
    reconcile the two. I have tried both rmic and the Weblogic appc commandto pre-generate
    the stubs, which I put in the same JAR as my home and remote interfaceclasses
    and load with my custom classloader. But the standard stub (generatedby either
    rmic or appc) is named TestHomeStub.class and Weblogic is ignoringthose and
    making a class with the name Test_EJB_kx82zy_HomeImpl_810_WLStub, asshown above.
    I have also tried to put the remote interface classes and stubs inthe System
    classpath using the -classpath option when I start WebLogic, but sameresult.
    The question is, Is there a way in WebLogic to communicate with a remoteEJB in
    a seperate EAR without bundling anything about that remote EAR in myEAR? Or is
    there something I've missed? I need to keep my application J2EE compliant,meaning
    I can't hardcode any AppServer-specific code in my application.
    Thanks.

  • ClassCastException exception while running EJB Client

    Folks,
    I am getting following exception while running the EJB Client.. I am
    using WLS 5.1
    Exception in thread "main" java.lang.ClassCastException
    at
    javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:319)
    at FirstStatelessEJBClient.Client.lookupHome(Client.java:149)
    at FirstStatelessEJBClient.Client.<init>(Client.java:44)
    at FirstStatelessEJBClient.Client.main(Client.java:82)
    Can anybody throw a light on this.
    Thanks
    Ashish

    Hi Eduardo,
    Below is my classpath. The stubs are in first_statlessSession.jar file.
    CLASSPATH=C:\weblogic\myserver\first_statelessSession.jar;
    C:\jdk1.2.2\lib\tools.jar;C:\weblogic\license;C:\weblogic\classes;C:\weblogi
    c\lib\weblogicaux.jar;
    C:\weblogic\myserver\clientclasses;C:\weblogic\myserver\serverclasses
    Also, I am just compiling and deploying the
    C:\weblogic\examples\ejb\basic\statelessSession myself and testing it. I
    am
    using the build.cmd files to compile and deploy the above EJB. If I use the
    jars provided by weblogic it works fine with same above classpath.
    I don't know what to do next. I have invested the whole day to solve this
    problem and couldn't.
    Please let me know if I am doing anything wrong.
    Appreciate your help.
    Thanks,
    Ashish
    Eduardo Ceballos wrote:
    Try putting the stubs into the client class path.
    "Ashish N. Shah" wrote:
    Folks,
    I am getting following exception while running the EJB Client.. I am
    using WLS 5.1
    Exception in thread "main" java.lang.ClassCastException
    at
    javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:319)
    at FirstStatelessEJBClient.Client.lookupHome(Client.java:149)
    at FirstStatelessEJBClient.Client.<init>(Client.java:44)
    at FirstStatelessEJBClient.Client.main(Client.java:82)
    Can anybody throw a light on this.
    Thanks
    Ashish

  • Java.lang.ClassCastException in EJB's

    Friends Need your suggestions on the following:-
    1. try {
    2.     InitialContext ctx = new InitialContext();
    3.     Object objref = ctx.lookup("ejb/test/MyTestSessionBean");
    4.     testSessionBean = (MyTestSessionHome) PortableRemoteObject.narrow(
    5.               objref, MyTestSessionHome.class);
    6. } catch (Exception NamingException) {
    7.      NamingException.printStackTrace();
    8. }
    I am unable to understand as to why I am getting an exception at line 4.
    The exception is:-
    11:21:56,649 ERROR [STDERR] java.lang.ClassCastException
    11:21:56,649 ERROR [STDERR] at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:
    293)
    11:21:56,649 ERROR [STDERR] at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
    11:21:56,649 ERROR [STDERR] at test.session.SessionTestServlet.init(SessionTestServlet.java:29)
    11:21:56,649 ERROR [STDERR] at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1105)
    11:21:56,649 ERROR [STDERR] at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:932)
    11:21:56,649 ERROR [STDERR] at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3917)
    11:21:56,649 ERROR [STDERR] at org.apache.catalina.core.StandardContext.start(StandardContext.java:4201)
    The above exception comes as soon as I deploy my ear to deploy folder in JBOSS.
    Thanks,
    Vishal

    I was facing the same proble. Simply diasble packaging class files in war file and the problem will be solved. Check build xml...I have commecnted class file addition in war file......Hope it solve your problem....I am beginer in Java technology...so dont hope expert repy from me in case your problem is still not solved....
    <?xml version="1.0"?>
    <!-- ==================================================== -->
    <!-- Build file for our first web application -->
    <!-- build.xml, Saturday, July 20, 2002 -->
    <!-- Author: Deepak Kumar -->
    <!-- Email : [email protected] -->
    <!-- Url : http://www.roseindia.net -->
    <!-- ==================================================== -->
    <project name="Jboss 3.0 tutorial series" default="all" basedir=".">
         <path id="build.classpath">
              <fileset dir="D:/JBOSS-4.0.4/server/default/lib/">
                   <include name="*.jar"/>
              </fileset>
         </path>
         <target name="init">
              <property name="dirs.base" value="${basedir}"/>
              <property name="classdir" value="${dirs.base}/build/src"/>
              <property name="src" value="${dirs.base}/src"/>
              <property name="web" value="${dirs.base}/web"/>
              <property name="deploymentdescription" value="${dirs.base}/deploymentdescriptors"/>
              <property name="warFile" value="example3.war"/>
              <property name="earFile" value="example3.ear"/>
              <property name="jarFile" value="example3.jar"/>
              <property name="earDir" value="${dirs.base}/build/ear"/>
              <property name="warDir" value="${dirs.base}/build/war"/>
              <property name="jarDir" value="${dirs.base}/build/jar"/>
              <!-- Create Web-inf and classes directories -->
              <mkdir dir="${warDir}/WEB-INF"/>
              <mkdir dir="${warDir}/WEB-INF/classes"/>
              <!-- Create Meta-inf and classes directories -->
              <mkdir dir="${earDir}/META-INF"/>
              <mkdir dir="${jarDir}/META-INF"/>
         </target>
         <!-- Main target -->
         <target name="all" depends="init,build,buildWar,buildJar,buildEar"/>
         <!-- Compile Java Files and store in /build/src directory -->
         <target name="build" >
              <javac srcdir="${src}" destdir="${classdir}" classpathref="build.classpath" debug="on" includes="**/*.java" />
         </target>
         <!-- Create the web archive File -->
         <target name="buildWar" depends="init">
    <!--          <copy todir="${warDir}/WEB-INF/classes">
                   <fileset dir="${classdir}" includes="**/*.class" />
              </copy>
    -->     
              <copy todir="${warDir}/WEB-INF">
                   <fileset dir="${deploymentdescription}/web/" includes="web.xml,jboss-web.xml" />
              </copy>
              <copy todir="${warDir}">
                   <fileset dir="${web}" includes="**/*.*" />
              </copy>
              <!-- Create war file and place in ear directory -->
              <jar jarfile="${earDir}/${warFile}" basedir="${warDir}" />
         </target>
         <!-- Create the jar File -->
         <target name="buildJar" depends="init">
              <copy todir="${jarDir}">
                   <fileset dir="${classdir}" includes="**/*.class" />
              </copy>
              <copy todir="${jarDir}/META-INF">
                   <fileset dir="${deploymentdescription}/jar/" includes="ejb-jar.xml,jboss.xml" />
              </copy>
              <!-- Create jar file and place in ear directory -->
              <jar jarfile="${earDir}/${jarFile}" basedir="${jarDir}" />
         </target>
         <!-- Create the ear File -->
         <target name="buildEar" depends="init">
              <copy todir="${earDir}/META-INF">
                   <fileset dir="${deploymentdescription}/ear" includes="application.xml" />
              </copy>
              <!-- Create ear file and place in ear directory -->
              <jar jarfile="${basedir}/${earFile}" basedir="${earDir}" />
         </target>
    </project>

  • Java.lang.ClassCastException in Servle while using EJB

    I m trying to get a ejb instant in a servlet.I am using Blazix EJB server as a EJB contianer and Blazix Web server as servlet container.I get a java.lang.ClassCastException.
    I m using Demo bean with DemoHome as home interface and DemoBean as EJB name.
    The servlet code contains....
    Context initial = getInitialContext();
    Object objref = initial.lookup("DemoBean");
    DemoHome dhome =(DemoHome)PortableRemoteObject.narrow(objref,DemoHome.class);
                   demo = dhome.create();
    The printStackTrace is as follows
    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 BeanServlet.init(BeanServlet.java:30)
    at desisoft.server.servlets.Servlet.init(Servlet.java:52)
    at desisoft.server.servlets.Context.getServletInstance(Context.java:1783
    at desisoft.server.servlets.Context.getContextInternalDispatcher(Context.java:2583)
    at desisoft.server.servlets.Context.getContextDispatcher(Context.java:2402)
    at desisoft.server.servlets.Context.getDispatcher(Context.java:2212)
    at desisoft.server.common.HttpStream.processRequest(HttpStream.java:617)
    at desisoft.server.conn.ServerThread.run(ServerThread.java:335)
    So please help me
    Regards
    Pravin

    I am having a similar issue with stratightforward client code ...
    I set properties values
    java.naming.provider.url=iiop://officepc:3700
    java.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory
    java.naming.factory.url.pkgs=com.sun.enterprise.naming
    in a properties file.
    When "Object objref = jndiContext.lookup( resourceId ) "
    returns,objref is resolved as a "com.sun.corba.se.internal.iiop.CDRInputStream_1_0$1"
    instance. The "resourceId" is a String jndi-name for a Session Bean reference.
    When the "javax.rmi.PortableRemoteObject.narrow((java.lang.Object) objref, CartHome.class )"
    is called, the stack dumps:
    java.lang.ClassCastException
    at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
    at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
    Any thoughts? I have tried everything, I think.
    HW

  • ClassCastException at narrow (Servlet/EJB)

    Hi
    I am new to this EJB concept.
    I try to use an EJB in a servlet but I have a ClassCastException thrown by the narrow method.
    I've already looked through the forums , but I haven't seen a solution for me.
    I use JBOSS-3.0.8 and TOMCAT-4.0.1.
    I include the client jar file generated by the deploytool in my client classpath.
    Here is the part of the servlet calling the EJB:
    Properties props= new Properties();
    props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
    props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
    try {
    Context jndiContext = new InitialContext(props);
    System.out.println("Lookup");
    Object object = jndiContext.lookup("ejb/eltUtil");
    System.out.println("Object =>" + object.getClass()+"<=");
    System.out.println("Object =>" + object.toString()+"<=");
    System.out.println("PortableRemoteObject");
    UtilHome lUtilHome = (UtilHome)PortableRemoteObject.narrow(object,UtilHome.class);
    Here is the result in the jsp page:
    java.lang.ClassCastException
         at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:296)
         at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
         at fr.gouv.defense.cimd.authentification.servlet.ServletListeUtil.doGet(ServletListeUtil.java:87)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1011)
         at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1106)
         at java.lang.Thread.run(Thread.java:484)
    And the log message in Tomcat:
    Lookup
    Object =>class org.jnp.interfaces.MarshalledValuePair<=
    Object =>org.jnp.interfaces.MarshalledValuePair@53cdaa<=
    PortableRemoteObject
    When I run the code in a Client interface in Eclipse, that works and the log is :
    Lookup
    Objet =>class $Proxy0
    Objet =>ejb/eltUtilHome
    PortableRemoteObject
    I don't know what to do.
    Does anybody got the answer?
    Thanks.

    even if isAssignableFrom returns false, still it can work.....
    here is how
    Object notificationServiceObject = initialContext.lookup(NotificationServiceHome.JNDI_NAME);          
    //Key Step
    Object notificationServiceRawObject = ((org.jnp.interfaces.MarshalledValuePair)
    notificationServiceObject).get();
    NotificationServiceHome notificationServiceHome =
              (NotificationServiceHome)javax.rmi.PortableRemoteObject.narrow
    (notificationServiceRawObject,NotificationServiceHome.class);
    NotificationService notificationService = notificationServiceHome.create();

  • ClassCastException using EJB from a service

    Hi all,
    I developed a DeployService and currently I'm getting a ClassCastException while accessing the a EJB.
    I put the lookup within a delegate which is also be used from a webDynpro application. With the WebDynpro App everything work properly, but if I call the delegate from the service a SAPClassCastException I thrown, when I cast the object to the home interface.
    The coding is as follows:
                   Properties props = new Properties();
                   props.put(Context.PROVIDER_URL,"localhost:50004");
                   props.put(Context.INITIAL_CONTEXT_FACTORY,
                   "com.sap.engine.services.jndi.InitialContextFactoryImpl");
                   context = new InitialContext(props);
                   Object obj = context.lookup(jndiName);
                   EJBHome ejb = EJBHomeFactory.getInstance().lookup(jndiName, ComponentHome.class);
                   ComponentHome componentHome = (ComponentHome)ejb;
    Thanks a lot for the help.
    Falk

    Hi Falk,
    Hey just tell me that what is the EJBHome and ComponentHome and EJBHomeFactory in your coding.....
    You can try the following code for the same.
    Object obj =(Object) jndicontext.lookup("<Your JNDI name>");
    TestEJBHome home = (TestEJBHome) javax.rmi.PortableRemoteObject.narrow(
                   obj,
                   TestEJBHome.class);
    TestEJB hello = home.create();
    Here, TestEJBHome is your Home interface of the EJB and TestEJB is your remote interface. Now you can use hello object to call your business methods of EJB.
    Regards,
    Bhavik

  • Java.lang.ClassCastException: examples.ejb.basic.statefulSession.TraderBeanHomeImpl_ServiceStub

    I am using the example from the XML/HTTP which uses a client, servlet and request
    handler. The Servlet calls the StatefulSession TraderHome Bean.
    I am getting the following: java.lang.ClassCastException: examples.ejb.basic.statefulSession.TraderBeanHomeImpl_ServiceStub.
    Anyboy have a similar problem?
    This works with the Client prg in the ejb/basic/StatefulSssion "Client" It works
    correctly

    I am using the example from the XML/HTTP which uses a client, servlet and request
    handler. The Servlet calls the StatefulSession TraderHome Bean.
    I am getting the following: java.lang.ClassCastException: examples.ejb.basic.statefulSession.TraderBeanHomeImpl_ServiceStub.
    Anyboy have a similar problem?
    This works with the Client prg in the ejb/basic/StatefulSssion "Client" It works
    correctly

  • ClassCastException calling EJB from EJB (diff  EARs) Urgent please help !!

    Hi,
    I�m trying to call a Remote EJB ( in jdev BBEAN.prj ) from another EJB (in jdev ABEAN.prj) located in a different EAR.
    In JDEVELOPER (oc4j 9.0.3) I also considered BBEAN as a libreary which is included in the ABEAN project.
    So that the ABEAN JAR contains the class definition for the Home and remote interface.
    From the ABEAN bean I call this code:
    DO ()
    private static Context getInitialContext() throws NamingException
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory");
    env.put(Context.SECURITY_PRINCIPAL, "admin");
    env.put(Context.SECURITY_CREDENTIALS, "manager");
    env.put(Context.PROVIDER_URL, "ormi://GSARNO-1/BBean");
    return new InitialContext(env);
    BBeanHome BBeanHome = (BBeanHome)PortableRemoteObject.narrow(context.lookup("BBean"), BBeanHome.class);
    BBean bBean;
    ������������..
    After having deployed both projects I then run a client (Calling the Do function).
    Doing so I keep receiving the following error when calling narrow.
    java.lang.ClassCastException
    java.lang.Object com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(java.lang.Object, java.lang.Class)
    PortableRemoteObject.java:296
    java.lang.Object javax.rmi.PortableRemoteObject.narrow(java.lang.Object, java.lang.Class)
    PortableRemoteObject.java:137
    java.lang.String mypackage1.impl.MySessionEJBBean.Do()
    MySessionEJBBean.java:39
    java.lang.String MySessionEJB_StatelessSessionBeanWrapper6.Do()
    MySessionEJB_StatelessSessionBeanWrapper6.java:85
    java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[])
    native code
    void com.evermind.server.rmi.RMICallHandler.run(java.lang.Thread)
    RMICallHandler.java:119
    void com.evermind.server.rmi.RMICallHandler.run()
    RMICallHandler.java:48
    void EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run()
    PooledExecutor.java:803
    void java.lang.Thread.run()
    Thread.java:484
    Can anyone help ?
    What should I do to call remote e/o local interfaces located on different EARs ?
    I�m using OC4J 9.0.3

    Hi Giuseppe,
    If both EAR files are in the same OC4J instance you do not have to use RMIInitialContextFactory to invoke the EJB. You have to do the following:
    In OC4J
    1) Make the BBEAN as the parent for ABEAN application defined in the server.xml as follows:
    application name="ABEAN" path="../applications/abean.ear" parent="BBEAN" auto-start="true" />
    2)
    You can define ejb-ref or ejb-local-ref in the deployment descriptor of your application
    3) You can use the default InitialContext to lookup your EJB as if both EJBs are in the same application
    regards
    Debu

  • Sun One EJB problem - PortableRemoteObject.narrow ClassCastException...

    Hi all,
    I'm using Sun One app server 7 for the first time and am having a bit of difficulty. I have deployed a very simple EAR containing one stateless session bean just to test it. The ear appears to have deployed correctly but PortableRemoteObject.narrow is throwing a ClassCastException when trying to do a remote lookup on the bean.
    I'm using the following env settings...
    initialContextFactory = com.sun.enterprise.naming.SerialInitContextFactory
    providerUrl = iiop://127.0.0.1:3700The lookup appears to work okay - this line of code executes successfully
    Object objref = initialContext.lookup(jndiHomeName);...objref appears to initalise succesfully (if I toString() it I get an iiop stream of some sort). However, it is the next line that is failing...
    Object obj = PortableRemoteObject.narrow(objref, homeClass);...this is the exception I get...
    java.lang.ClassCastException
         at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(Unknown Source)
         at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
         at com.scorlog.ServiceLocator.getRemoteHome(ServiceLocator.java:145)Furthermore, when PortableRemoteObject.narrow() executes, I get the following console exception on the server...
    com.sun.corba.ee.internal.core.DuplicateServiceContext
            at com.sun.corba.ee.internal.core.ServiceContexts.put(ServiceContexts.java:208)
            at com.sun.corba.ee.internal.iiop.ServerRequestImpl.getServiceContextsForReply(ServerRequestImpl.java:258)
            at com.sun.corba.ee.internal.iiop.ServerRequestImpl.createResponse(ServerRequestImpl.java:89)
            at com.sun.corba.ee.internal.POA.SubcontractResponseHandler.createReply(SubcontractResponseHandler.java:50)
            at org.omg.CosNaming.NamingContextExtPOA._invoke(NamingContextExtPOA.java:377)
            at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatchToServant(GenericPOAServerSC.java:569)
            at com.sun.corba.ee.internal.POA.GenericPOAServerSC.internalDispatch(GenericPOAServerSC.java:211)
            at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatch(GenericPOAServerSC.java:113)
            at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:275)
            at com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProcessor.java:83)
            at com.iplanet.ias.corba.ee.internal.iiop.ServicableWrapper.service(ServicableWrapper.java:25)
            at com.iplanet.ias.util.threadpool.FastThreadPool$ThreadPoolThread.run(FastThreadPool.java:288)
            at java.lang.Thread.run(Thread.java:534)
    FINE: No SAS context element found in service context listI have seen the forum that other users have had similar problems and the suggestion was that the client can't see the ejb stubs. I don't think this is the problem in my case as I deployed the same ear on weblogic 7 (obviously substituting sun-ejb-jar.xml for a weblogic-ejb-jar.xml) and successfully executed the same client code for the remote lookup.
    My feeling is that the problem revolves around the JNDI binding. Could it be the case that even though the object is binding properly, the app server doesn't realise it is an ejb and not a jdbc/jms/mail object? The documentation gives details on looking up a JDBC, javamail, URL, JMS resource (http://docs.sun.com/source/817-2177/djjndi.html) but not ejb so I could be doing something simple wrong here...
    My sun-ejb-jar.xml is as follows....
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Generated by XDoclet -->
    <sun-ejb-jar>
        <enterprise-beans>
            <ejb>
                <ejb-name>SBTest</ejb-name>
                <jndi-name>ejb/SBTestBean</jndi-name>
            </ejb>
        </enterprise-beans>
    </sun-ejb-jar>However, I noticed on another thread, a user had some additional elements under their <ejb> tag like this...
    <?xml version="1.0" encoding="UTF-8"?>
    <sun-ejb-jar>
      <enterprise-beans>
        <name>Ejb1</name>
        <ejb>
          <ejb-name>HelloBean</ejb-name>
          <jndi-name>HelloBean</jndi-name>
          <ejb-ref>
            <ejb-ref-name>ejb/helloBean</ejb-ref-name>
            <jndi-name>HelloBean</jndi-name>
          </ejb-ref>
        </ejb>
      </enterprise-beans>
    </sun-ejb-jar>However, when I tried to add and <ejb-ref> element to my xml doc the ear failed to deploy. This is the error I get in the admin console...
    Error
    Deployment Error -- Error while running ejbc -- Fatal Error from EJB Compiler -- --
    Failed to load deployment descriptor for: testApp cause: Error converting J2EE-
    specific ejb xml to object representation: testApp.jar app_testApp Generated by
    XDoclet This bean has no ejb reference by the name of [ejb/SBtest]
    ejb/SBTestSBTestThis problem is eating up my time and being made all the more frustrating by the fact that a) it deploys on weblogic and b) the documentation is terrible. Even the sample application that comes with sun one only provides the .class files for the code that does the ejb look up and not the .java so you can't see how they hell they do it!
    Unfortunately I am tied to using Sun One so I really need to solve this problem fast. If anyone can provide any help I'd greatly appreciate it.
    Cheers,
    John :)

    I am having the same problem after upgrading to Sun One from iplanet. Any clue?

  • ClassCastException when accessing others app ejb

    Hi,
    I have the following problem:
    I use OC4J 9.0.2.0.0.
    I have a stateless SessionBean BeanA deployed in application AppA.
    I have a stateless SessionBean BeanB deployed in application AppB.
    I have a servlet ServletC deployed in application AppC.
    All 3 applications are deployed to the same oc4j instance.
    ServletC needs BeanA and BeanB.
    When ServletC tries to access one of the 2 ejbs a ClassCastException is thrown when the PortableRemoteObject.narrow() should be done.
    In the forum I found some hints using the parent attribute in the application tag of the server.xml file.
    But this only works for a client only using one other application but I have 2.
    Thanks for your help
    Guenther

    Hi Debabrata,
    I use the com.evermind.server.rmi.RMIInitialContextFactory.
    I think it is no good idea to have a chain of parents.
    I lose the separate class loaders.
    I cannot use different versions of libraries.
    There must exist a better solution than chaining applications with the parent attribute.
    Thanks
    Guenther

Maybe you are looking for

  • CS5 / Win - Debug: Treeview crash

    Hi I try to implement a list box in a dialog, not a panel, using tree view. This works in CS3, CS4 and CS5 (Win - release, Mac debug and release). But it crashs with Windows - debug. It crash if I includes the tree view manager in my fr file. If I re

  • Unzip.vi only works with 1-internal file, error2 with multiple even in raw form.

    I've attempted to use the LabView unzip tool with several different meathods & I can only get it to work when there's only one file in the zip file. Multiple files continually cause an error in the VI, even when using raw LabView example code/tools.

  • Setting up exchange webmail in ipod

    Hi, I'm confuse about setting up my microsoft exchange webmail account in my ipod touch. Should I choose 'other' or 'Microsoft Exchange'? I've tried 'other', but it seems doesn't work. I need help about this. Hope to hear any feedback from anyone. Th

  • Searching for archived documents / data retrieval

    Hi, In a clients system, salesdocuments for a given period has been archived. Unfortunately we now need this info (combination of salesdocument / material). Anybody know if that info is easily retrievable (if possible to accessible in tables i was th

  • ALV OO with pictures on cell

    Hi, I need to create a report and put the corresponding picture of the material. I know the name of the picture but how can i define this cell in order to show this picture?? Thanks & regards