Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java- Jersey, JAX RS

I've some experience developing Java programs. However I have always struggled to understand some basics, such as all the different components that make up a Java Enterprise Application.

For example I have implemented RESTful and SOAP based Web services that are consumed from a J2ME application and performed performance and costing tests for my MSC.

To develop the RESTful/SOAP based Web services, I used the wizard functionality in Netbeans. It uses JAX-RS to implement the REST web services. Then I see other tutorials that use JAX-RS with Jersey etc. I often get lost in the jargon such as API's, application frameworks, configuration files, Java edition and so on etc. Here are a few questions

  1. JAX-RS is an API. Is an API basically a collection of libraries used to implement some form of functionality in Java?

  2. According to their site "Jersey is the open source, production quality, JAX-RS (JSR 311) Reference Implementation for building RESTful Web services." Is Jersey another API or is it used in conjunction with JAX-RS, and whats the difference between the two?

  3. How do I recognise if in fact I have implemented such API's and know if I need them?

When I decided to implement RESTful web services, I just followed a Netbeans tutorial and the wizards provided easy and quick development time. I understand that wizards are used because they are quick and do the job. However I wonder, when you are given a task to code. How do you know what API's, frameworks, add-ons etc to use. What edition of Java is compliant with the libraries etc. Is it just me or do you get lost at times? Or will this come from experience.

Thanks for taking the time to read :)

like image 807
Paddy Avatar asked May 16 '11 15:05

Paddy


People also ask

What is Jersey and JAX-RS?

JAX-RS is an specification (just a definition) and Jersey is a JAX-RS implementation. Jersey framework is more than the JAX-RS Reference Implementation. Jersey provides its own API that extend the JAX-RS toolkit with additional features and utilities to further simplify RESTful service and client development.

What is Java Jersey used for?

What is Java Jersey Framework? Java Jersey project tracks the JAX-RS API, which is used to create Restful web services in Java.

What is the difference between JAX-RS and JAX WS?

Actually,JAX-WS represents both RESTful and SOAP based web services. One way to think about it is that JAX-RS specializes in RESTful, while JAX-WS allows you more flexibility to choose between either, while at the same time being (in some cases) more complicated to configure.


2 Answers

  1. JAX-RS is more than just an API. It is a Java Specification Request (JSR). Those define the API and behaviors that must be supported by an implementor. If you write your code to use the API defined by the JSR then you can choose which implementation to use at runtime.

  2. Jersey is code that provides the behavior dictated by JAX-RS defined by JSR 311. Calling it the reference implementation indicates that it is supported by the creators of the JSR and is probably bundled with Oracle's software. Other implementations of JSR 311 also include Restlet, CXF, and RESTEasy.

  3. Typically you would use a 3rd party library that implements the specification as I mentioned in number 2 above. The only reason you might consider implementing it yourself is if a suitable implementation did not exist.

The only way to find out what APIs and specifications can help you is through a discovery process really. JSRs are meant to be a common approach to defining a solution for a generic problem where you can choose the implementation that works best for you.

like image 92
laz Avatar answered Sep 27 '22 20:09

laz


  1. The API does not provide any implementation code (that is, concrete classes that do the actual processing). The API only specifies interfaces, annotations, exceptions. There can be concrete classes with some very basic, core behaviour, but that's all. The idea of standard APIs, like JAX-RS, is to give developers something to code against regardless of the underlying platform and implementation

  2. Jersey is the implementation - it includes many concrete classes that actually handle the business promised by the API. In JAX-RS case - it handles requests and responses.

  3. You don't usually implement an API. You use one. Normally JavaEE standard APIs use the javax. package, while implementations use a different package - com.sun, org.apache, etc. It is a good sign if you only use the javax. interfaces and not the concrete classes.

like image 29
Bozho Avatar answered Sep 27 '22 20:09

Bozho