Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

gettinng name not found exception using jboss and ejb3.0 and statful session bean  RSS feed

 
deepthi jaladi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm using EJB3.0+myeclipse+jboss4.0.5

This is my code

Interface:

package cart;
import javax.ejb.Remote;

@Remote

public interface ShoppingCart {

public void initialize(String user);
public void addUser(String city);


}

Implementation:

package cart;

import javax.ejb.Stateful;
import java.sql.*;

@Stateful
public class ShoppingCartBean implements ShoppingCart, ShoppingCartBeanLocal,
ShoppingCartBeanRemote {
Connection con=null;
Statement st=null;
ResultSet rs=null;
String qry="";
String name=null;

public void addUser(String city) {
// TODO Auto-generated method stub

try{
st=con.createStatement();
qry="insert into usermaster values('"+name+"','"+city+"')";
st.executeUpdate(qry);

}
catch(Exception e)
{System.out.println("Exception while inserting data"+e);}



}

public void initialize(String user) {
// TODO Auto-generated method stub
System.out.println("intialize");
if(user!=null)
{
name=user;
System.out.println("name");
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");

}
catch(Exception e)
{System.out.println("exception caused by DB connection failure"+e);}


}//if


}

}

and i'm using jsp as client


<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ page import="javax.ejb.*"%>
<%@ page import="javax.naming.*" %>
<%@ page import="cart.*"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<%


Properties props=new Properties();

props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");

props.put(Context.PROVIDER_URL,"localhost:8080");

props.put(Context.URL_PKG_PREFIXES,"org.jboss.naming rg.jnp.interfaces");

Context context=new InitialContext(props);


//InitialContext ic=new InitialContext();
ShoppingCart scart=(ShoppingCart)context.lookup(ShoppingCart.class.getName());



%>
when i run the application i'm getting fallowing exception

Servlet.service() for servlet jsp threw exception
javax.naming.NameNotFoundException: cart.ShoppingCart
at org.jboss.ha.jndi.TreeHead.lookup(TreeHead.java:242)
at org.jboss.ha.jndi.HAJNDI.lookup(HAJNDI.java:155)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.ha.framework.interfaces.HARMIClient.invoke(HARMIClient.java:258)
at $Proxy67.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at org.apache.jsp.success_jsp._jspService(success_jsp.java:73)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
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.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
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)



Please help me i'm new to EJb3.0

Thank you.
 
Reza Rahman
author
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepthi,

The global JNDI name you are using is not the correct one for JBoss AS (looks like GlassFish look-up code). Here is how JBoss JNDI bindings work: http://docs.jboss.org/ejb3/app-server/tutorial/jndibinding/jndi.html.

Regards,
Reza

P.S.: The properties you are specifying for the JNDI context are also unnecessary if the web container is also on the same local JBoss instance. From the looks of the code, I would recommend that you slow down and start with some sample JBoss code. For example, you are welcome to start with the JBoss example code for EJB 3 in Action. It is freely downloadable from the book's website.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To add to what Reza said, you can use the JNDIView in the jmx-console on JBoss to figure out the correct jndi name for the bean.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!