Publishing the Web Service

JAX-WS web services can be deployed by Java application servers such as BEA WebLogic, GlassFish, JBoss, and Jetty. If you had created the SquareRootServer web service in a development environment that supported those servers, you’d be ready at this point to launch it.

You also can write your own Java application that loads a web service and makes it available over the Internet.

The SquareRootServerPublisher application handles this task, which requires only two steps:

• Load the class that implements the web service

• Publish that object at an address accessible to the Internet

The EndPoint class in the javax.xml.ws package has a class method, publish(String, Object), that deploys a web service.

This method’s first argument is the web address where the service can be accessed, which for this project is http://127.0.0.1:5335/service. This web address begins with a host name, 127.0.0.1, that’s called the localhost because it’s the local computer you’re using to create and run your Java programs.

The second part of the address is the port number on the localhost where the web service waits for connections. The port 5335 has been chosen arbitrarily because it’s not likely to be in use by other Internet-aware programs on your computer.

The final part of the address, /service, is the path. Every web service must have a unique path. If you run any other web services on your computer, they can’t have the same path as SquareRootServer.

To deploy the web service, create an empty Java file called SquareRootServerPublisher in the com.java24hours.ws package. Enter the text of Listing 22.3 in this file.

Listing 22.3. The Full Text of SquareRootServerPublisher.java


 1: package com.java24hours.ws;
 2:
 3: import javax.xml.ws.*;
 4:
 5: public class SquareRootServerPublisher {
 6:     public static void main(String[] arguments) {
 7:         SquareRootServerImpl srsi = new SquareRootServerImpl();
 8:         Endpoint.publish(
 9:             "http://127.0.0.1:5335/service",
10:             srsi
11:         );
12:     }
13: }


When you run the application, it waits for connections on port 5335 of your computer. You can call the methods of the web service from any program that supports SOAP- or REST-based web services, whether the program is written in Java or another language. As long as your web service is on the Internet, any other Internet-connected software can call the methods.

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

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