0 Replies Latest reply on Aug 14, 2002 7:38 AM by Marketta Priha

    How to run Sun J2EE tutorial samples, EJB references, no ejb

    Marketta Priha Newbie

      This information has been written after studying these forum messages:
      1. Porting/migrating J2EE tutorials
      http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ Needs/gives basic advise
      http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ Due to upgrade stopped working
      http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ Got it working finally
      http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ Testing Tomcat without ejb's
      http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ When investigating JBoss it is very natural to try to run the well guided examples in the J2EE Tutorial by Sun. Sometimes you cannot simply port EAR archives. How do you proceed?

      A: (These instructions are valid at least for the 3.0.1 version of JBoss. I presume that you have created the original files following Sun's instructions.)

      For instance the Date application you can simply port by copying the <j2eetutorial>\examples\src\web\date\DateApp.ear file into the JBoss hot deploy directory. Some Sun specific files do not seem to harm, but to be prudent you could remove them.

      The Converter sample is more tricky. This is due to the fact that all of the deployment information has not been defined in the J2EE specification and therefore is vendor specific. (This may change in the J2EE v. 1.4.)
      You have to remove the Sun specific descriptor and replace it with two JBoss specific descriptors. Here are the instructions about the content of the EAR.


      j2ee-tutor-converter.ear is packed from these files
      ---------------------------------------------------
      META-INF
      ----application.xml (1)
      ----MANIFEST.MF
      ejb-jar-ic.jar (A)
      war-ic.war (B)

      ejb-jar-ic.jar (A) is packed from these files
      ---------------------------------------------
      META-INF
      ----jboss.xml (2)
      ----ejb-jar.xml (3)
      ----MANIFEST.MF
      ConverterHome.class
      ConverterBean.class
      Converter.class

      war-ic.war (B) is packed from these files
      -----------------------------------------
      WEB-INF
      ----jboss-web.xml (4)
      ----web.xml (5)
      META-INF
      ----MANIFEST.MF
      index.jsp (6)


      application.xml (1) - standard, taken as such
      ---------------------------------------------
      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN' 'http://java.sun.com/dtd/application_1_3.dtd'>


      <display-name>ConverterApp</display-name>
      Application description


      <web-uri>war-ic.war</web-uri>
      <context-root>converter</context-root>



      ejb-jar-ic.jar



      jboss.xml (2) - vendor specific, modified from sun-j2ee-ri.xml
      --------------------------------------------------------------
      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd">


      <enterprise-beans>

      <ejb-name>ConverterEJB</ejb-name>
      <jndi-name>MyConverter</jndi-name>

      </enterprise-beans>


      ejb-jar.xml (3) - standard, taken as such
      ------------------------------------------
      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>

      <ejb-jar>
      <display-name>ConverterJAR</display-name>
      <enterprise-beans>

      This is my first EJB ConverterBean
      <display-name>ConverterEJB</display-name>
      <ejb-name>ConverterEJB</ejb-name>
      ConverterHome
      Converter
      <ejb-class>ConverterBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Bean</transaction-type>
      <security-identity>

      <use-caller-identity></use-caller-identity>
      </security-identity>

      </enterprise-beans>
      <assembly-descriptor>
      <method-permission>


      <ejb-name>ConverterEJB</ejb-name>
      <method-intf>Home</method-intf>
      <method-name>remove</method-name>
      <method-params>
      <method-param>java.lang.Object</method-param>
      </method-params>


      <ejb-name>ConverterEJB</ejb-name>
      <method-intf>Remote</method-intf>
      <method-name>yenToEuro</method-name>
      <method-params>
      <method-param>java.math.BigDecimal</method-param>
      </method-params>


      <ejb-name>ConverterEJB</ejb-name>
      <method-intf>Remote</method-intf>
      <method-name>getHandle</method-name>
      <method-params />


      <ejb-name>ConverterEJB</ejb-name>
      <method-intf>Home</method-intf>
      <method-name>remove</method-name>
      <method-params>
      <method-param>javax.ejb.Handle</method-param>
      </method-params>


      <ejb-name>ConverterEJB</ejb-name>
      <method-intf>Home</method-intf>
      <method-name>getHomeHandle</method-name>
      <method-params />


      <ejb-name>ConverterEJB</ejb-name>
      <method-intf>Remote</method-intf>
      <method-name>getPrimaryKey</method-name>
      <method-params />


      <ejb-name>ConverterEJB</ejb-name>
      <method-intf>Home</method-intf>
      <method-name>getEJBMetaData</method-name>
      <method-params />


      <ejb-name>ConverterEJB</ejb-name>
      <method-intf>Remote</method-intf>
      <method-name>remove</method-name>
      <method-params />


      <ejb-name>ConverterEJB</ejb-name>
      <method-intf>Home</method-intf>
      <method-name>create</method-name>
      <method-params />


      <ejb-name>ConverterEJB</ejb-name>
      <method-intf>Remote</method-intf>
      <method-name>isIdentical</method-name>
      <method-params>
      <method-param>javax.ejb.EJBObject</method-param>
      </method-params>


      <ejb-name>ConverterEJB</ejb-name>
      <method-intf>Remote</method-intf>
      <method-name>getEJBHome</method-name>
      <method-params />


      <ejb-name>ConverterEJB</ejb-name>
      <method-intf>Remote</method-intf>
      <method-name>dollarToYen</method-name>
      <method-params>
      <method-param>java.math.BigDecimal</method-param>
      </method-params>

      </method-permission>
      </assembly-descriptor>
      </ejb-jar>

      jboss-web.xml (4) - vendor specific
      --- necessary to avoid no ejb-link match error
      ----------------------------------------------
      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.3//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_3_0.dtd">

      <jboss-web>
      <ejb-ref>
      <ejb-ref-name>ejb/TheConverter</ejb-ref-name>
      <jndi-name>MyConverter</jndi-name>
      </ejb-ref>
      </jboss-web>

      web.xml (5) - standard, taken as such
      -------------------------------------
      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 'http://java.sun.com/dtd/web-app_2_3.dtd'>

      <web-app>
      <display-name>ConverterWAR</display-name>

      <servlet-name>Converter Index Page</servlet-name>
      <display-name>Converter Index Page</display-name>
      Converter index page JSP file for demo purpose.
      <jsp-file>/index.jsp</jsp-file>

      <session-config>
      <session-timeout>30</session-timeout>
      </session-config>
      <ejb-ref>
      <ejb-ref-name>ejb/TheConverter</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      ConverterHome
      Converter
      </ejb-ref>
      </web-app>

      index.jsp (6) - standard, taken as such
      ---------------------------------------
      <%--

      Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.

      This software is the proprietary information of Sun Microsystems, Inc.
      Use is subject to license terms.

      --%>

      <%@ page import="Converter,ConverterHome,javax.ejb.*, java.math.*, javax.naming.*, javax.rmi.PortableRemoteObject, java.rmi.RemoteException" %>
      <%!
      private Converter converter = null;

      public void jspInit() {
      try {
      InitialContext ic = new InitialContext();
      Object objRef = ic.lookup("java:comp/env/ejb/TheConverter");
      ConverterHome home = (ConverterHome)PortableRemoteObject.narrow(objRef, ConverterHome.class);
      converter = home.create();
      } catch (RemoteException ex) {
      System.out.println("Couldn't create converter bean."+ ex.getMessage());
      } catch (CreateException ex) {
      System.out.println("Couldn't create converter bean."+ ex.getMessage());
      } catch (NamingException ex) {
      System.out.println("Unable to lookup home: "+ "TheConverter "+ ex.getMessage());
      }
      }

      public void jspDestroy() {
      converter = null;
      }
      %>


      Converter



      <h1>Converter</h1>

      Enter an amount to convert:








      <%
      String amount = request.getParameter("amount");
      if ( amount != null && amount.length() > 0 ) {
      BigDecimal d = new BigDecimal (amount);
      %>

      <%= amount %> dollars are <%= converter.dollarToYen(d) %> Yen.

      <%= amount %> Yen are <%= converter.yenToEuro(d) %> Euro.
      <%
      }
      %>