[jboss-user] [EJB/JBoss] - What is wrong with my local ejb JNDI lookup code (or the ejb
sairndain
do-not-reply at jboss.com
Fri Jan 11 00:22:17 EST 2008
I'm trying to perform a JNDI lookup on a local stateless session bean.
When I use the jboss jmx console to check the JNDI name space I get the following:
anonymous wrote : +- HandleDelegate (class: org.jboss.proxy.ejb.handle.HandleDelegateImpl)
| +- ORB (class: org.jacorb.orb.ORB)
| +- env (class: org.jnp.interfaces.NamingContext)
| | +- ejb (class: org.jnp.interfaces.NamingContext)
| | | +- DddEJBBeanLocal[link -> local/DddEJBBean at 16619879] (class: javax.naming.LinkRef)
| | +- DddEJBRemoteHome[link -> DddEJBBean] (class: javax.naming.LinkRef)
The code I am using for the JNDI lookup is as follows:
private DddEJBLocal lookupDddEJBBean() {
| try {
| Context c = new InitialContext();
| DddEJBLocalHome rv = (DddEJBLocalHome) c.lookup("java:comp/env/ejb/DddEJBBeanLocal");
| 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);
| }
| }
The ejb-jar.xml is as follows:
<?xml version="1.0" encoding="UTF-8"?>
| <ejb-jar version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
| <enterprise-beans>
| <session>
| <display-name>DddEJBSB</display-name>
| <ejb-name>DddEJBBean</ejb-name>
| <home>ddd.ejb.DddEJBRemoteHome</home>
| <remote>ddd.ejb.DddEJBRemote</remote>
| <local-home>ddd.ejb.DddEJBLocalHome</local-home>
| <local>ddd.ejb.DddEJBLocal</local>
| <ejb-class>ddd.ejb.DddEJBBean</ejb-class>
| <session-type>Stateless</session-type>
| <transaction-type>Container</transaction-type>
|
| <ejb-ref>
| <description>DddEJBBean</description>
| <ejb-link>dddEAR-ejb.jar#DddEJBBean</ejb-link>
| <ejb-ref-name>DddEJBRemoteHome</ejb-ref-name>
| <ejb-ref-type>Session</ejb-ref-type>
| <home>ddd.ejb.DddEJBRemoteHome</home>
| <remote>ddd.ejb.DddEJBRemote</remote>
| </ejb-ref>
|
| <ejb-local-ref>
| <description>DddEJBBean</description>
| <ejb-link>dddEAR-ejb.jar#DddEJBBean</ejb-link>
| <ejb-ref-name>ejb/DddEJBBeanLocal</ejb-ref-name>
| <ejb-ref-type>Session</ejb-ref-type>
| <local-home>ddd.ejb.DddEJBLocalHome</local-home>
| <local>ddd.ejb.DddEJBLocal</local>
| </ejb-local-ref>
|
| </session>
| </enterprise-beans>
| <assembly-descriptor>
| <container-transaction>
| <method>
| <ejb-name>DddEJBBean</ejb-name>
| <method-name>*</method-name>
| </method>
| <trans-attribute>Required</trans-attribute>
| </container-transaction>
| </assembly-descriptor>
| </ejb-jar>
I get the the following error:
anonymous wrote : javax.naming.NameNotFoundException: ejb not bound
| at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
| at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
| at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
| at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
| at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
| at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
| at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:716)
| at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
| at javax.naming.InitialContext.lookup(InitialContext.java:351)
| at ddd.ejb.DddHelper.lookupDddEJBBean(DddHelper.java:32)
QUESTION#1:
What is wrong with my lookup code or the ejb-jar.xml configuration?
QUESTION#2
Are proprietary JBoss configuration files (e.g., jboss.xml) required in order to successfully perform a JNDI lookup on the above mentioned bean?
Thanks for any help! --sd
[More information... if needed]
***ddd.ejb.DddEJBBean***
package ddd.ejb;
|
| import javax.ejb.SessionBean;
| import javax.ejb.SessionContext;
|
| /**
| *
| * @author sairndain
| */
| public class DddEJBBean implements SessionBean {
|
| private SessionContext context;
|
| // <editor-fold defaultstate="collapsed" desc="EJB infrastructure methods. Click the + sign on the left to edit the code.">;
|
| // 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() {
|
| }
|
| // </editor-fold>;
|
| /**
| * 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.
| }
|
| private String field1 = "...value of field1 in DddEJBBean.java...";
| public String getField1() {
| System.out.println(".................DddEJBBean/getField1()..............");
|
| return this.field1;
| }
|
| // Add business logic below. (Right-click in editor and choose
| // "EJB Methods > Add Business Method" or "Web Service > Add Operation")
|
| }
|
***ddd.ejb.DddHelper***
package ddd.ejb;
|
| import javax.ejb.CreateException;
| import javax.naming.Context;
| import javax.naming.InitialContext;
| import javax.naming.NamingException;
|
| /**
| *
| * @author sairndain
| */
| public class DddHelper {
|
|
| private String field1 = "...value of field1 in DddHelper.java...";
| public String getField1()
| {
| System.out.println(".................DddHelper/getField1()..............");
|
| DddEJBLocal localref = this.lookupDddEJBBean();
| return localref.getField1() + this.field1;
| }
|
| private DddEJBLocal lookupDddEJBBean() {
| try {
| Context c = new InitialContext();
| DddEJBLocalHome rv = (DddEJBLocalHome) c.lookup("java:comp/env/ejb/DddEJBBeanLocal");
| 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.WelcomeJSFBean***
package ddd.web;
|
| import ddd.ejb.DddHelper;
|
| /**
| *
| * @author sairndain
| */
|
| public class WelcomeJSFBean {
|
| /** Creates a new instance of WelcomeJSFBean */
| public WelcomeJSFBean() {
| }
|
| private String field1 = "...value of field1 in WelcomeJSFBean.java...";
| public String getField1()
| {
| System.out.println(".................WelcomeJSFBean/getField1()..............");
| DddHelper dh = new DddHelper();
| return dh.getField1() + this.field1;
| }
| }
***web.xml***
<?xml version="1.0" encoding="UTF-8"?>
| <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
| <servlet>
| <servlet-name>Faces Servlet</servlet-name>
| <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
| <load-on-startup>1</load-on-startup>
| </servlet>
| <servlet-mapping>
| <servlet-name>Faces Servlet</servlet-name>
| <url-pattern>*.faces</url-pattern>
| </servlet-mapping>
| <session-config>
| <session-timeout>
| 30
| </session-timeout>
| </session-config>
| <welcome-file-list>
| <welcome-file>welcomeJSF.faces</welcome-file>
| </welcome-file-list>
| </web-app>
|
***
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4118913#4118913
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4118913
More information about the jboss-user
mailing list