Browse DevX
Sign up for e-mail newsletters from DevX


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

In Part 1, you built a fully-functional chat application using the Eclipse IDE and free Web services software from Systinet. In Part 2, use WASP Developer for Eclipse 4.6 to extend your original application with asynchronous messaging.




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

The Demo Application
The base line of this demo is the previous SimpleChatServer application. Please note that this demo isn't focused on versioning of Web services and their APIs. Although versioning is a pretty exciting topic, its scope goes beyond this tutorial. This demo simply breaks backward compatibility with the old clients, and implement the service in a new Java package, using a new target namespace for the WSDL file. To do this, you need to create new clients (or modify the existing ones), but it avoids clashes with the existing SimpleChatServer.

A new method has been added to the IChatService interface in order to model long latency business logic in the chat server:

ChatMessage[] getOrWaitforNewMessages(long afterId, long waitMillis) throws NoMessageArrivedException;

This method either returns messages whose id is larger than afterId (the newer ones) immediately, or waits until a new message is posted to the chat server. This is quite natural behavior for a chat server. The client doesn't have to periodically poll for new messages, as in every fraction of second. Instead, it places its request, and gets back the result when new messages arrive.

This model does have its weak spots. For instance, I've added a maximum wait time parameter to the call. When no message arrives at the server within the specified amount of time, the NoMessageArrivedException is thrown and returned to the client. Despite the imperfection, this design is sufficient for this tutorial's purposes. The source for the IChatService interface can be seen in Listing 1.

The new backend logic now contains the implementation of this new method. Hopefully, it's simplicity compensates for other aspects. The source for this can be found in Listing 2. Please note that the service code doesn't contain any code that would be specific to asynchronous invocation. The interesting stuff comes with the client.

Finding the Right Application Framework
You need a reliable, feature-rich platform for Web Services that lets you develop and deploy the asynchronous chat server and its client. In this demonstration, you'll be using Systinet's WASP (Web Applications and Services Platform) Server for Java.

The remaining part of the tutorial assumes that you have the WASP Developer for Eclipse 4.6 up and running. It internally contains a distribution of WASP Server for Java 4.6.1, which is a must for this tutorial. This tutorial will not work in WASP Developer 4.5.

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