4.2. Build, deploy, and try it out... with the same client

After splitting up the implementation, we are now ready to build and deploy our new service. First off, the WSDD file has only two small changes: a new service name, and a new service class name. Since we are reusing the WSDL file from the previous chapter, we don't have to change anything else in the WSDD file.

<?xml version="1.0" encoding="UTF-8"?>
<deployment name="defaultServerConfig" 
    xmlns="http://xml.apache.org/axis/wsdd/" 
    xmlns:java="http://xml.apache.org/axis/wsdd/providers/java" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <service name="examples/core/singleton/MathService" provider="Handler" use="literal" style="document">
        <parameter name="className" value="org.globus.examples.services.core.singleton.impl.MathService"/>
        <wsdlFile>share/schema/examples/MathService_instance/Math_service.wsdl</wsdlFile>
        <parameter name="allowedMethods" value="*"/>
        <parameter name="handlerClass" value="org.globus.axis.providers.RPCProvider"/>
        <parameter name="scope" value="Application"/>
        <parameter name="providers" value="GetRPProvider"/>
        <parameter name="loadOnStartup" value="true"/>
    </service>

</deployment>
[Note]

This file is $EXAMPLES_DIR/org/globus/examples/services/core/singleton/deploy-server.wsdd.

Now, let's take a closer look at the JNDI deployment file. In the previous chapter we asked you to please take a leap of faith and accept that we needed this file "because we need it". Now, we can explain what this file does. It is responsible for specifying what resource home our service has to use to get a hold of resources. In this file we will also specify parameters related to how the resource home manages those resources. However, since at this point we are only managing a single resource, our JNDI deployment file will be pretty simple.

<?xml version="1.0" encoding="UTF-8"?>
<jndiConfig xmlns="http://wsrf.globus.org/jndi/config">

<service name="examples/core/singleton/MathService">
	<resource name="home" type="org.globus.examples.services.core.singleton.impl.MathResourceHome">
	<resourceParams>

		<parameter>
			<name>factory</name>
			<value>org.globus.wsrf.jndi.BeanFactory</value>
		</parameter>

	</resourceParams>
		
	</resource>
</service>

</jndiConfig>
[Note]

This file is $EXAMPLES_DIR/org/globus/examples/services/core/singleton/deploy-jndi-config.xml.

In a nutshell, the root element jndiConfig of the file can contain several service elements (one for each service we're configuring... since we're only configuring one service, we'll have a single service element). This element has a name attribute whose value must match the service name specified in the WSDD file (this is basically the 'glue' between the WSDD file and the JNDI file).

The service element contains a resource element which we'll use to specify the resource home for our service. Notice that we do so using the type attribute. The resource element can contain several resource parameters. In this example we have a single parameter, which will be common to all the services we deploy.

[Note]

If you look back on the JNDI deployment file from the previous chapter, you'll see that it is the same as the one shown above, except that the resource home we specify is ServiceResourceHome.

Now, we can build the service:

./globus-build-service.sh singleton

And deploy it:

globus-deploy-gar $EXAMPLES_DIR/org_globus_examples_services_core_singleton.gar
[Note]

You will need to restart the Globus standalone container for the deployment to take effect.

Finally, we're going to make sure the service works. Another nice perk of reusing the WSDL file is that we can also reuse the client described in the previous chapter. Remember that we've only changed the implementation of the service; as long as we don't change the WSDL interface, there's no need to write a new client.

So, remember you have to run the client like so:

java \
-classpath ./build/stubs/classes/:$CLASSPATH \
org.globus.examples.clients.MathService_instance.Client \
http://127.0.0.1:8080/wsrf/services/examples/core/singleton/MathService

If all goes well, you should see the following:

Current value: 15
Current value: 10

If you run the client another time, since our service is tied to a singleton resource, you should see the value of increase with each run of the client.

Current value: 25
Current value: 20
Current value: 35
Current value: 30