6 Replies Latest reply on Sep 16, 2002 10:38 AM by Chris Bailey

    Bean deployment example

    Mads Hansen Newbie

      Hi

      Does anyone have an example of how to deploy beans (session and entity) in JBoss 3. I'm reading the book "Mastering EJB 2" and going through the examples. I would like to deploy the examples to JBoss but I have failed in finding documentation on how to deploy beans in JBoss.

      /Mads

        • 1. Re: Bean deployment example
          patrick Novice

          The documentation examples are written for jboss 2.4 but 3.0 also works with a bit of work.

          Deployment of the files (jar's war'w ear's) go to $JBOSS_DIST/server/default/deploy

          • 2. Re: Bean deployment example
            Javier Torreblanca Beltran Newbie

            Mads,
            I´m using the same book and I have running the examples (Session beans (Stateless and Stateful), Entity beans (BMP and CMP 2.0) and Message-driven beans), I will prepare a instructions document of this, but in this moment I have the first part (Session stateless bean) at :

            http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ attached a primerEJB.ear file but it doesn´t work because I used my IP address server in JSP file, you need to follow the instructions for create a new EAR file with your IP address server.

            I see another workbook at :

            http://www.monson-haefel.com/titanbooks/download.html

            This book explains many EJB examples using JBoss 3.0.

            Regards

            Javier

            • 3. Re: Bean deployment example
              Mads Hansen Newbie

              Thanks for the help.

              Javier, do you have the Accout example (BMP example) up an running? If so do you have any pointers to the procedure? I'm using postgresql. So, far this is what I have (see http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/

              • 4. Re: Bean deployment example
                Mads Hansen Newbie

                I figured my problem out. I had to put the postgresql jdbc file in $(JONAS_HOME)/server/default/deploy instead of $(JONAS_HOME)/lib.

                • 5. Re: Bean deployment example
                  Javier Torreblanca Beltran Newbie

                  Mads,
                  Yes, I have running the account example. I will give you the procedure.

                  1. First you need to install the database server. Create your database and your accounts table with the following fields: id (varchar(64)), ownername (varchar(64)) and balance(double).

                  2. I use MySql but I see the postgres-service.xml and it seems like to mysql-service.xml.
                  You can get postgres-service.xml file from $(JBOSS_HOME)/docs/examples/jca or from http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jboss/jbosscx/src/etc/example-config.

                  3. Copy postgres-service.xml file into $(JBOSS_HOME)/server/default/deploy.
                  4. Edit postgres-service.xml file :
                  4.1. Uncomment <application-policy name = "PostgresDbRealm"> tag.
                  4.2. Set the correct values in the following lines :

                  <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required">
                  <module-option name = "principal">yourprincipal</module-option>
                  <module-option name = "userName">yourusername</module-option>
                  <module-option name = "password">yourpassword</module-option>
                  <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=PostgresDS</module-option>
                  </login-module>

                  yourprincipal : in this tag you need to set your database username, this user must be administrator or must have administrator privilegies.
                  yourusername : in this tag you need to set your database username, this user must be administrator or must have administrator privilegies.
                  yourpassword : in this tag you need to set your database password.

                  For example if I have the following user (username=adm and password admcc) then :

                  <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required">
                  <module-option name = "principal">adm</module-option>
                  <module-option name = "userName">adm</module-option>
                  <module-option name = "password">admcc</module-option>
                  <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=PostgresDS</module-option>
                  </login-module>

                  4.3. Uncomment PostgresDbRealm tag.
                  4.4. Set the correct values in the following line (servername,port,database name):

                  <config-property name="ConnectionURL" type="java.lang.String">jdbc:postgresql://[servername]:[port]/[database name]</config-property>

                  4.5. In the following lines, use the same database username that you use in the 4.2 step.

                  <config-property name="UserName" type="java.lang.String"></config-property>
                  <config-property name="Password" type="java.lang.String"></config-property>

                  For example, using the same user :

                  <config-property name="UserName" type="java.lang.String">adm</config-property>
                  <config-property name="Password" type="java.lang.String">admcc</config-property>

                  In the end of this step you can get the following postgres-service.xml file :

                  <?xml version="1.0" encoding="UTF-8"?>
                  <!-- ======================================================================================== -->
                  <!-- New ConnectionManager setup for default PostgreSQL dbs -->
                  <!-- Build jmx-api (build/build.sh all) and view for config documentation -->
                  <!-- To avoid class not found headaches, copy your postgres driver to the jboss lib directory -->
                  <!-- ======================================================================================== -->




                  <!-- ======================================================= -->
                  <!-- You must include a login module configuration named PostgresDbRealm
                  in your login-conf.xml, here is an example for a
                  ConfiguredIdentityLoginModule:
                  -->
                  <application-policy name = "PostgresDbRealm">

                  <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required">
                  <module-option name = "principal">yourusername</module-option>
                  <module-option name = "userName">yourusername</module-option>
                  <module-option name = "password">yourpassword</module-option>
                  <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=PostgresDS</module-option>
                  </login-module>

                  </application-policy>
                  <!--
                  NOTE: the application-policy name attribute must match SecurityDomainJndiName, and the
                  module-option name = "managedConnectionFactoryName"
                  must match the object name of the ConnectionManager you are configuring here.
                  -->
                  <!-- ===================================================================== -->
                  <!--uncomment out this line if you are using the PostgresDbRealm above
                  -->
                  PostgresDbRealm

                  <depends optional-attribute-name="ManagedConnectionFactoryName">
                  <!--embedded mbean-->

                  <!-- ========== Set the JndiName ======================= -->
                  PostgresDS


                  <config-property name="ConnectionURL" type="java.lang.String">jdbc:postgresql://[servername]:[port]/[database name]</config-property>
                  <config-property name="DriverClass" type="java.lang.String">org.postgresql.Driver</config-property>
                  <!--set these only if you want only default logins, not through JAAS -->
                  <config-property name="UserName" type="java.lang.String">yourusername</config-property>
                  <config-property name="Password" type="java.lang.String">yourpassword</config-property>




                  <!--Below here are advanced properties -->
                  <!--hack-->
                  <depends optional-attribute-name="OldRarDeployment">jboss.jca:service=RARDeployment,name=JBoss LocalTransaction JDBC Wrapper

                  <!--real attributes-->



                  <depends optional-attribute-name="ManagedConnectionPool">
                  <!--embedded mbean-->


                  0
                  50
                  5000
                  15
                  <!--criteria indicates if Subject (from security domain) or app supplied
                  parameters (such as from getConnection(user, pw)) are used to distinguish
                  connections in the pool. Choices are
                  ByContainerAndApplication (use both),
                  ByContainer (use Subject),
                  ByApplication (use app supplied params only),
                  ByNothing (all connections are equivalent, usually if adapter supports
                  reauthentication)-->
                  ByContainer



                  <depends optional-attribute-name="CachedConnectionManager">jboss.jca:service=CachedConnectionManager

                  <depends optional-attribute-name="JaasSecurityManagerService">jboss.security:service=JaasSecurityManager

                  java:/TransactionManager
                  <!--make the rar deploy! hack till better deployment-->
                  jboss.jca:service=RARDeployer







                  5. Edit login-config.xml file. This file is in %JBOSS_HOME%/server/default/conf. You need to add the following lines after <application-policy name = "HsqlDbRealm"> tag.

                  <application-policy name = "PostgresDbRealm">

                  <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required">
                  <module-option name = "principal">yourusername</module-option>
                  <module-option name = "userName">yourusername</module-option>
                  <module-option name = "password">yourpassword</module-option>
                  <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=MySqlDS</module-option>
                  </login-module>

                  </application-policy>

                  The application-policy name must be equal to application-policy name used in postgres-service.xml file.
                  yourprincipal is the same username used in the postgres-service.xml.
                  yourusername is the same username used in the postgres-service.xml.
                  yourpassword is the same password used in the postgres-service.xml.

                  In the end you have the following login-config.xml file :

                  <?xml version='1.0'?>
                  <!DOCTYPE policy PUBLIC
                  "-//JBoss//DTD JBOSS Security Config 3.0//EN"
                  "http://www.jboss.org/j2ee/dtd/security_config.dtd">

                  <!-- The XML based JAAS login configuration read by the
                  org.jboss.security.auth.login.XMLLoginConfig mbean. Add
                  an application-policy element for each security domain.

                  The outline of the application-policy is:
                  <application-policy name="security-domain-name">

                  <login-module code="login.module1.class.name" flag="control_flag">
                  <module-option name = "option1-name">option1-value</module-option>
                  <module-option name = "option2-name">option2-value</module-option>
                  ...
                  </login-module>

                  <login-module code="login.module2.class.name" flag="control_flag">
                  ...
                  </login-module>
                  ...

                  </application-policy>

                  $Revision: 1.1.2.4 $
                  -->


                  <!-- Used by clients within the application server VM such as
                  mbeans and servlets that access EJBs.
                  -->
                  <application-policy name = "client-login">

                  <login-module code = "org.jboss.security.ClientLoginModule"
                  flag = "required">
                  </login-module>

                  </application-policy>

                  <!-- Security domain for JBossMQ -->
                  <application-policy name = "jbossmq">

                  <login-module code = "org.jboss.mq.sm.file.DynamicLoginModule"
                  flag = "required">
                  <module-option name = "unauthenticatedIdentity">guest</module-option>
                  <module-option name = "sm.objectname">jboss.mq:service=StateManager</module-option>
                  </login-module>

                  </application-policy>

                  <!-- Security domains for testing new jca framework -->
                  <application-policy name = "HsqlDbRealm">

                  <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule"
                  flag = "required">
                  <module-option name = "principal">sa</module-option>
                  <module-option name = "userName">sa</module-option>
                  <module-option name = "password"></module-option>
                  <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=hsqldbDS</module-option>
                  </login-module>

                  </application-policy>

                  <application-policy name = "PostgresDbRealm">

                  <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required">
                  <module-option name = "principal">yourusername</module-option>
                  <module-option name = "userName">yourusername</module-option>
                  <module-option name = "password">yourpassword</module-option>
                  <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=MySqlDS</module-option>
                  </login-module>

                  </application-policy>

                  <application-policy name = "FirebirdDBRealm">

                  <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule"
                  flag = "required">
                  <module-option name = "principal">sysdba</module-option>
                  <module-option name = "userName">sysdba</module-option>
                  <module-option name = "password">masterkey</module-option>
                  <module-option name = "managedConnectionFactoryName">jboss.jca:service=XaTxCM,name=FirebirdDS</module-option>
                  </login-module>

                  </application-policy>

                  <application-policy name = "JmsXARealm">

                  <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule"
                  flag = "required">
                  <module-option name = "principal">guest</module-option>
                  <module-option name = "userName">guest</module-option>
                  <module-option name = "password">guest</module-option>
                  <module-option name = "managedConnectionFactoryName">jboss.jca:service=XaTxCM,name=jmsra</module-option>
                  </login-module>

                  </application-policy>

                  <!-- A template configuration for the jmx-console web application. This
                  defaults to the UsersRolesLoginModule the same as other and should be
                  changed to a stronger authentication mechanism as required.
                  -->
                  <application-policy name = "jmx-console">

                  <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
                  flag = "required" />

                  </application-policy>

                  <!-- The default login configuration used by any security domain that
                  does not have a application-policy entry with a matching name
                  -->
                  <application-policy name = "other">
                  <!-- A simple server login module, which can be used when the number
                  of users is relatively small. It uses two properties files:
                  users.properties, which holds users (key) and their password (value).
                  roles.properties, which holds users (key) and a comma-separated list of
                  their roles (value).
                  The unauthenticatedIdentity property defines the name of the principal
                  that will be used when a null username and password are presented as is
                  the case for an unuathenticated web client or MDB. If you want to
                  allow such users to be authenticated add the property, e.g.,
                  unauthenticatedIdentity="nobody"
                  -->

                  <login-module code = "org.jboss.security.auth.spi.UsersRolesLoginModule"
                  flag = "required" />

                  </application-policy>




                  6. Edit standardjaws.xml file. This file is in %JBOSS_HOME%/server/default/conf.
                  Comment the following lines :

                  java:/DefaultDS
                  <type-mapping>Hypersonic SQL</type-mapping>

                  Add the following lines :

                  java:/PostgresDS
                  <type-mapping>PostgreSQL</type-mapping>

                  In the end you have the following standardjaws.xml file :

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

                  <!DOCTYPE jbosscmp-jdbc PUBLIC
                  "-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN"
                  "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd">

                  <!-- ===================================================================== -->
                  <!-- -->
                  <!-- Standard Jaws Configuration -->
                  <!-- -->
                  <!-- ===================================================================== -->

                  <!-- $Id: standardjaws.xml,v 1.27.2.3 2002/06/27 19:54:12 dsundstrom Exp $ -->


                  <!--
                  java:/DefaultDS
                  <type-mapping>Hypersonic SQL</type-mapping>
                  -->
                  java:/PostgresDS
                  <type-mapping>PostgreSQL</type-mapping>
                  false

                  <default-entity>
                  <create-table>true</create-table>
                  <remove-table>false</remove-table>
                  <tuned-updates>true</tuned-updates>
                  <read-only>false</read-only>
                  <time-out>300</time-out>
                  <row-locking>false</row-locking>
                  <read-ahead>false</read-ahead>
                  </default-entity>
                  .........
                  .........
                  .........
                  .
                  .

                  7. Copy the jdbc file (jar) for PostgreSQL into %JBOSS_HOME%\server\default\lib

                  8. Move hsqldb-service.xml file from %JBOSS_HOME%\server\default\deploy to another directory where JBoss doesn´t take it.

                  9. Modify AccountBean.java, edit the getConnection() method in the following line, you need to set your JNDI name:

                  javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("java:/PostgresDS");

                  10. Compile your java files.

                  11. Create ejb-jar.xml file with the following lines :

                  <?xml version="1.0"?>

                  <!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>
                  <enterprise-beans>

                  <ejb-name>Account</ejb-name>
                  com.bmp.AccountHome
                  com.bmp.Account
                  <local-home>com.bmp.AccountLocalHome</local-home>
                  com.bmp.AccountLocal
                  <ejb-class>com.bmp.AccountBean</ejb-class>
                  <persistence-type>Bean</persistence-type>
                  <prim-key-class>com.bmp.AccountPK</prim-key-class>
                  False

                  <resource-ref>
                  <res-ref-name>java:/PostgresDS</res-ref-name>
                  <res-type>javax.sql.DataSource</res-type>
                  <res-auth>Container</res-auth>
                  </resource-ref>

                  </enterprise-beans>
                  <assembly-descriptor>
                  <container-transaction>

                  <ejb-name>Account</ejb-name>
                  <method-intf>Local</method-intf>
                  <method-name>*</method-name>


                  <ejb-name>Account</ejb-name>
                  <method-intf>Remote</method-intf>
                  <method-name>*</method-name>

                  <trans-attribute>Required</trans-attribute>
                  </container-transaction>
                  </assembly-descriptor>
                  </ejb-jar>



                  12. Create the JAR file (account.jar).

                  jar -cvfM account.jar com META-INF WEB-INF

                  13. Start PostgreSQL server.

                  14. Start JBoss Server.

                  15. Run client using the following instruction :

                  java -classpath %classpath%;/com/bmp/Account/src;%JBOSS_HOME%/client/jboss-client.jar;%JBOSS_HOME%/client/jboss-j2ee.jar;%JBOSS_HOME%/client/jnp-client.jar;%JBOSS_HOME%/client/jboss-common-client.jar;%JBOSS_HOME%/client/log4j.jar;%JBOSS_HOME%/client/jbosssx-client.jar;%JBOSS_HOME%/client/jnet.jar -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.provider.url=jnp://13.134.79.127:1099 -Djava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces com.bmp.AccountClient

                  Note : Change the following line :

                  -Djava.naming.provider.url=jnp://13.134.79.127:1099

                  You need set you IP Address JBoss server

                  -Djava.naming.provider.url=jnp://[your IP address]:1099


                  Regards

                  Javier

                  • 6. Security Config not found
                    Chris Bailey Newbie

                    Interesting that your example worked. Does it still?

                    Even some of the security examples from the JBoss literature fail now, did the security_config.dtd get removed from the JBoss web site?

                    Here the error deploying chapter 8 example 1

                    09:22:38,495 ERROR [MainDeployer] could not start deployment: njar:file:/C:/jboss3/server/default/tmp/deploy/server/default/deploy/chap8-ex1.jar/63.chap8-ex1.jar^/chap8-ex1.sar
                    org.jboss.deployment.DeploymentException: External entity not found: "http://www.jboss.org/j2ee/dtd/security_config.dtd".; - nested throwable: (java.net.ConnectException: Connection refused: connect)

                    Thanks,

                    Chris