Java Jersey: Difference between revisions
Line 72: | Line 72: | ||
== See also == | == See also == | ||
<span class="editsection">[[#content|top]]</span> | <span class="editsection">[[#content|top]]</span> | ||
Implementations of JAX-RS include:<ref>Mark Little, [http://www.infoq.com/news/2008/10/jaxrs-comparison A Comparison of JAX-RS Implementations]</ref> | |||
* [[wikipedia:Apache CXF|Apache CXF]], an open source Web service framework | |||
* [[wikipedia:Project_Jersey | Jersey]], the [[wikipedia:reference implementation|reference implementation]] from [[wikipedia:Sun Microsystems|Sun]] (now [[wikipedia:Oracle Corporation|Oracle]]) | |||
* [http://www.jboss.org/resteasy RESTeasy], [[wikipedia:JBoss|JBoss]]'s implementation | |||
* [[wikipedia:Restlet| Restlet]] | |||
* [[wikipedia:Apache Wink|Apache Wink]], [[wikipedia:Apache Software Foundation| Apache Software Foundation]] Incubator project, the server module implements JAX-RS | |||
* [[wikipedia:WebSphere Application Server|WebSphere Application Server]] from [[IBM]]: | |||
** Version 7.0: via the [http://www-01.ibm.com/software/webservers/appserv/was/featurepacks/cea/index.html "Feature Pack for Communications Enabled Applications"] | |||
** Version 8.0 onwards: natively | |||
* [[wikipedia:Oracle WebLogic Server|WebLogic Application Server]] from [[wikipedia:Oracle Corporation|Oracle]], see [http://docs.oracle.com/cd/E24329_01/web.1211/e24963/standards.htm#g1090347 notes] | |||
* Apache Tuscany (http://tuscany.apache.org/documentation-2x/sca-java-bindingrest.html) | |||
* Cuubez framework (http://www.cuubez.com) | |||
* [https://github.com/codenvy/everrest/wiki Everrest], Codenvy's Implementation | |||
== Reference == | == Reference == |
Revision as of 06:57, 20 June 2015
Developing RESTful Web services that seamlessly support exposing your data in a variety of representation media types and abstract away the low-level details of the client-server communication is not an easy task without a good toolkit.
In order to simplify development of RESTful Web services and their clients in Java, a standard and portable JAX-RS API
[1]
[2]
has been designed. Jersey RESTful Web Services framework is open source, production quality, framework for developing RESTful Web Services in Java that provides support for JAX-RS APIs and serves as a JAX-RS (JSR 311 & JSR 339) Reference Implementation.
Jersey framework [3] is more than the JAX-RS Reference Implementation. Jersey provides it’s own API that extend the JAX-RS toolkit with additional features and utilities to further simplify RESTful service and client development. Jersey also exposes numerous extension SPIs so that developers may extend Jersey to best suit their needs.
Maven
Jersey is complete maven build. The following is tested for OS/X and should work on Linux/Unix. Assumed is that you have installed maven successful and also have the right location for the m2 libraries.
Creating a New Project from Maven Archetype
- Open Terminal
- Goto the directory where you wanna build the Jersey Simple Service (i.e. /Sources/Java/Jersey/Refmaven)
- Type:
mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-grizzly2 -DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false -DgroupId=com.example -DartifactId=simple-service -Dpackage=com.example -DarchetypeVersion=2.18
which should end-up with
[INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 15.289s [INFO] Finished at: Fri Jun 19 20:01:09 CEST 2015 [INFO] Final Memory: 13M/126M [INFO] ------------------------------------------------------------------------ $
The results are:
- A new simple-service project directory created in your current location.
- Project build and management configuration is described in the pom.xml located in the project root directory.
- Project sources are located under src/main/java.
- Project test sources are located under src/test/java.
- There are 2 classes in the project source directory in the com.example package:
- The
Main class
is responsible for bootstrapping the Grizzly container as well as configuring and deploying the project's JAX-RS application to the container. - The
MyResource class
contains implementation of a simple JAX-RS resource.
- The
MyResource class
package com.example; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; /** * Root resource (exposed at "myresource" path) */ @Path("myresource") public class MyResource { /** * Method handling HTTP GET requests. The returned object will be sent * to the client as "text/plain" media type. * * @return String that will be returned as a text/plain response. */ @GET @Produces(MediaType.TEXT_PLAIN) public String getIt() { return "Got it!"; } }
See also
top Implementations of JAX-RS include:[4]
- Apache CXF, an open source Web service framework
- Jersey, the reference implementation from Sun (now Oracle)
- RESTeasy, JBoss's implementation
- Restlet
- Apache Wink, Apache Software Foundation Incubator project, the server module implements JAX-RS
- WebSphere Application Server from IBM:
- Version 7.0: via the "Feature Pack for Communications Enabled Applications"
- Version 8.0 onwards: natively
- WebLogic Application Server from Oracle, see notes
- Apache Tuscany (http://tuscany.apache.org/documentation-2x/sca-java-bindingrest.html)
- Cuubez framework (http://www.cuubez.com)
- Everrest, Codenvy's Implementation
Reference
- ↑ Wikipedia JAX API WS, Java API for XML Webservices.
- ↑ Wikipedai JAX RS, Java API for RESTful WebServices
- ↑ Jersey Homepage, Jersey
- ↑ Mark Little, A Comparison of JAX-RS Implementations