Sams Teach Yourself Java™ in 24 Hours (Covering Java 7 and Android)

(singke) #1
ptg7068951

Publishing the Web Service 317

13:
14: publicString getTime() {
15: Date now = new Date();
16: returnnow.toString();
17: }
18: }


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


Publishing the Web Service


JAX-WS web services can bedeployed by Java application servers such as
BEAWebLogic, GlassFish, JBoss, and Jetty. If you had created the
SquareRootServerweb service in a development environment that sup-
ported 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 SquareRootServerPublisherapplication 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 EndPointclass in the javax.xml.wspackage 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 local-
host 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 arbi-
trarily because it’s not likely to be in use by other Internet-aware programs
on your computer.


LISTING 22.2 Continued CAUTION
The name of Service
Implementation Beans refers to
JavaBeans,special Java class-
es 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 properannota-
tions.

Free download pdf