Once the starting point code is generated, you must provide the business logic for each of the operations defined in the service's interface.
You generate the implementation class for your service with wsdl2java's -impl
flag.
Tip | |
---|---|
If your service's contract includes any custom types defined in XML Schema, you will also need to ensure that the classes for the types are also generated and available. |
The service implementation code consists of two files:
is the service interface(SEI) for the service.portTypeName
.java
is the class you will use to implement the operations defined for the service.portTypeName
Impl.java
You provide the business logic for your service's operations by completing the stub methods in
. 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 Celtix Advanced Service Engine specific APIs that you can use to access some advanced features.portTypeName
Impl.java
For example, an implementation class for the service defined in Example 3.1, “HelloWorld WSDL Contract” may look like Example 4.1, “Implementation of the Greeter Service”. Only the code portions highlighted in bold must be inserted by the programmer.
Example 4.1. 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 void greetMeOneWay(String me) { System.out.println("Executing operation greetMeOneWay\n"); System.out.println("Hello there " + me); } public String 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); System.out.println("Executing operation pingMe, throwing PingMeFault exception\n"); throw new PingMeFault("PingMeFault raised by server", faultDetail); } }