Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAX-WS vs JAX-RS For RESTful Web Service

Tags:

Hi I have worked with JAX-WS for SOAP based webservices. Now I want to use REST because REST have advantages over SOAP as i studied about from here.

But from different articles I knew that we can create RESTful webservices from JAX-WS also. But most of people says that we should use JAX-RS instead of JAX-WS.

My question is what is difference in between JAX-WS RESTful webservice and JAX-RS(jersey). What are advantages of JAX-RS over JAX-WS? And why we should use JAX-RS for RESTful webservices?

Thanks in Advance.

like image 753
Abhendra Singh Avatar asked Sep 26 '12 10:09

Abhendra Singh


People also ask

Is JAX-WS is the API for REST?

JAX-WS is a fundamental technology for developing SOAP (Simple Object Access Protocol) and RESTful (Web services that use representational state transfer, or REST, tools) Java Web services, where JAX-WS is designed to take the place of the JAVA-RPC (Remote Procedure Call) interface in Web services and Web-based ...

What is the difference between JAX-RS and spring REST?

JAX-RS is only a specification and it needs a compatible implementation to be used. On the other hand, Spring MVC is a complete framework with REST capabilities. Like JAX-RS, it also provides us with useful annotations to abstract from low-level details.

Is JAX-RS a web services technology?

JAX-RS stands for JAVA API for RESTful Web Services. JAX-RS is a JAVA based programming language API and specification to provide support for created RESTful Web Services. Its 2.0 version was released on the 24th May 2013.

Can we use JAX-RS in spring boot?

Spring Boot has excellent support for JAX-RS web services. You generally have two JAX-RS implementations to choose from: Jersey. Apache CXF.


1 Answers

TL;DR

JAX-WS is meant for XML based web services such as SOAP. JAX-RS does not have the same restriction.

JAX-WS is generally geared towards server to server interactions with well defined contracts (WSDLs) and usually when the service and client side are from separate groups. It is very resource intensive so it isn't feasible for client-to-server interactions where the network or client device capability is less than optimal.

JAX-RS is geared towards client to server interactions, although server-to-server is okay. As it has little service obligations, it can be tuned to whatever the client needs are.

More info

The JAX-RS API only provides code-first approaches, whereas JAX-WS allows for both code-first (generally not recommended) and contract-first using WSDL files (more commonly recommended).

JAX-RS 2.0 introduces the client API which is a smart wrapper for HttpUrlConnection that has a lot more mapping capability, JAX-WS is also a wrapper, but the data it deals with in the reference implementations is just XML.

JAX-RS has the advantage of creating APIs that are simpler to create and digest messages for in different browsers and mobile devices, namely JSON structure. It does not introduce the notion of an envelope and uses HTTP for it. It does not introduce cryptography or security, it uses HTTPS for it.

JAX-WS though it runs on HTTPS for cryptography provides additions for security using WS-SecurityPolicy etc. In addition, contracts are firmly established using WSDL and can be verified outside the application using ESBs such as DataPower.

So what to choose

JAX-WS is generally geared towards server to server interactions with well defined contracts (WSDLs) and usually when the service and client side are from separate groups. It is very resource intensive so it isn't feasible for client-to-server interactions where the network or client device capability is less than optimal.

JAX-RS is geared towards client to server interactions, although server-to-server is okay. The only contractual obligation between a client and server is the message and the request headers. As it has little service obligations, it can be tuned to whatever the client needs are.

However, using RESTful service APIs is akin to doing meta-programming like Ruby and Python which delays problems to run-time as there is no defined schema agreed and technically enforced upon by the two sides. As such I don't recommend RESTful services everywhere, but I would recommend it if I had control of the two sides which normally happens when you do build a web application that uses static HTML/CSS/JS and talks with a RESTful server for the data.

like image 92
Archimedes Trajano Avatar answered Oct 24 '22 05:10

Archimedes Trajano