Skip to main content

generated ejb call to session bean not working..whats wrong???

1 reply [Last post]
sairndain
Offline
Joined: 2004-06-08
Points: 0

Its seems as if this should work...but it doesn't...
(Is there something else I should be configuring?.... or is this a bug?)

I created this project mostly using Netbeans 6.0 wizards...i.e.,

1. New Project --> Enterprise --> Enterprise Application
(Project name: dddEAR, Server: GlassFish V2, Java EE version: J2EE 1.4, create EJB Module, create Web Application Module, uncheck "Set Source Level to 1.4")

2. dddEAR-war --> Properties --> Frameworks --> Add "Javaserver Faces"

3. dddEAR-war --> New --> JSF Managed Bean --> Class Name: Jsp1Bean, Package: ddd.web

4. dddEAR-ejb --> New --> Session Bean, EJB Name: DddEJB, Package: ddd.ejb

5. dddEAR-ejb --> New --> Java Class, Class Name: Helper, Package: ddd.ejb

6. (in ddd.ejb.DddEJBBean.java) EJB Methods --> Add Business Method, Name: getField1, Return Type: String)

7. (in ddd.ejb.Helper.java) Enterprise Resources --> Call Enterprise Bean --> choose DddEJBSB)

etc... (SEE CODE BELOW)

---- ddd.ejb.DddEJBBean.java ----
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package ddd.ejb;

import javax.ejb.SessionBean;
import javax.ejb.SessionContext;

/**
*
* @author sairndain
*/
public class DddEJBBean implements SessionBean {

private SessionContext context;

// ;

// TODO Add code to acquire and use other enterprise resources (DataSource, JMS, enterprise bean, Web services)
// TODO Add business methods or web service operations

/**
* @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
*/
public void setSessionContext(SessionContext aContext) {
context = aContext;
}

/**
* @see javax.ejb.SessionBean#ejbActivate()
*/
public void ejbActivate() {

}

/**
* @see javax.ejb.SessionBean#ejbPassivate()
*/
public void ejbPassivate() {

}

/**
* @see javax.ejb.SessionBean#ejbRemove()
*/
public void ejbRemove() {

}

// ;

/**
* See section 7.10.3 of the EJB 2.0 specification
* See section 7.11.3 of the EJB 2.1 specification
*/
public void ejbCreate() {
// TODO implement ejbCreate if necessary, acquire resources
// This method has access to the JNDI context so resource aquisition
// spanning all methods can be performed here such as home interfaces
// and data sources.
}

// Add business logic below. (Right-click in editor and choose
// "EJB Methods > Add Business Method" or "Web Service > Add Operation")
private String field1 = "...value of field1 from ddd.ejb.DddEJBBean.java...";
public String getField1() {
return this.field1;
}

}

---- ddd.ejb.Helper.java ---
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package ddd.ejb;

import javax.ejb.CreateException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
*
* @author sairndain
*/
public class Helper {

private String field1 = "...value of field1 from ddd.ejb.Helper.java...";
public String getField1()
{
String field1ValueFromEjb = this.lookupDddEJBBean().getField1();
return field1ValueFromEjb + this.field1;
}

private DddEJBLocal lookupDddEJBBean() {
try {
Context c = new InitialContext();
DddEJBLocalHome rv = (DddEJBLocalHome) c.lookup("java:comp/env/DddEJBBean");
return rv.create();
} catch (NamingException ne) {
java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, "exception caught", ne);
throw new RuntimeException(ne);
} catch (CreateException ce) {
java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, "exception caught", ce);
throw new RuntimeException(ce);
}
}
}

--- ddd.web.Jsp1Bean.java ---
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package ddd.web;

import ddd.ejb.Helper;

/**
*
* @author sairndain
*/

public class Jsp1Bean {

/** Creates a new instance of Jsp1Bean */
public Jsp1Bean() {
}

private String field1 = "...value of field1 from ddd.web.Jsp1Bean.java...";
public String getField1()
{
String field1ValueFromHelper = new Helper().getField1();
return field1ValueFromHelper + this.field1;
}

}

--- welcomeJSF.jsp ---
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

<%--
This file is an entry point for JavaServer Faces application.
--%>

JSP Page

--- ejb.jar.xml ---
<?xml version="1.0" encoding="UTF-8"?>

DddEJBSB
DddEJBBean
ddd.ejb.DddEJBLocalHome
ddd.ejb.DddEJBLocal
ddd.ejb.DddEJBBean
Stateless
Container

DddEJBBean
*

Required

--- sun-ejb-jar.xml ---
<?xml version="1.0" encoding="UTF-8"?>

--- faces-config.xml ---
<?xml version='1.0' encoding='UTF-8'?>

Jsp1Bean
ddd.web.Jsp1Bean
request

--- web.xml ---

<?xml version="1.0" encoding="UTF-8"?>

com.sun.faces.verifyObjects
false

com.sun.faces.validateXml
true

javax.faces.STATE_SAVING_METHOD
client

Faces Servlet
javax.faces.webapp.FacesServlet
1

Faces Servlet
*.faces

30

index.jsp

--- sun-web.xml ---
<?xml version="1.0" encoding="UTF-8"?>

/dddEAR-war

Keep a copy of the generated servlet class' java code.

---ERROR MESSAGE --
-
-
-
Caused by: javax.naming.NameNotFoundException: No object bound to name java:comp/env/DddEJBBean
at com.sun.enterprise.naming.NamingManagerImpl.lookup(NamingManagerImpl.java:834)
at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:173)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:337)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at ddd.ejb.Helper.lookupDddEJBBean(Helper.java:29)
... 56 more
-
-
-

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sairndain
Offline
Joined: 2004-06-08
Points: 0

I've gotten no response, so far -- Sorry if I've not phrased the question clearly enough...

To clarify (hopefully)... In NetBeans 6.0, I created an "Enterprise" project (containing an EJB project and WEB project)...

In doing so, I found the following:

The code to call to a Session EJB -- generated in a POJO using the NetBeans 6.0 context menu command (i.e., "Enterprise Resources --> Call Enterprise Bean") -- will compile, but, will NOT run, when this POJO is inside the Session EJB's package (EJB project). --See the full code is in my previous post

(NOTE: In contrast, the same code generated within the POJO of the WEB project will work fine)

Is this be a "NetBeans 6.0" or "GlassFish" issue/bug.... or neither.

Please help.

Thanks!

sd