Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is JAX-WS part of the JDK but JAX-RS is not?

When using Eclipse, I'm able to use JAX-WS annotations (e.g. @WebService) without including any external dependencies, but I can't do the same for JAX-RS annotations (e.g. @Path). I took a look at this answer and I understand that javax.ws.rs is not a part of the JDK. Why is it that JAX-WS is part of the JDK and JAX-RS is not? Secondly, if I deploy a JAX-WS annotated application on a GlassFish or WildFly server, does the server use a well-known WebService stack to run the application (e.g. Metro) or its own implementation?

like image 319
Aamir Khan Avatar asked Aug 02 '16 10:08

Aamir Khan


People also ask

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

JAX-WS is used for mainly building up web-services on an enterprise-level where you have stringent data formats to abide by and a common mode of message exchange in XML. JAX-RS is mostly used in smartphone apps and for purposes like Web Integration.

Is JAX-WS a framework?

JAX-WS is a framework that simplifies using SOAP. It is part of standard Java.

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 ...

Is JAX-RS part of Java EE?

From version 1.1 on, JAX-RS is an official part of Java EE 6. A notable feature of being an official part of Java EE is that no configuration is necessary to start using JAX-RS. For non-Java EE 6 environments a small entry in the web. xml deployment descriptor is required.


2 Answers

JAX-WS: Java API for XML Web Services

Let's go back to 2006. Java SE 6 was released introducing lot of new features.

Quoting the Java SE 6 specification (JSR 270), about the features introduced in Java SE 6:

The feature set for Java SE 6 is driven, in large part, by a set of themes.

The themes describe the main focal points of the release. Some themes are fairly abstract guiding principles; others are more concrete in that they identify particular problem areas, significant new feature sets, or specific target market segments.

[...]

  • XML & Web Services: The Java SE 5 release, as originally proposed, was intended to include a full Web Services client stack. That work unfortunately could not be completed in time for that release, and in the meantime XML and Web Services have only increased in their importance to many members of the community.

[...]

One of the goals of the JAX-WS 2.0 specification was to prepare JAX-WS for inclusion in a future version of J2SE (that was renamed to Java SE later). Quoting the JSR 224:

  • Inclusion in J2SE: JAX-WS 2.0 will prepare JAX-WS for inclusion in a future version of J2SE. Application portability is a key requirement and JAX-WS 2.0 will define mechanisms to produce fully portable clients.

Java SE 6 included the JAX-WS 2.0 component, introducing the possibility of creating SOAP based web services in Java SE. Quoting this article from Oracle:

One of the most exciting new features of the Java Platform, Standard Edition 6 (Java SE 6) is support for the Java API for XML Web Services (JAX-WS), version 2.0. JAX-WS 2.0 is the center of a newly rearchitected API stack for web services [...].

Although JAX-WS finds its main home in the open-source world of the Java Platform, Enterprise Edition 5 (Java EE 5) and is designed to take the place of Java API for XML-Based RPC (JAX-RPC) in such an environment, you can reuse much of the functionality without even touching an enterprise server [...]

You can use JAX-WS to build web applications and web services, incorporating the newer XML-based web services functionality. [...]

When you run the application, the Java SE 6 platform has a small web application server that will publish the web service. [...]

JAX-RS: Java API for RESTful Web Services

JAX-RS came later, in 2008. It was initially defined by the JSR 311 and it was included under the Java EE 6 umbrella specification (JSR 316).

The second version of JAX-RS came in 2013, defined by the JSR 339 and it was included under the Java EE 7 umbrella specification (JSR 342).

JAX-RS is HTTP centric and JAX-RS applications are frequently deployed on servlet containers.

The Java SE 7 (JSR 336) and the Java SE 8 (JSR 337) specifications don't incorporate the JAX-RS component. However, JAX-RS applications can be published in Java SE environments (using RuntimeDelegate) and JAX-RS implementations also may support publication via JAX-WS.

Including JAX-RS in Java SE also means including an implementation for that specification. And it makes things more complicated in the Java SE environment, but perfectly acceptable in a Java EE environment where your container will provide you an implementation. For example, GlassFish gives you Jersey (the reference implementation) while JBoss/WildFly gives you RESTEasy.

like image 161
cassiomolin Avatar answered Sep 30 '22 15:09

cassiomolin


JAX-RS (The Java API for RESTful Web Services) is actually a specification that defines REST support. The specification is defined via the Java Specification Request (JSR) 311.

In a nutshell this specification defines an API and some Annotations that all compliant JAX-RS implementations should use. So the specification itself is used by JAX-RS implementors that create a JAX-RS implementation such as Jersey and by programmers (end users) that can use any compliant JAX-RS implementation with the same way.

In order to use JAX-RS you need an implementation of the JAX-RS. So if one is not included in JDK an external one can be used. The actual decision of what implementations should be included or not in the JDK is complex, some interesting criteria could be the implementation maturity and acceptance, as well as the frequency of usage. (A rarely used feature could be downloaded extra.)

This answer uses information provided here:

http://www.vogella.com/tutorials/REST/article.html#restjersey

For the second part of your question: Servers use the bundled implementations. For example Glassfish use Metro for JAX-WS but this depends on the server.

like image 35
Spyros K Avatar answered Sep 30 '22 15:09

Spyros K