Browse DevX
Sign up for e-mail newsletters from DevX


Build a SOAP-based Chat Application with Java Web Services : Page 2

This introduction to Web services eschews the canonical "stockQuote" service in favor of a more complex and more informative SOAP-based chat application. Learn how to develop a fully-functional application using the Eclipse IDE and free Web services software from Systinet.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Design of the Chat Server
The complete implementation of the chat server is decoupled into several classes. The interface is defined in the package com.systinet.simplechat.server.iface. It consists of three classes; IChatService.java, the interface class of the chat server, and two structures that are used for the representation of chat messages and participants—ChatMessage.java and ChatPerson.java.

The implementation of the chat server is in the package com.systinet.simplechat.server.impl. It decouples the simple implementation of the interface from the backend business logic. I've used the Adaptor design pattern, i.e., the calls to ChatService.java are delegated to a backend processor. The business logic is pretty simple. It's a singleton instance of the class SimpleBackendImpl.java that stores the messages in a collection.

At first glance, the adaptor/backend implementation might seem too complicated for a simple tutorial. However, even complex existing business logic can be reused to become a Web service without any need to change its code. This is a frequent real-life use case. Even if the application wasn't designed using the Adaptor pattern originally, writing a wrapper class like ChatService can be accomplished in a matter of seconds, without the need to rewrite the original backend logic. However, the backend could have been implemented using JDBC and a relational database, or as an EJB, or even make calls to native methods of external non-Java applications. The possibilities are endless. The Adaptor pattern simply allows you to switch to new backend logic quickly.

Turning the Chat Server into a Web Service
Right now, the chat server is just a Java implementation. It is not yet SOAP aware. It's just a working chat server for clients running in the same JVM. The next step is to make the chat server speak SOAP and create a WSDL document that describes it.

This example uses Systinet's Web Applications and Services Platform (WASP) software to create the Web services application. WASP software is platform independent and works in almost any Java environment. This platform presents two distinct deployment scenarios: programmatic deployment and declarative deployment. In both cases what gets deployed is a plain old Java object. Programmatic deployment (also called runtime publishing) happens in an application's runtime and enables dynamic deployment of application classes as web services. Literally, you start WASP inside your application, and register its objects with calls to the WASP API. In other words, you actually embed WASP into your application. Declarative deployment means packaging your application into a deployment package (kind of a JAR file with an included deployment descriptor) and publishing that to a running instance of WASP. For its simplicity and straightforward access, we're using the runtime publishing method.

Figure 1: Import existing code.

Installing the Chat Server into Eclipse
Assuming that you have Eclipse with WASP Developer up and running, install the sample code.

  1. In Eclipse create a new project (File -> New -> Project...). Choose the Systinet Web Services/Web Service Project.
  2. In the following dialog enter the project name, ChatServiceProject and location. Finish the wizard.
  3. From the File menu, choose the Import... command, and choose the Zip file method.
  4. In the following dialog choose the zip file downloaded earlier as the source, and click on the Finish button.
Your project should now contain the two packages with the source for the Chat Service. You can verify this by examining the Package Explore view.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date