aspose file tools*
The moose likes Java in General and the fly likes Socket Server calling web service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Socket Server calling web service" Watch "Socket Server calling web service" New topic
Author

Socket Server calling web service

John Dendrinos
Greenhorn

Joined: Jan 25, 2011
Posts: 7
I have the following requirement:

Create a socket server that accept request from clients (clients are implemented in C).

The request data form clients is in JSON format.

The data is deserialized (probably with Jackson).

The data is going to be used initially to call a web service. Later there might be a need to redirect the data to a Servlet, or to a different application so it can process it.

My question is, what is the best way to implement such a system? How should I implement the notification mechanism to notify the web service, Servlet etc?

Note: The socket server is a multi-thread application.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14150
    
  18

I would use Jersey, the reference implementation for the JAX-RS API (for working with RESTful web services in Java). When you use it together with JAXB, it's quite easy to expose methods as web services, which can accept data in XML or JSON format. You don't have to do any low-level parsing and formatting of JSON data; Jersey and JAXB can do that almost automatically for you.

The Jersey user guide gives a good overview of how to use it.

In the project I'm currently working on, we're using Jersey and JAXB together with the Grizzly web server as described in section 11.3.1 of the user guide. Grizzly is the multi-threaded socket server.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
John Dendrinos
Greenhorn

Joined: Jan 25, 2011
Posts: 7
Hi, maybe I was not clear enough, or maybe I did not understand your answer.

I have the socket server ready. It's a multi-threaded standalone java application that opens a java socket and listens for client requests.

My issue is about the mechanism to use when forwarding the client data to the web service, or to a Servlet, etc.

I need something flexible and generic.

I have been advised to use the Observable/Observer pattern but then I read that this might not be a very good idea (not very flexible?).

Also I don't know if this mechanism should be a different application, or part of the socket server application.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Socket Server calling web service