External Resource

This chapter describes a variety of external resources that can be used to build a system by integrating with JEUS, and how to configure them. Refer to each external resource guide for more information about configuring external resources and their usage.

1. Resource Types

External resources exist outside JEUS, and applications can access them through JEUS. A typical example is a database. Resources like these can be accessed by adding related configurations to JEUS.

If an external resource provides a resource adapter with JCA standard compatibility, it is recommended to deploy and use the provided resource adapter.

The following are the resources that can be configured in JEUS.

  • Data Source

    A client can directly access a data source without adding any configurations to JEUS. However, configuring a data source enables applications to more easily access databases by using JDBC connection pool through JNDI. Refer to DB Connection Pool and JDBC for more information about data source configurations.

  • Mail Resource

    A mail resource is used by a client application to send an e-mail by using a mail protocol like SMTP. In JEUS, a mail resource binds the e-mail host information to the JNDI export name and allows the client to indirectly gain access to the host.

    A mail resource of the jakarta.mail.Session type can be obtained through JNDI lookup.

  • URL Resource

    A URL resource allows applications to access the external URL objects through JNDI. If a URL changes, the URL configuration is modified and the applications can continue to use the resource without source modification.

    A URL object of the java.net.URL type can be obtained through JNDI lookup.

  • Message Bridge

    A bridge for connection between destinations of different JMS vendors. An MQ that complies with the Jakarta Messaging 2.0 specification can be configured without any limitations. For more information, refer to JEUS MQ Message Bridge in JEUS MQ Guide.

  • Custom Resource

    A custom resource allows a Java bean resource to be bound to the JNDI repository. It is a typical resource that performs a lookup by using a service that is registered through the JNDI ObjectFactory.

  • External Resources - IBM MQ and Sonic MQ

    Denormalized resources that can be connected to JEUS. Usually, Jakarta Messaging products of IBM MQ or Sonic MQ and Tmax TP Monitor can be configured in JEUS. These resources can also be accessed directly via Java APIs without being configured in JEUS. However, to manage these resources from the transaction manager, they need to be configured in JEUS. For more information, refer to Transaction Manager.

  • External Resource

    Resources running on JEUS. They are usually used by WebT, jTmax, or InfiniteCache that are integrated with JEUS. A class that implements the jeus.external.ResourceBootstrapper interface must be used to access the external resources in JEUS.

  • Concurrency Utilities Resource

    Defines resources related to Jakarta Concurrency. This allows you to define manageable tasks on the application server and maintain context and operate when the tasks are executed. For more information, see JEUS Jakarta Concurrency Guide.

2. Resource Configuration

This section describes how to configure each resource.

Resources are configured within the scope of the domain and registered on a server when the server starts.

2.1. Configuring a Data Source

Data sources handle configurations that are related to the database. For more information, refer to DB Connection Pool and JDBC.

2.2. Configuring a Mail Source

A mail source can be used to configure an SMTP host that is used by a client application to send an e-mail to JEUS. Refer to the Jakarta Mail specification for more information about e-mail hosts.

You can set the mail source by editing domain.xml as follows:

<servers>
    <server>
        <name>server1</name>
        ...
        <resources>
            <mail-source>
                <mail-entry>
                    <export-name>mailSource</export-name>
                    <mail-property>
                        <name>mail.smtp.auth</name>
                        <value>true</value>
                    </mail-property>
                </mail-entry>
            </mail-source>
        </resource>
    </server>
</servers>

Since the property names in the 'Mail Property' section follow the Jakarta Mail specification, refer to the corresponding specification for each property configuration.

2.3. Configuring a URL Source

The following values are bound to the JNDI names, PRIMARY_URL and SECONDARY_URL respectively.

http://www.foo.com
http://www.bar.com

Edit domainl.xml as follows to set the URL source.

<resources>
    <url-source>
        <url-entry>
            <export-name>PRIMARY_URL</export-name>
            <url>http://www.foo.com</url>
        </url-entry>
        <url-entry>
            <export-name>SECONDARY_URL</export-name>
            <url>http://www.bar.com</url>
        </url-entry>
    </url-source>
</resources>

2.4. Configuring a Custom Resource

Custom resources enable the lookup and use of Java bean resources through JNDI ObjectFactory. This section describes how to configure and register custom resources.

The following is an example of an object factory class that creates a Java bean resource class and resource instance. This class must be exist in the 'SERVER_HOME/lib/application' or 'DOMAIN_HOME/lib/application' directory.

Factory Class Example that Creates Custom Resources
package dog;

import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.spi.ObjectFactory;

public class DogFactory implements ObjectFactory {
    public DogFactory() {}

    public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment)
        throws Exception {
        Dog dog = Dog.getInstance();
        System.out.println("Creating a dog whose name is " + dog.getName() + ",
and age is " + dog.getAge());
        return dog;
    }
}
Custom Resource Class Example
package dog;

public class Dog implements java.io.Serializable {
    public static final String DOG_NAME = "wangwang";
    public static final int DOG_AGE = 1;

    private static Dog instance = new Dog();

    private int age = DOG_AGE;
    private String name = DOG_NAME;

    public Dog() {}

    public static Dog getInstance() {
        return instance;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean equals(Object anObject) {
        if (this == anObject) {
           return true;
        }
        if (anObject instanceof Dog) {
           Dog anotherDog = (Dog) anObject;
           return (this.age == anotherDog.age && this.name.equals(anotherDog.name));
        }
        return false;
    }

}

To dynamically add a custom resource, the applicable classes must exist in the class path of the server class loader. If the class loader cannot load the classes, then the add command, which is normally executed dynamically, is processed as pending. In this case, add the custom resource classes to the 'SERVER_HOME/lib/application' or 'DOMAIN_HOME/lib/application' folder and restart the server.

Deleting a custom resource is not performed gracefully. In other words, even if there is a request in progress, the system does not wait until the request is complete which may cause errors to occur in the user applications.

Using the Console Tool

A custom resource can be looked up and dynamically added or deleted using the console tool.

[MASTER]domain1.adminServer>add-custom-resource custom/dog -resource dog.Dog -factory dog.DogFactory
Successfully performed the ADD operation for A custom resource.
Check the results using "list-custom-resources or add-custom-resource"

[MASTER]domain1.adminServer>list-custom-resources
List of Custom Resources
================================================================================
+-------------+--------------------+--------------------------+----------------+
| Export Name |   Resource Class   |       Factory Class      |   Properties   |
+-------------+--------------------+--------------------------+----------------+
| custom/dog  | dog.Dog            | dog.DogFactory           | [test=1,       |
|             |                    |                          |test1=2]        |
+-------------+--------------------+--------------------------+----------------+
================================================================================

[MASTER]domain1.adminServer>add-custom-resource-to-servers custom/dog -servers server1
Successfully performed the ADD operation for A custom resource.
Check the results using "list-custom-resources"

[MASTER]domain1.adminServer>remove-custom-resource custom/dog
Successfully performed the REMOVE operation for A custom resource.
Check the results using "list-custom-resources or remove-custom-resource"

[MASTER]domain1.adminServer>list-custom-resources
List of Custom Resources
================================================================================
+-------------+--------------------+--------------------------+----------------+
| Export Name |   Resource Class   |       Factory Class      |   Properties   |
+-------------+--------------------+--------------------------+----------------+
(No data available)
================================================================================

2.5. Configuring an External Resource

External sources are largely divided into JMS sources and Connectors.

JMS Source

To add a JMS source, you need to edit domain.xml as follows:

<resources>
    <external-source>
        <jms-source>
            <vendor>ibmmq</vendor>
            <factory-class-name>FirstClassName</factory-class-name>
            <resource-type>QCF</resource-type>
            <export-name>exportName</export-name>
            <queue>MQ</queue>
            <queueManager>MQManager</queueManager>
        </jms-source>
    </external-source>
</resources>

The following describes the JMS Source configuration items.

Item Description

Vendor

JMS vendor. Select one of:

  • ibmmq: IBM product.

  • sonicmq: Sonic MQ.

  • others: other product.

Factory Class Name

Factory class name of the JMS resource.

Resource Type

JMS type.

Select one of:

  • QCF

  • TCF

  • Q

  • T

  • XAQCF

  • XATCF

  • LOCALXAQCF

  • LOCALXATCF

Export Name

Name to bind to JNDI. Can be used to obtain JMS ConnectionFactory and Destination.

Queue

Use only when the resource type is Q.

QueueManager

Use only when the resource type is Q.

Topic

Use only when the resource type is T.

Property

Necessary attributes for JMS resources. It has a name, a type, and a value.

Refer to the IBM MQ or the Sonic MQ manual for more information about each item.

Adding a Connector

You can add a Connector by editing domain.xml as follows:

<resources>
    <external-source>
        <connector>
            <resource-adapter-module-id>connectorModuleId</resource-adapter-module-id>
            <worker-pool>
                <min>0</min>
                <max>5</max>
                <keep-alive-time>60000</keep-alive-time>
                <queue-size>4096</queue-size>
                <shutdown-timeout>-1</shutdown-timeout>
            </worker-pool>
        </connector>
    </external-source>
</resources>

For more information about the Connector, see JEUS Jakarta Connectors Guide.

2.6. Configuring an External Resource

External resources can be configured so that JEUS can integrate with Tmax or Infinite Cache. For integration with Tmax, JEUS connects to Tmax to configure WebT and JTmax. WebT is an outbound service that uses Tmax transaction services, and JTmax is an inbound service that receives requests from Tmax. Refer to the JTmax Server Guide of the Tmax manual for more information.

This section describes how to implement and register the external resources.

The following is the jeus.external.ResourceBootstrapper interface. The class that implements this interface must reside in the 'SERVER_HOME/lib/application' or 'DOMAIN_HOME/lib/application' directory.

jeus.external.ResourceBootstrapper
package jeus.external;

import javax.naming.Context;
import java.util.Map;

/**
 * A bootstrapper to use external resources in JEUS.
 */
public interface ResourceBootstrapper {
    /**
     *
     * @param propertyMap A Map with resource settings.
     */
    void setProperties(Map propertyMap) throws InvalidPropertyException;

    /**
     * Binds a resource.
     * @param context
     */
    void initResources(Context context);

    /**
     * Returns information about available properties.
     * @return
     */
    ResourcePropertyInfo[] getPropertyInfo();

    /**
     *
     * @param propertyMap A map with properties to be modified.
     */
    void modifyProperties(Map propertyMap) throws InvalidPropertyException;

    /**
     * To be called when re-binding the resource.
     * @param context
     */
    void reconfigResources(Context context);

    /**
     * Removes the resource.
     * @param context
     */
    void destroyResources(Context context);
}

To dynamically add an external resource, the applicable classes must exist in the class path of the server class loader. If the class loader cannot load the classes, then the add command, which is normally executed dynamically, is processed as pending. In this case, add the external resource classes to the 'SERVER_HOME/lib/application' or 'DOMAIN_HOME/lib/application' folder and restart the server.

Deleting an external resource is not performed gracefully. This means that an incomplete request may cause errors to occur in the user applications.

Using the Console Tool

An external resource can be looked up and dynamically added or deleted by using the console tool.

[MASTER]domain1.adminServer>add-external-resource test/ext -resource test.ext.TestResourceBootstrapper
Successfully performed the ADD operation for A external resource.
Check the results using "list-external-resources or add-external-resource"

[MASTER]domain1.adminServer>list-external-resources
List of External Resources
=============================================================================
+----------+---------------------------------------------------+------------+
| Name     |                   Resource Class                  | Properties |
+----------+---------------------------------------------------+------------+
| test/ext | test.ext.TestResourceBootstrapper                 | []         |
+----------+---------------------------------------------------+------------+
=============================================================================

[MASTER]domain1.adminServer>add-external-resource-to-servers test/ext -servers server1
Successfully performed the ADD operation for A external resource.
Check the results using "list-external-resources"

[MASTER]domain1.adminServer>remove-external-resource test/ext
Successfully performed the REMOVE operation for A external resource.
Check the results using "list-external-resources or remove-external-resource"

[MASTER]domain1.adminServer>list-external-resources
List of External Resources
=========================================================================
+------+---------------------------------------------------+------------+
| Name |                   Resource Class                  | Properties |
+------+---------------------------------------------------+------------+
(No data available)
=========================================================================