Packaging message-driven rule beans

To package a client by using message-driven rule beans (MDB), you write and compile the client code, and edit the deployment descriptors. Then, you put the MDB JAR file and all the other files into the relevant archive files.

About this task

For more information about creating a Java™ Message Service (JMS) connection factory, see the appropriate topic, depending on your application server:

Procedure

To package an application by using a QueueConnectionFactory object:

  1. Write and compile the client code, including the following basic tasks:
    • Locating the connection factory and queue
    • Creating the queue connection and session
    • Sending a message to the queue to call a business method
  2. Write the user interface by using JavaServer Pages (JSP), servlets, or front-end Enterprise JavaBeans (EJB).
  3. Edit the deployment descriptors.
    • Inside the ejb-jar.xml file, you can define a java.lang.Boolean property named traceEnabled. This property enables a trace mode to print the incoming message to System.out.
    • You also can edit the names of the JMS resources (queues, topics, connection factories) by updating your MDB JAR file META-INF/ejb-jar.xml.
  4. Package the .class, .jsp, and .html files, and deployment descriptors into the appropriate archive files.

    You must assemble the application modules into a Java EE application EAR file, including the jrules-res-mdb-<appserver>.jar. You can edit the deployment descriptors directly or use a tool to add XML tags.

    In your application.xml file, add the following code, where appserver is the relevant application server, for example, WAS8.5 for WebSphere Application Server 8.5.
    <application>
       <display-name>RES MDB</display-name>
       <description>RES MDB sample</description>
       ...
       <module>
          <ejb>jrules-res-mdb-appserver.jar</ejb>
       </module> 
       ...
    </application>

    You can package the Java XOM in different ways. The simplest way is put the classes into a JAR file, then package the archive with the MDB EJB JAR file in the same EAR file.

    By default, the message-driven rule bean is provided with support for container-managed transactions, as indicated by the following line in the deployment descriptor file ejb-jar.xml: <trans-attribute>Required</trans-attribute>

    Note:
    If you use WebSphere Application Server in secure mode, the client application that uses and packages the Rule Execution Server rule sessions requires a META-INF/was.policy file. Write this file as shown in the following example. appserver is a placeholder for the appropriate application server: for example, WAS8.5 for WebSphere Application Server 8.5. Specify the JAR file name that matches your WebSphere Application Server version number.
    grant codeBase "file:jrules-res-mdb-WAS85.jar" {
        /* Classloader */
        permission java.lang.RuntimePermission "getClassLoader";
        permission java.lang.RuntimePermission "setContextClassLoader";
        permission java.io.FilePermission "${java.io.tmpdir}${/}-", "read,write,delete";
        /* Log */
        permission java.io.FilePermission "${was.install.root}${/}-", "read,write";
        permission java.io.FilePermission "${user.install.root}${/}-", "read,write";
        /* MBean plugin */
        permission com.ibm.websphere.security.WebSphereRuntimePermission "AdminPermission";
        permission javax.management.MBeanPermission "*", "*";
        permission java.util.PropertyPermission "*", "read,write";
        /* XU Config */
        permission java.lang.RuntimePermission "accessDeclaredMembers";
        permission java.net.NetPermission "specifyStreamHandler";
    };