Implementing the Service
Generating the implementation code
You generate the implementation class for your service with wsdl2java 's -impl flag.
The service implementation code consists of two files:
-
portTypeName.java is the service interface(SEI) for the service.
-
portTypeNameImpl.java is the class you will use to implement the operations defined for the service.
Implement the operation's logic
You provide the business logic for your service's operations by completing the stub methods in portTypeNameImpl.java . For the most part, you use standard Java to implement the business logic. If your service uses custom XML Schema types, you will need to use the generated classes for each type to manipulate them. There are also some CXF specific APIs that you can use to access some advanced features.
Example
For example, an implementation class for a service that defined the operations sayHi and greetMe may look like the below example.
Implementation of the Greeter Service
package demo.hw.server;
import org.apache.hello_world_soap_http.Greeter;
@javax.jws.WebService(portName = "SoapPort", serviceName = "SOAPService",
targetNamespace = "http://apache.org/hello_world_soap_http",
endpointInterface = "org.apache.hello_world_soap_http.Greeter")
public class GreeterImpl implements Greeter {
public String greetMe(String me) {
System.out.println("Executing operation greetMe");
System.out.println("Message received: " + me + "\n");
return "Hello " + me;
}
public String sayHi() {
System.out.println("Executing operation sayHi\n");
return "Bonjour";
}
}