Documentos de Académico
Documentos de Profesional
Documentos de Cultura
6 Tutorial
Implementing Java Web
Services Using Eclipse
Cape Clear 6.6 Tutorial | Implementing Java Web Services Using Eclipse
Copyright © 2006 Cape Clear Software, including this documentation, all demonstrations,
and all software. All rights reserved. The document is not intended for production and is
furnished “as is” without warranty of any kind. All warranties on this document are hereby
disclaimed including the warranties of merchantability and fitness for a particular purpose.
Trademarks
Cape Clear is a registered trademark of Cape Clear Software. Cape Clear Software, Cape
Clear Studio, Cape Clear Server, Cape Clear Data Transformer, Cape Clear Orchestrator,
and Cape Clear Manager are trademarks of Cape Clear Software in the United States and
other countries.
All other company, product, and service names mentioned in this product may be
trademarks or service marks of others.
Contents
1. Introduction................................................................. 4
2. Getting Started with the Chat Application .................... 4
2.1. Downloading the Source Files .....................................................5
2.2. Setting Up the Source Files in Eclipse .........................................5
2.3. Running the Application............................................................ 30
1. Introduction
This tutorial demonstrates how to implement Java Web services. This is
achieved using the example of a simple instant-messaging (chat)
application. The following sections describe the various aspects of this
tutorial:
Section 2 describes how to set up and run the simple chat
application using the supplied defaults.
Section 3 provides details on the design of this application,
including the client and server interfaces and how they are
exposed.
Section 4 describes how to expose the chat server as a Web
service.
Section 5 discusses creating a Web service client that will
communicate with the chat server.
Section 6 explains how to implement a call-back mechanism to
expose a service on the clients to which the server can make calls.
14. Click OK. Select the check box next to java, as shown below.
Figure 16: The resulting IChatUtility project in the Cape Clear Studio
perspective
16. Next, create another Java Web Service Utility project that will
contain the Java source code of the chat client, called
ChatClientUtility.
19. Click Finish. In Cape Navigator, note that the red markers
indicate that interfaces are missing in the client code.
Figure 22: Specifying the Java build path for the project
22. Select the IChatUtility project, then click OK.
31. For the project name, specify ChatServer, which is the name of
the Web service that will be passed to the chat client in a later
step.
33. Click Next. To add in the required modules (that is, the chat server
utility project that contains the source code of the Web service, and
the interface utility project), click Add next to the Required
Modules list box.
select and right-click the ChatServer folder, then select Run As,
then Run on Server, as shown below.
Figure 51 shows the sequence of events between a chat client and the
chat server. The operations in this sequence represent the public
operations of both the client and server.
Figure 51: Interaction between a chat client and the chat server
Figure 51 also shows that the server must be able to call each client to
inform it of any new messages. To enable this to happen, the client must
expose an interface as a Web service for the server to use. This interface
is defined as follows:
register(“Thomas”, “http://localhost:9085/clientCallBack”);
the unregister method is invoked by the client, which removes that client
from the list of registered clients in the server and sends out a notice to all
clients by calling their displayMessage method.
The chat client GUI is implemented using the Java Swing framework. A
detailed discussion of the GUI class is beyond the scope of this tutorial.
proxy = (IChatServer)ConcreteProxyFactory.createProxy(
IChatServer.class,
"ChatServer",
wsdlURL,
null,
serverURL);
Once the proxy is created, when we invoke its methods, the invocations
are forwarded to the running chat server. This kind of proxy is called a
dynamic proxy, because no stub code has been generated. The Java
interface is bound to the proxy object dynamically at runtime (for more
information on dynamic proxy classes, see
http://java.sun.com/j2se/1.3/docs/guide/reflection/proxy.html). Example
6 shows the code for invoking the sendMessage business method on the
server:
proxy.sendMessage(msg);
7. Summary
This tutorial demonstrated the use of Cape Clear APIs to expose business
methods of Java classes as a Web service. We created an instance of a
Cape Clear Embedded Server and deployed a Java class programmatically
using only two lines of code.
A client invoking on a Web service required a dynamic proxy together with
the interface of the Java class exposed as a Web service. Invoking a
business method was then as simple as proxy.method_name(parameters);.
We also saw that communication in a chat system is bi-directional,
involving a Web service on the server and a call-back Web service on the
client.