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

2

5

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?

Anestassia answered 2/8, 2016 at 10:31 Comment(0)
D
5

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.

Downstage answered 4/8, 2016 at 23:2 Comment(0)
H
2

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.

Hobson answered 2/8, 2016 at 13:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.