Library Link To Toggle Frames Print Feedback

Greeter Service Implementation

This section shows a sample implementation of the Greeter interface. Due to the portability of the Celtix ASE programming API, this same code can be deployed into a wide variety of containers, including a servlet container, a JBI container, and a Spring container.

GreeterImpl class

The GreeterImpl class shown in Example 1.6, “The GreeterImpl Class” provides the implementation of the Greeter interface.

Example 1.6. The GreeterImpl Class

package demo.hw.server;

import java.util.logging.Logger;
import org.apache.hello_world_soap_http.Greeter;
import org.apache.hello_world_soap_http.PingMeFault;
import org.apache.hello_world_soap_http.types.FaultDetail;

1@javax.jws.WebService(portName = "SoapPort", serviceName = "SOAPService", 
  targetNamespace = "http://apache.org/hello_world_soap_http",
  endpointInterface = "org.apache.hello_world_soap_http.Greeter")
                  
2public class GreeterImpl implements Greeter {

    private static final Logger LOG = 
        Logger.getLogger(GreeterImpl.class.getPackage().getName());
    
3    public String greetMe(String me) {
        LOG.info("Executing operation greetMe");
        System.out.println("Executing operation greetMe");
        System.out.println("Message received: " + me + "\n");
        return "Hello " + me;
    }
    
    public void greetMeOneWay(String me) {
        LOG.info("Executing operation greetMeOneWay");
        System.out.println("Executing operation greetMeOneWay\n");
        System.out.println("Hello there " + me);
    }

    public String sayHi() {
        LOG.info("Executing operation sayHi");
        System.out.println("Executing operation sayHi\n");
        return "Bonjour";
    }
    
    public void pingMe() throws PingMeFault {
        FaultDetail faultDetail = new FaultDetail();
        faultDetail.setMajor((short)2);
        faultDetail.setMinor((short)1);
        LOG.info("Executing operation pingMe, throwing PingMeFault
exception");
        System.out.println("Executing operation pingMe, throwing PingMeFault
exception\n");
        throw new PingMeFault("PingMeFault raised by server", faultDetail);
    }
}

The GreeterImpl class follows the JAX-WS standard to implement the Greeter port type. In outline, the preceding code example can be explained as follows:

  1. The @jaxws annotation preserves information from the original WSDL contract; specifically recording the WSDL port type, service name, and port name associated with The GreeterImpl class.

  2. The GreeterImpl class provides an implementation of the org.apache.hello_world_soap_http.Greeter base class, which is generated automatically by the wsdl2java tool.

  3. Each of the operations from the Greeter interface—greetMe, greetMeOneWay, sayHi, and pingMe—are implemented by the GreeterImpl class. These operation impementations can be called by Web service clients once the GreeterImpl class has been deployed into a suitable container.