Discussions

EJB programming & troubleshooting: I'm Going Mad while running a EJB Client

  1. I'm Going Mad while running a EJB Client (2 messages)

    Hi,

    I've been trying to connect to a Simple Stateless EJB successfully deployed in Weblogic 6 from a JSP written running on JRun 3.0.
    I'm using a Bean for Connectivity.
    Instead of a JSP if i use a Simple Java Application Client, it is connecting and working.
    The bean is working properly, cauz i tested it with including a main().
    The same bean if i instantiate and use within a JSP, is not working.
    I guess the problem is with the JNDI calls.
    I tried printing out the InitialContext return values and to my surprise, i got a constant value from the Application Client( the bean with a main() ). and i'm getting varying values within a JSP Client.

    I tried different JNDI connecting measures also..
    Still it is throwing the CLASSCASTEXCEPTION for the Stub.

    Pls help me to get rid of this..
    I've been trying a lot for some time..
    but fruitless.


    I'm including the Worker Bean Code and JSP code also:-

    The Worker - Bean:-
    **********************
    import java.rmi.*;
    import javax.ejb.*;
    import java.util.*;
    import javax.naming.*;
    import examples.ejb.basic.statelessSession.*;
    import java.io.*;


    public class JClient implements Serializable
    {

    private TraderHome home;
    private Trader cTrade;


    public JClient()
    {

    try {

    Properties props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
    props.put(Context.PROVIDER_URL, "t3://localhost:7001");
            Context ctx=new javax.naming.InitialContext(props);

    System.out.println("Obtaining Home Interface reference..in Context "+ctx.toString()+"\n");

    home = (examples.ejb.basic.statelessSession.TraderHome)javax.rmi.PortableRemoteObject.narrow(ctx.lookup("statelessSession.TraderHome"),examples.ejb.basic.statelessSession.TraderHome.class);

            cTrade = home.create();



    } catch(Throwable t) { System.out.println(t); }
    }

    public String getReply()
    {
    String msg="Bad";
    try{

    return cTrade.sayHello("Fire Your Imagination..!");

           }catch(Throwable t) { msg=t.toString(); System.out.println(t);}

           return (msg);
    }

    public static void main(String args[])
    {
    try {

    JClient jc=new JClient();
    System.out.println(jc.getReply());

    }catch(Exception e) { System.out.println(e); }

    }

    }

    The JSP Code:-
    ***************
    <html>
    <h2>
    JSP Client for EJB
    </h2>

    <br>

    <b>
    <jsp:useBean id="jc" scope="application" class="JClient" />

    <%= jc.getReply() %>

    </b>
    </html>
    ***********************************************

    The ERROR:
    CLASSCASTEXCEPTION












  2. Have you tried to "narrow" the remote object.
    Do you know where exactly you get the ClassCastException ??

    and btw, post your message in appropriate forum..
    could have found one down below for "Troubleshooting EJB.."

    hth
    -Praveen
  3. We had a vaguely similar problem to do with Context, see thread 6650 for details. During the month it took to find the solution(!) it at times manifested itself as a ClassCastException.