EJBContext error

Discussions

EJB programming & troubleshooting: EJBContext error

  1. EJBContext error (3 messages)

    I am trying to access an EJB from a JSP and have the foll code piece: (i am using weblogic 6.0)
    ..............
    String url = "t3://localhost:7001";

    public Context getInitialContext() throws Exception {
    Properties p = new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY,
    "weblogic.jndi.WLInitialContextFactory");
    //p.put(Context.PROVIDER_URL, url);
    return new InitialContext(p);
    }

    String getStackTraceAsString(Exception e)
    {
    // Dump the stack trace to a buffered stream, then send it's contents
    // to the JSPWriter.
    ByteArrayOutputStream ostr = new ByteArrayOutputStream();
    e.printStackTrace(new PrintWriter(ostr));
    return(ostr.toString());
    }
    %>
    <%
    String op="";
    try {
    // Contact the AccountBean container (the "AccountHome") through JNDI.
    Context ctx = getInitialContext();
    out.println("initial context got !!");
    DemoHome home = (DemoHome) ctx.lookup("demo.DemoHome");
    out.println("home got !!");

    %>



    <%
    Demo ac = null;
    try {
    ac = (Demo) home.create();
    out.println("create called!!");
    if (ac==null)
    out.println("ac is null!");
    }
    catch (Exception ee) {
    out.print("exception 1");
    }


    %>


    <%
    try {
    out.println("going to call method!");
    if (ac!= null)
    op = ac.demoSelect();
    else
    out.println("ac is null->error!!");
    out.println(ac.demoSelect());
    out.println("string got!!");
    out.println(op);
    }
    catch (Exception e) {
    getStackTraceAsString(e);

    e.printStackTrace();
    out.println("error 2");
    }
    }
    catch(Exception e)
    {
    out.println("error 3!");
    }
    ..................

    It gives an error on trying to access the method "demoSelect".
    e.printStackTrace gives the output:
    -------------------
    java.lang.RuntimeException: javax.ejb.EJBContext.getEnvironment is deprecated in EJB 1.1. EJB 1.1 compli
    ant containers are not required to implement this method. Use java:comp/env instead.
    <--------------------

    What is wrong???

    pls help

    -R

    Threaded Messages (3)

  2. your ejb is wrong.[ Go to top ]

    Check your code of EJB.
    the method getEnvironment() has been Deprecated.
  3. Your lookup() code is wrong that is shown above. You are using EJB 1.0 type of lookup. You need to use lookup("java:comp/env/....") which is part of EJB 1.1 spec.

    Hope this helps.

    Regards,
    Chintala
  4. Error Found - in EJB[ Go to top ]

    Yeah .. I found out that the EJB's setSessionContext method was referring to getEnvironment() method which is now deprecated. This was what was giving a problem. I just removed that invocation and the whole thing worked fine.

    Please note that I did not make any changes in the JSP at all.
    So, I guess, the JSP lookup code is as per EJB 1.1 reqmnts.

    Any comments, Chintala?