WebReference.com - Part 2 of chapter 3 from Professional Java Web Services, Wrox Press Ltd. (4/5) | WebReference

WebReference.com - Part 2 of chapter 3 from Professional Java Web Services, Wrox Press Ltd. (4/5)

To page 1To page 2To page 3current pageTo page 5
[previous] [next]

Professional Java Web Services

Deploying via the Web-Based Administration Tool

An alternative to deploying a service via the command line is to deploy using the web-based administration tool that is provided by the Apache SOAP toolkit. We installed the tool when we installed Apache SOAP in the Installing Apache SOAP section. The admin tool doesn't use the deployment descriptor directly to register the service, but it uses the same data specified in the deployment descriptor. So, the deployment descriptor should be created even if the service is not going to be registered via the command line. It will be helpful in registering the service via the web-based tool. To access the administration tool point a browser to https://localhost:8080/soap/admin/index.html. The following screen will be shown:

We can deploy the "Hello World" service by clicking the Deploy button. The following screen will be displayed:

Populate the form by entering values for fields (properties) that correspond with fields in the deployment descriptor. A list of the fields and their values are in the following table:

IDurn:HelloWorldService
ScopeApplication
MethodsgetMessage
Provider TypeJava
Provider Classcom.wrox.helloworld.service.HelloWorld
StaticNo
Default Mapping Registry Classorg.apache.soap.server.DOMFaultListener

Click Deploy at the bottom of the page to register the service. Once the service is registered it can be unregistered by clicking Un-deploy. A list of registered services will be displayed. To delete a service, click on its name.

Running the Service

Now that the "Hello World" service is deployed we will discuss a console-based Java application that uses the Apache SOAP client-side API for accessing the service. The name of the application is "HelloWorldClient". Running the application in a command prompt will give you:

> java –cp .;%CLASSPATH%; HelloWorldClient
Hello World!

Note that the service could also be accessed using other toolkits such as the Microsoft SOAP toolkit. This is not always a straightforward task because there are some interoperability issues that we may encounter when using a SOAP toolkit other than Apache SOAP to access an Apache SOAP service. As discussed in the Future of Apache SOAP section, these types of issues are being addressed by the next generation of Apache SOAP called Axis.

HelloWorldClient.java

In this section we will discuss the HelloWorldClient application. We aren't going to dive into the details at this moment--we will defer this discussion until the Developing SOAP Clients section. However, we touch on some key points within the application. The source-code for the entire application is listed below:

import org.apache.soap.Constants;
import java.net.URL;
import org.apache.soap.Fault;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Response;
import org.apache.soap.rpc.Parameter;
public class HelloWorldClient {
  static String DEFAULT_ENDPOINT = "https://localhost:8080/soap/servlet/rpcrouter";
  public static void main (String args[]) throws Exception {
    String endPoint = DEFAULT_ENDPOINT;
    //Process Arguments
    if (args.length == 1) {
      endPoint = args[0];
    } else if (args.length > 1) {
      System.out.println("java HelloWorldClient [endpoint]");
    }
    // Build the SOAP RPC request message using the Call object
    Call call = new Call ();
    call.setTargetObjectURI ("urn:HelloWorldService");
    call.setMethodName ("getMessage");
    call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
    // Create a URL object, which represents the endpoint
    URL url = new URL(endPoint);
    // Send the SOAP RPC request message using invoke() method
    Response resp = call.invoke (url, "");
    // Check the response.
    if (resp.generatedFault ()) {                     // Error Occured
      Fault fault = resp.getFault ();
      System.out.println ("The Following Error Occured: ");
      System.out.println ("  Fault Code   = " + fault.getFaultCode ());
      System.out.println ("  Fault String = " + fault.getFaultString ());
    } else {                                          // Completed Successfully
      Parameter result = resp.getReturnValue ();
      System.out.println (result.getValue ());
    }
  }
}

To page 1To page 2To page 3current pageTo page 5
[previous] [next]

Created: May 23, 2002
Revised: May 23, 2002

URL: https://webreference.com/programming/java/webservices/chap3/2/4.html