Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Socket Server calling web service

 
John Dendrinos
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15437
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
John Dendrinos
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic