apache > ws.apache
WSRF
 

Creating a Singleton Service

Introduction

You can create a singleton service if only a single instance of a resource is required. If a service is a singleton, no resource ID parameter is expected in the header of requests sent to the service. To create a singleton service, you must create a single instance of the resource in the generated home class and modify the deployed jndi-config.xml file.

Create a Single Instance

Resource instances are created in the service's home class. For a singleton, specify an identifier of null when you call createInstance(). This ensures that only a single instance of the resource is created. For example:

public void init() throws Exception
    {
        super.init();
        
        HostResource host = (HostResource) createInstance( null );
        add( host );
    }			

Modify the JNDI Configuration File

To update the JNDII configuration file for a singleton service:

  1. Using a text editor, open jndi-config.xml in the WEB-INF/classes directory.
  2. From the <service name="your_service"> block, remove the resourceIdentifierReferenceParameterName parameter. This parameter is not required for a singleton. Removing this entry ensures that Apache WSRF does not look for a resource id in the WS Addressing header.
  3. Save and close jndi-config.xml.
  4. Restart Tomcat if it is already started.
    Note
    The service entry in jndi-config is only present if the service has been deployed.