Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementation of web service

I just want to implement a service in java that will:

  • take some arguments, then search the database

  • return the JSON object of the fetched data

I need help to identify the ways through which I can implement this thing.

e.g. Suppose I am getting the name of the book as argument I want to render.

On service part, I have to fetch book data and convert it to JSON and write/return to response.

I was looking at the Apache Axis2 but I am not sure that I am going in the right direction.

So, pls help.

Need guidelines not implementation.

Thanks

like image 991
mj.scintilla Avatar asked Jan 06 '11 08:01

mj.scintilla


2 Answers

I would suggest using JAX-RS based services which would be ideal for your scenario as you want json data. These are pretty easy to get started with. Jersey is a widely used frameworks. Also see RESTEasy.

like image 195
Vivek Avatar answered Oct 12 '22 02:10

Vivek


If you are returning the data in JSON then you probably don't need to implement a full web service, which uses XML for both the request and the response.

A normal dynamic web application (written as a Java Servlet) will be able to read request parameters in the HTTP payload and return a JSON-encoded HTTP response.

However you need to consider your clients; if they are only able to access web services then you need to forget about a JSON response and simply objectify the response. However if the clients can access web resources without issue then go with the servlet approach.

If you need to go with web services then look at the Metro 2 framework.

like image 45
trojanfoe Avatar answered Oct 12 '22 03:10

trojanfoe