This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 13868
    
  10

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.
 
Consider Paul's rocket mass heater.
 
subject: Socket Server calling web service
 
Similar Threads
Between java.net package or servlet class, which is better
Should I use EJB?
How send file data to JSP/Servlet page and save to disk?
Part 2 design question
Chapter 2 (HFSJ) notes , may be useful for anyone