apache > ws.apache
WSRF
 

Creating a Singleton Resource

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 wsrf-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 WSRF Configuration File

To update the WSRF configuration file for a singleton service:

  1. Using a text editor, open wsrf-config.xml in the WEB-INF/classes directory.
  2. From the <bean name="YourSingletonHome" class="org.example.YourSingletonHome" init-method="init"> block, remove the resourceIdentifierReferenceParameterName property element. This parameter is not required for a singleton. Removing this entry ensures that Apache WSRF does not look for a resource id WS-Addressing reference parameter in the SOAP header.
  3. Save and close wsrf-config.xml.
  4. Restart Tomcat if it is already started.
    Note
    A resource home entry in wsrf-config.xml will only be present if your service has been deployed.