facebook

EJB3/Jboss – binding issue.

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #258060 Reply

    bartstanczyk
    Member

    Hi, I’m pretty new to EJB3 and I started doing this simple forum tutorial (http://www.informit.com/guides/content.asp?g=java&seqNum=239&rl=1)

    I created an EAR and put the EJBs in the EJB module and the test servlet in the Web module. It deploys without errors, but when I invoke the getForums command I get an error.

    I’ve been trying to fix this for about 5 days now. I hope someone can help me out here.

    I know that the problem has to do with the ForumManager session bean.

    I’m using MyEclipse 5/Eclipse 3.2 / Jboss 404 / MySQL

    -Thanks in advance

    stacktrace

    21:59:31,197 ERROR [STDERR] javax.naming.NameNotFoundException: com.javasrc.forums.business.ForumManager not bound
    21:59:31,197 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
    21:59:31,197 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
    21:59:31,217 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
    21:59:31,217 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
    21:59:31,217 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    21:59:31,217 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    21:59:31,227 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    21:59:31,227 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
    21:59:31,227 ERROR [STDERR] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
    21:59:31,227 ERROR [STDERR] at sun.rmi.transport.Transport$1.run(Transport.java:153)
    21:59:31,227 ERROR [STDERR] at java.security.AccessController.doPrivileged(Native Method)
    21:59:31,227 ERROR [STDERR] at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
    21:59:31,227 ERROR [STDERR] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)
    21:59:31,227 ERROR [STDERR] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)
    21:59:31,227 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)
    21:59:31,227 ERROR [STDERR] at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
    21:59:31,227 ERROR [STDERR] at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
    21:59:31,227 ERROR [STDERR] at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
    21:59:31,227 ERROR [STDERR] at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
    21:59:31,227 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
    21:59:31,227 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
    21:59:31,227 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:351)
    21:59:31,227 ERROR [STDERR] at com.javasrc.forums.web.ForumServlet.init(ForumServlet.java:39)
    21:59:31,227 ERROR [STDERR] at javax.servlet.GenericServlet.init(GenericServlet.java:211)
    21:59:31,227 ERROR [STDERR] at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1105)
    21:59:31,227 ERROR [STDERR] at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:757)
    21:59:31,227 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:130)
    21:59:31,227 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    21:59:31,227 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
    21:59:31,227 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
    21:59:31,227 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    21:59:31,227 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    21:59:31,227 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    21:59:31,227 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    21:59:31,227 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    21:59:31,227 ERROR [STDERR] at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
    21:59:31,227 ERROR [STDERR] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    21:59:31,227 ERROR [STDERR] at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
    21:59:31,227 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)
    21:59:31,237 ERROR [[ForumServlet]] Servlet.service() for servlet ForumServlet threw exception
    java.lang.NullPointerException

    at com.javasrc.forums.web.ForumServlet.service(ForumServlet.java:57)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
    at java.lang.Thread.run(Thread.java:595)

    ForumServlet.java

    package com.javasrc.forums.web;

    // Import the servlet classes
    import javax.servlet.*;
    import javax.servlet.http.*;

    // Import the standard Java classes
    import java.io.*;
    import java.util.*;

    // Import the EJB classes
    import javax.naming.*;
    import javax.ejb.*;

    // Import our EJBs (stateless session and entity)
    import com.javasrc.forums.business.*;
    import com.javasrc.forums.entity.*;

    public class ForumServlet extends HttpServlet {
    /**
    *
    */
    private static final long serialVersionUID = -3182140332587612047L;

    public void init() {
    // Load a reference to the ForumManager the first time this Servlet
    // is invoked
    ServletContext ctx = getServletContext();

    ForumManager fm = (ForumManager) ctx.getAttribute(“forums”);
    if (fm == null) {
    try {
    // Lookup a reference to the ForumManager EJB and save it
    // in the application scope attribute “forum-manager”
    InitialContext ic = new InitialContext();
    fm = (ForumManager) ic.lookup(ForumManager.class.getName());
    ctx.setAttribute(“forums”, fm);

    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }

    public void service(HttpServletRequest req, HttpServletResponse res)
    throws ServletException {
    try {
    // Simple debug interface: write HTML Strings to the response
    PrintWriter out = res.getWriter();
    out.println(“<html><head><title>Forums</title><head><body>”);

    // Load our ForumManager EJB
    ServletContext ctx = getServletContext();
    ForumManager fm = (ForumManager) ctx.getAttribute(“forums”);

    String command = req.getParameter(“cmd”);
    if (command == null)
    command = “getForums”;

    // Add a new forum
    if (command.equalsIgnoreCase(“addForum”)) {
    String forumName = req.getParameter(“name”);
    String forumDescription = req.getParameter(“desc”);
    System.out.println(“Adding forum: ” + forumName + “, ”
    + forumDescription);
    fm.addForum(forumName, forumDescription);
    out.println(“Added forum ” + forumName);
    }

    // Return a list of all forums
    else if (command.equalsIgnoreCase(“getForums”)) {
    out.println(“<h3>Forums</h3>”);
    //Collection<ForumBean> forums = fm.getForums();
    out.println(“<table width=\”90%\” align=\”center\”>”);
    for (ForumBean forum : forums) {
    out
    .println(“<tr><td width=’20%’><a href=’forum?cmd=getTopics\”forumName=”
    + forum.getName()
    + “‘>”
    + forum.getName()
    + “</a></td><td>”
    + forum.getDescription()
    + “</td></tr>”);
    }
    out.println(“</table>”);
    out.println(“Forums should be here”);
    }

    // Return a list of all topics for a specified forum
    else if (command.equalsIgnoreCase(“getTopics”)) {
    String forumName = req.getParameter(“forumName”);
    Collection<TopicBean> topics = fm.getTopics(forumName);
    if (topics.size() == 0) {
    System.out
    .println(“No topics exist for forum ” + forumName);
    } else {
    out.println(“<h3>” + forumName + ” Topics (”
    + topics.size() + “)</h3>”);
    // out.println( “<b>Topics found for forum ” + forumName +
    // “: ” + topics.size() );
    out.println(“<table width=’90%’ align=’center’>”);
    for (TopicBean topic : topics)

    {
    out.println(“<tr><td width=’20%’>”
    + “<a href=’forum?cmd=getMessages\”forumName=”
    + forumName + “\”topicName=” + topic.getName()
    + “‘>” + topic.getName() + “</a></td><td>”
    + topic.getDescription() + “</td></tr>”);
    }
    out.println(“</table>”);
    }
    }

    // Add a new topic to a forum
    else if (command.equalsIgnoreCase(“addTopicToForum”)) {
    String forumName = req.getParameter(“forumName”);
    String topicName = req.getParameter(“topicName”);
    String topicDescription = req.getParameter(“desc”);
    System.out.println(“Adding topic ” + topicName + ” to ”
    + forumName + “: ” + topicDescription);
    fm.addTopicToForum(topicName, forumName, topicDescription);
    out.println(“Added topic ” + topicName + ” to forum ”
    + forumName);
    }

    // Add a new user to the system
    else if (command.equalsIgnoreCase(“addUser”)) {
    String name = req.getParameter(“name”);
    String login = req.getParameter(“login”);
    String password = req.getParameter(“password”);
    fm.addUser(name, login, password);
    out.println(“Successfully added new user ” + name
    + ” with login id ” + login);
    }

    // Post a message to a topic
    else if (command.equalsIgnoreCase(“postMessage”)) {
    String forumName = req.getParameter(“forumName”);
    String topicName = req.getParameter(“topicName”);
    String login = req.getParameter(“login”);
    String title = req.getParameter(“title”);
    String body = req.getParameter(“body”);
    fm.postMessage(forumName, topicName, login, title, body);
    out.println(“Successfully added message ” + title
    + ” to forum ” + forumName + “, topic ” + topicName);
    }

    // Get messages
    else if (command.equalsIgnoreCase(“getMessages”)) {
    String forumName = req.getParameter(“forumName”);
    String topicName = req.getParameter(“topicName”);
    Collection<MessageBean> messages = fm.getMessages(forumName,
    topicName);
    out.println(“<h3>” + forumName + ” / ” + topicName
    + ” Messages (” + messages.size() + “)</h3>”);
    out.println(“<table width=\”90%\” align=\”center\”>”);
    for (MessageBean message : messages) {
    out
    .println(“<tr><td width=’20%’><a href=’forum?cmd=getMessage\”id=”
    + message.getId()
    + “‘>”
    + message.getTitle()
    + “</a></td><td>”
    + message.getTimestamp() + “</td></tr>”);
    }
    out.println(“</table>”);
    }

    else if (command.equalsIgnoreCase(“getMessage”)) {
    String messageId = req.getParameter(“id”);
    int id = Integer.parseInt(messageId);
    MessageBean message = fm.getMessage(id);
    StringBuffer sb = new StringBuffer(
    “<table width=\”90%\” align=\”center\”>”);
    sb.append(“<tr><td><b>Title:</b> ” + message.getTitle()
    + “</td></tr>”);
    sb.append(“<tr><td><b>User:</b> ”
    + message.getUserBean().getName() + “</td></tr>”);
    sb.append(“<tr><td><b>Date:</b> ” + message.getTimestamp()
    + “</td></tr>”);
    sb.append(“<tr><td>” + message.getBody() + “</td></tr>”);
    sb.append(“</table>”);
    out.println(sb.toString());
    }

    out.println(“</body></html>”);
    } catch (Exception e) {
    throw new ServletException(e);
    }
    }
    }

    #258096

    Riyad Kalla
    Member

    Moving to OT > Soft Dev, seems to be a naming/configuration issue.

    21:59:31,197 ERROR [STDERR] javax.naming.NameNotFoundException: com.javasrc.forums.business.ForumManager not bound

    Focus on fixing this first. I haven’t done any JEE 5/EJB projects yet so I’m not farmiliar with our you register the beans with specific names, do you have that code handy?

    The way you are looking up the bean now looks a little strange:

    InitialContext ic = new InitialContext();
    fm = (ForumManager) ic.lookup(ForumManager.class.getName());
    ctx.setAttribute(“forums”, fm);

    Normally your lookup string is something like “ejb/MyBean” or something like that. But then again, I don’t know if this is different with annots in JEE5.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: EJB3/Jboss – binding issue.

You must be logged in to post in the forum log in