Axis2

Axis2, which implements but also extends JAX-WS, is an alternative to the Metro implementation. The current version is 1.6.x. Axis2 can be downloaded in various formats, including as a self-contained WAR file, axis2.war, which can be copied to TOMCAT_HOME/webapps. An Axis2 service does not require annotations if the proper configuration file is used. This section introduces Axis2 using a deliberately simple service so that the focus is on the deployment steps.

The HiService class (see Example 5-15) is a POJO class, free of annotations, that implements the SOAP-based HiService in Axis2. Any public instance method in the class is thereby a service operation; in this case, there is a single operation: echo.

Example 5-15. The HiService in Axis2

package hello;

public class HiService {            // service
  public String echo(String name) { // service operation
    String msg =
      (name == null || name.length() < 1) ? "Hello, world!" : "Hello, " + name + "!";
    return msg;
  }
}

The configuration file services.xml (see Example 5-16) specifies that an instance of the Axis2 class RPCMessageReceiver will act as the interceptor for requests against the operation named echo. The configuration document services.xml must be deployed in the JAR file’s META-INF directory.

Example 5-16. The services.xml configuration file for the Axis2 HiService

<service>
  <parameter name = "ServiceClass" locked = "false">hello.HiService</parameter>
  <operation name = "echo">
    <messageReceiver class = "org.apache.axis2.rpc.receivers.

Get Java Web Services: Up and Running, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.