https://github.com/ghusta/jaxrs-sample-jersey
JAX-RS Sample : Jersey version
https://github.com/ghusta/jaxrs-sample-jersey
jax-rs jersey
Last synced: over 1 year ago
JSON representation
JAX-RS Sample : Jersey version
- Host: GitHub
- URL: https://github.com/ghusta/jaxrs-sample-jersey
- Owner: ghusta
- Created: 2017-11-16T16:01:50.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-24T10:04:50.000Z (over 8 years ago)
- Last Synced: 2025-01-06T22:36:00.716Z (over 1 year ago)
- Topics: jax-rs, jersey
- Language: Java
- Size: 38.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.adoc
Awesome Lists containing this project
README
= JAX-RS Sample : Jersey version
:toc:
:toc-placement: manual
:toclevels: 2
image:https://travis-ci.org/ghusta/jaxrs-sample-jersey.svg?branch=master["Build Status", link="https://travis-ci.org/ghusta/jaxrs-sample-jersey"]
toc::[]
== Overview
Sample project for testing JAX-RS 2.0 with Jersey 2.x
== Project generation
Maven archetype used :
[source,shell]
----
mvn archetype:generate -DarchetypeGroupId=org.glassfish.jersey.archetypes -DarchetypeArtifactId=jersey-quickstart-webapp -DarchetypeVersion=2.25.1 -DgroupId=fr.husta.test.jaxrs -DartifactId=jaxrs-sample-jersey -B
----
== Run
Run the webapp with :
[source,shell]
----
mvn jetty:run
----
[NOTE]
Jetty 9 needs Java 8 !
== REST with JAX-RS
What is the use of certain HTTP headers ?
=== Request Headers
|===
| HTTP Header | Use | JAX-RS Annotations | Example
| `Accept`
| Used to set the preference for the content type of the *response body*. Can have multiple values. If unsuitable, server will send a HTTP 406.
| `@Produces`
| application/json,application/xml
| `Content-Type`
| Used to precise the content type of the *request body*.
| `@Consumes`
| application/json
|===
=== Response Headers
|===
| HTTP Header | Use | JAX-RS Annotations | Example
| `Content-Type`
| Used to precise the content type of the *response body*. No header if no content.
| Depends on `@Accept` and https://en.wikipedia.org/wiki/Content_negotiation[Content negotiation]
| application/json
|===
== JAX-RS with Jersey
I use https://jersey.github.io/[Jersey] as the https://github.com/jax-rs[JAX-RS] implementation.
Up to Jersey 2.25, Java 6 and JAX-RS 2.0 (https://jcp.org/en/jsr/detail?id=339[JSR-339]) are required.
As of Jersey 2.26, there are https://jersey.github.io/documentation/latest/migration.html#mig-2.26[important changes] :
- Requires Java 8
- Use JAX-RS 2.1 (https://jcp.org/en/jsr/detail?id=370[JSR-370])
== Docker
=== Build an image
[source,shell]
----
docker build -t jaxrs-sample-jersey .
----
=== Run a container
[source,shell]
----
docker run -d –name jaxrs-test-1 -p 8090:8080 jaxrs-sample-jersey
----
=== Test
Open a browser on http://localhost:8090/jaxrs-sample-jersey/[http://localhost:8090/jaxrs-sample-jersey/]
Or try :
[source,shell]
----
curl -X GET http://localhost:8090/jaxrs-sample-jersey/webapi/myresource[http://localhost:8090/jaxrs-sample-jersey/webapi/myresource]
----
_Generated with Asciidoctor {asciidoctor-version}_