|
Page Edited :
CXF20DOC :
Developing a Service
Developing a Service has been edited by Eric Johnson (Nov 30, 2006). Content:Developing a Service using JAX-WSYou can develop a service using one of two approaches:
However, there are many cases where you may need to service enable an existing application. While JAX-WS eases the process, it does require that you make some changes to source code of your application. You will need to add annotations to the source. It also requires that you migrate your code to Java 5.0. WSDL First DevelopmentUsing the WSDL first model of service development, you start with a WSDL document that defines the service you wish to implement. This WSDL document could be obtained from another developer, a system architect, a UDDI registry, or you could write it yourself. The document must contain at least a fully specified logical interface before you can begin generating code from it. Once you have a WSDL document, the process for developing a JAX-WS service is three steps:
Generating the Starting Point CodeJAX-WS specifies a detailed mapping from a service defined in WSDL to the Java classes that will implement that service. The logical interface, defined by the wsdl:portType element, is mapped to a service endpoint interface (SEI). Any complex types defined in the WSDL are mapped into Java classes following the mapping defined by the Java Architecture for XML Binding (JAXB) specification. The endpoint defined by the wsdl:service element is also generated into a Java class that is used by consumers to access endpoints implementing the service. The wsdl2java command automates the generation of this code. It also provides options for generating starting point code for your implementation and an ant based makefile to build the application. wsdl2java provides a number of arguments for controlling the generated code. Running wsdl2javaYou can generate the code needed to develop your service using the following command: The command does the following:
Generated codeTable1 describes the files generated for creating a service. Table 1: Generated Classes for a Service
Implementing the ServiceOnce the starting point code is generated, you must provide the business logic for each of the operations defined in the service's interface. Generating the implementation codeYou generate the implementation class for your service with wsdl2java's -impl flag.
Generated codeThe service implementation code consists of two files:
Implement the operation's logicYou provide the business logic for your service's operations by completing the stub methods in _portTypeName_Impl.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. ExampleFor example, an implementation class for a service that defined the operations sayHi and greetMe may look like Example1 Example 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 String sayHi() { System.out.println("Executing operation sayHi\n"); return "Bonjour"; } } |
Unsubscribe or edit your notifications preferences
