Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 5 of 7
From the command line
Instead of using the Web-based administration tool for deploying the server, you can use a command-line-based Java class,
org.apache.soap.server.ServiceManagerClient, that comes with Apache SOAP. This class takes two mandatory parameters: a URL to the Apache SOAP's router servlet (rpcrouter) and an action. The action can be one of the following: deploy, undeploy, list, or query. Based on the specified action,
an additional parameter may be required. For example, if the action is deploy, you must provide the name of an XML deployment descriptor file that contains all the information required by the Apache SOAP
server to successfully deploy the service at the command line, which an XML file specifies. For example, the deployment XML
for the HelloWorld service can be specified as follows:
<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment" id="urn:Hello">
<isd:provider type="java" scope="Application" methods="sayHelloTo">
<isd:java class="hello.HelloServer" static="false"/>
</isd:provider>
</isd:service>
The XML above embodies the same information that you entered in the Web-based administration tool. As an exercise, try mapping the information that you manually entered to the information contained in the XML. To deploy the HelloWorld service from the command line, you could do the following:
java org.apache.soap.server.ServiceManagerClient http://localhost:8080/apache-soap/servlet/rpcrouter deploy DeploymentDescriptor.xml
DeploymentDescriptor.xml is the name of the file that contains the deployment XML shown above. To verify that the server has been successfully deployed,
try the following:
java org.apache.soap.server.ServiceManagerClient http://localhost:8080/apache-soap/servlet/rpcrouter query urn:Hello
You should receive the same XML that is contained in DeploymentDescriptor.xml.
Coding the client program is much more involved than coding the HelloWorld service. That should not surprise you; you already
know that the client shoulders the responsibility for (at least) setting up the Call object, which requires a fair amount of work. As a reminder, in Part 4 of this series I will present you with a framework
based on the newly introduced dynamic proxy classes in Java 2, version 1.3, which will make creating clients easy and intuitive.
But you'll have to wait for that!
Listing 1 shows the client program in its entirety. Let's walk through this program step-by-step. The program expects one mandatory parameter: the name of the person to whom it says hello.
Listing 1: Client.java
package hello;
import java.net.URL;
import java.util.Vector;
import org.apache.soap.SOAPException;
import org.apache.soap.Constants;
import org.apache.soap.Fault;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Parameter;
import org.apache.soap.rpc.Response;
public class Client
{
public static void main(String[] args) throws Exception
{
if(args.length == 0)
{
System.err.println("Usage: java hello.Client [SOAP-router-URL] <name>");
System.exit (1);
}
try
{
URL url = null;
String name = null;
if(args.length == 2)
{
url = new URL(args[0]);
name = args[1];
}
else
{
url = new URL("http://localhost:8080/apache-soap/servlet/rpcrouter");
name = args[0];
}
// Build the call.
Call call = new Call();
call.setTargetObjectURI("urn:Hello");
call.setMethodName("sayHelloTo");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
Vector params = new Vector();
params.addElement(new Parameter("name", String.class, name, null));
call.setParams(params);
// Invoke the call.
Response resp = null;
try
{
resp = call.invoke(url, "");
}
catch( SOAPException e )
{
System.err.println("Caught SOAPException (" + e.getFaultCode() + "): " + e.getMessage());
System.exit(-1);
}
// Check the response.
if( !resp.generatedFault() )
{
Parameter ret = resp.getReturnValue();
Object value = ret.getValue();
System.out.println(value);
}
else
{
Fault fault = resp.getFault();
System.err.println("Generated fault: ");
System.out.println (" Fault Code = " + fault.getFaultCode());
System.out.println (" Fault String = " + fault.getFaultString());
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
The client begins by setting up the Call object, which requires the following information: