[jboss-user] [EJB/JBoss] - Re: What is wrong with my local ejb JNDI lookup code (or the

sairndain do-not-reply at jboss.com
Sun Jan 13 22:18:22 EST 2008


Apparently, jboss.xml, jboss-web.xml, jboss-application.xml are not required... at least in this simple "enterprise" project I created.   

What is not clear is whether the jboss*.xml configuration files allow JBoss to provide some other benefit -- other than short JNDI names.

Anyway this is the code for those interested I've included the code in this post (see below)...

If anyone knows what other benefits the "jboss*.xml" provide, please post it... -Thanks in advance!

sd


environment:
Windows XP
NetBeans 6.0 ide
JBoss4.0.4GA
EJB 2.1
J2EE 1.4.x


----------EAR----------
application.xml configuration file

  | <?xml version="1.0" encoding="UTF-8"?>
  | <application version="1.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/application_1_4.xsd">
  |   <display-name>jjjEAR</display-name>
  |   <module>
  |     <web>
  |       <web-uri>jjjEAR-war.war</web-uri>
  |       <context-root>/jjjEAR-war</context-root>
  |     </web>
  |   </module>
  |   <module>
  |     <ejb>jjjEAR-ejb.jar</ejb>
  |   </module>
  | </application>
  | 

----------EJB Module----------

jjj.ejb.JjjEJBBean  stateless session bean (I'm not including the remote and local interface files here because they are standard fare)

  | package jjj.ejb;
  | 
  | import javax.ejb.SessionBean;
  | import javax.ejb.SessionContext;
  | 
  | public class JjjEJBBean 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() {
  |         
  |     }
  |     
  |     public void ejbCreate() {
  |     }
  | 
  |     private String field1 = "...value of field1 in jjj.ejb.JjjEJBBean (in EJB module)...";
  |     public String getField1() {
  |         return this.field1;
  |     }
  | }
  | 

ejb-jar.xml  configuration file

  | <?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>JjjEJBSB</display-name>
  |             <ejb-name>JjjEJBBean</ejb-name>
  |             <home>jjj.ejb.JjjEJBRemoteHome</home>
  |             <remote>jjj.ejb.JjjEJBRemote</remote>
  |             <local-home>jjj.ejb.JjjEJBLocalHome</local-home>
  |             <local>jjj.ejb.JjjEJBLocal</local>
  |             <ejb-class>jjj.ejb.JjjEJBBean</ejb-class>
  |             <session-type>Stateless</session-type>
  |             <transaction-type>Container</transaction-type>
  |         </session>
  |         
  |         <ejb-ref>
  |             <ejb-ref-name>JjjEJBBean</ejb-ref-name>
  |             <ejb-ref-type>Session</ejb-ref-type>
  |             <home>jjj.ejb.JjjEJBRemoteHome</home>
  |             <remote>jjj.ejb.JjjEJBRemote</remote>
  |             <ejb-link>jjjEAR-ejb.jar#JjjEJBBean</ejb-link>
  |         </ejb-ref>
  |         <ejb-local-ref>
  |             <ejb-ref-name>JjjEJBLocalHome</ejb-ref-name>
  |             <ejb-ref-type>Session</ejb-ref-type>
  |             <local-home>jjj.ejb.JjjEJBLocalHome</local-home>
  |             <local>jjj.ejb.JjjEJBLocal</local>
  |             <ejb-link>jjjEAR-ejb.jar#JjjEJBBean</ejb-link>
  |         </ejb-local-ref>
  |         
  |     </enterprise-beans>
  |     <assembly-descriptor>
  |         <container-transaction>
  |             <method>
  |                 <ejb-name>JjjEJBBean</ejb-name>
  |                 <method-name>*</method-name>
  |             </method>
  |             <trans-attribute>Required</trans-attribute>
  |         </container-transaction>
  |     </assembly-descriptor>
  | </ejb-jar>
  | 


----------WEB Module----------

jjj.web.JjjBean   POJO

  | package jjj.web;
  | 
  | import java.rmi.RemoteException;
  | import javax.ejb.CreateException;
  | import javax.naming.Context;
  | import javax.naming.InitialContext;
  | import javax.naming.NamingException;
  | import jjj.ejb.JjjEJBLocal;
  | import jjj.ejb.JjjEJBLocalHome;
  | import jjj.ejb.JjjEJBRemote;
  | import jjj.ejb.JjjEJBRemoteHome;
  | 
  | public class JjjBean {
  | 
  |     private String field1RemoteLookup = "...value of field1LocalLookup in jjj.web.JjjBean in WEB module...";
  |     public String getField1RemoteLookup() throws RemoteException
  |     {
  |         JjjEJBRemote remoteRef = this.lookupJjjEJBRemote();
  |         return  remoteRef.getField1() + this.field1RemoteLookup;
  |     }
  | 
  |     private String field1LocalLookup = "...value of field1LocalLookup in jjj.web.JjjBean...";
  |     public String getField1LocalLookup()
  |     {
  |         JjjEJBLocal localRef = this.lookupJjjEJBLocal();
  |         return localRef.getField1() + this.field1LocalLookup;
  |     }
  |     
  |     
  |     private JjjEJBLocal lookupJjjEJBLocal() {
  |         try {
  |             Context c = new InitialContext();
  |             JjjEJBLocalHome rv = (JjjEJBLocalHome) c.lookup("java:comp/env/JjjEJBLocalHome");
  |             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);
  |         }
  |     }
  | 
  |     private JjjEJBRemote lookupJjjEJBRemote() {
  |         try {
  |             Context c = new InitialContext();
  |             Object remote = c.lookup("java:comp/env/JjjEJBBean");
  |             JjjEJBRemoteHome rv = (JjjEJBRemoteHome) javax.rmi.PortableRemoteObject.narrow(remote, jjj.ejb.JjjEJBRemoteHome.class);
  |             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);
  |         } catch (RemoteException re) {
  |             java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, "exception caught", re);
  |             throw new RuntimeException(re);
  |         }
  |     }
  | }
  | 

index.jsp   web page

  | <%@page contentType="text/html"%>
  | <%@page pageEncoding="UTF-8"%>
  | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  | <html>
  |     <head>
  |         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  |         <title>JSP Page</title>
  |     </head>
  |     <body>
  |         <jsp:useBean id="jjjBean" class="jjj.web.JjjBean" scope="request" />
  | 
  |     <h1>value of field1 - remote lookup...</h1>
  |     <jsp:getProperty name="jjjBean" property="field1RemoteLookup" />
  | 
  |     <h1>value of field1 - local lookup...</h1>
  |     <jsp:getProperty name="jjjBean" property="field1LocalLookup" />
  |    
  |     </body>
  | </html>
  | 

web.xml  configuration file

  | <?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">
  |     <session-config>
  |         <session-timeout>
  |             30
  |         </session-timeout>
  |     </session-config>
  |     <welcome-file-list>
  |         <welcome-file>index.jsp</welcome-file>
  |     </welcome-file-list>
  |     <ejb-ref>
  |         <ejb-ref-name>JjjEJBBean</ejb-ref-name>
  |         <ejb-ref-type>Session</ejb-ref-type>
  |         <home>jjj.ejb.JjjEJBRemoteHome</home>
  |         <remote>jjj.ejb.JjjEJBRemote</remote>
  |         <ejb-link>jjjEAR-ejb.jar#JjjEJBBean</ejb-link>
  |     </ejb-ref>
  |     <ejb-local-ref>
  |         <ejb-ref-name>JjjEJBLocalHome</ejb-ref-name>
  |         <ejb-ref-type>Session</ejb-ref-type>
  |         <local-home>jjj.ejb.JjjEJBLocalHome</local-home>
  |         <local>jjj.ejb.JjjEJBLocal</local>
  |         <ejb-link>jjjEAR-ejb.jar#JjjEJBBean</ejb-link>
  |     </ejb-local-ref>
  | </web-app>
  | 



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4119490#4119490

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4119490



More information about the jboss-user mailing list