WebReference.com - Part 2 of chapter 3 from Professional Java Web Services, Wrox Press Ltd. (1/5)
[next] |
Professional Java Web Services
Deploying and Running a "Hello World" Service
[The following is a continuation of our series of excerpts from chapter 3 of the Wrox Press title, Professional Java Web Services.]
Now that we have Apache SOAP installed and configured let's deploy and run a simple service called "Hello World". There are two ways a service can be deployed: via the Apache SOAP command line tool or via the web-based administration tool. We are going to discuss both methods within this section. We will also discuss how to use an Apache SOAP client to run the service. We will not dive into the details of implementing the service or the client, but will defer this discussion until the Developing SOAP Services and Developing SOAP Clients sections, respectively.
HelloWorld.java
The Java class that will implement the "Hello World" service is located in
HelloWorld.java
, which is listed below:
package com.wrox.helloworld.service;
public class HelloWorld {
String getMessage() {
return "Hello World!";
}
}
Notice that this class only has one method, getMessage()
. We will expose this method
through the "Hello World" service. This means that SOAP clients will be able to invoke this method.
In order to utilize the HelloWorld
class it must be accessible from the Apache SOAP
run-time environment, which is hosted within Tomcat. This means that the HelloWorld
class has to be accessible from Tomcat. This can be achieved by doing the following:
- Create a JAR file called
helloworld.jar
with the contents containing thecom.wrox.helloworld.service.HelloWorld
class. - Copy the
helloworld.jar
file to<TOMCAT_HOME>\lib\
Deploying Via the Command Line
In order for the getMessage()
method to be exposed a deployment descriptor for
the service has to be created and registered with the Apache SOAP run-time environment. In this
section we discuss the details of deployment descriptors and how to register the service using
the Apache SOAP command line tool.
Deployment Descriptors
A deployment descriptor is an XML document that provides the details of the service to the Apache SOAP run-time environment. The format of a deployment descriptor depends on the type of code artifact. The term code artifact is usually used to refer to a software component that contains logic that can be invoked via methods or functions. A code artifact can be written in any language. Apache SOAP ships with support for the following code artifacts:
- Standard Java classes
- Enterprise Java Beans (EJB)
- Bean Scripting Framework (BSF)-supported script
Support for standard Java classes includes support for JavaBeans. Support for EJBs includes stateless session beans, stateful session beans, and entity beans. The BSF framework can be used to allow SOAP services to be written in any BSF-supported scripting language such as Rhino. Rhino is an opensource implementation of JavaScript that supports the BSF framework. Rhino is written completely in Java and is maintained by mozilla.org. More information about BSF and Rhino can be located at https://oss.software.ibm.com/developerworks/projects/bsf/ and https://www.mozilla.org/rhino/.
Apache SOAP defines a different deployment descriptor for each one the aforementioned code artifacts.
We will discuss the deployment descriptor for a standard Java class. This is best done using an example,
so we will discuss the deployment descriptor for the "Hello World" service, which is implemented as a
standard Java class. The deployment descriptor for the "Hello World" service is located in a file
called HelloWorldDD.xml
. It's listed below:
<?xml version="1.0"?>
<isd:service xmlns:isd="https://xml.apache.org/xml-soap/deployment"
id="urn:HelloWorldService">
<isd:provider type="java"
scope="Application"
methods="getMessage">
<isd:java class="com.wrox.helloworld.service.HelloWorld" static="false"/>
</isd:provider>
<isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:faultListener>
</isd:service>
In order to understand this, we will go through each element to see how it is used.
[next] |
Created: May 23, 2002
Revised: May 23, 2002
URL: https://webreference.com/programming/java/webservices/chap3/2/