Creating a Service Implementation Bean

The Java class that implements the Service Endpoint Interface is called the Service Implementation Bean. Learning odd new bits of jargon is an unavoidable part of JAX-WS.

The SquareRootServerImpl class implements the SquareRootServer interface, as stated in the class declaration:

public class SquareRootServerImpl implements SquareRootServer {

This means the class you’re creating must contain all the methods in the interface, each with the proper parameters.

The getSquareRoot(double) and getTime() methods are implemented using techniques you’ve learned previously.

The only new aspect of the class is the following annotation, which appears before the class statement:

@WebService(endpointInterface = "com.java24hours.ws.SquareRootServer")

This annotation indicates the class is a service implementation bean for a service endpoint interface named com.java24hours.ws.SquareRootServer. You must use the full class name, including the name of its package.

Take note of the fact that annotations are not followed by semicolons, unlike statements.

Start coding this class: Create a new empty Java file named SquareRootServerImpl in the package com.java24hours.ws, and then fill it with the contents of Listing 22.2.

Listing 22.2. The Full Text of SquareRootServerImpl.java


 1: package com.java24hours.ws;
 2:
 3: import java.util.*;
 4: import javax.jws.*;
 5:
 6: @WebService(endpointInterface = "com.java24hours.ws.SquareRootServer")
 7:
 8: public class SquareRootServerImpl implements SquareRootServer {
 9:  
10:     public double getSquareRoot(double input) {
11:         return Math.sqrt(input);
12:     }
13:
14:     public String getTime() {
15:         Date now = new Date();
16:         return now.toString();
17:     }
18: }



Caution

The name of Service Implementation Beans refers to JavaBeans, special Java classes designed to function as reusable software components in the Java Enterprise Edition. However, the reference to beans is a bit of a misnomer when it comes to JAX-WS. Any Java object can be a Service Implementation Bean as long as it follows the rules for web service methods and has been created with the proper annotations.


With the two classes you’ve created, you’re ready to launch the web service so it can be called by other software.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.72.74