# jersey-rest-server
**Repository Path**: shine05/jersey-rest-server
## Basic Information
- **Project Name**: jersey-rest-server
- **Description**: RESTful WebService with Maven, Jersey and Jetty
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2021-04-14
- **Last Updated**: 2021-11-03
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
[](https://buildhive.cloudbees.com/job/marcelbirkner/job/jersey-rest-server/)
# Overview
This Github project contains examples, how to create annotated REST Services. The following examples are provided:
- HTTP Methods used: @GET, @POST, @PUT, @DELETE
- MediaType: Application/JSON
- Path configuration: @Path
The REST Services are automatically documented using Enunciate (http://enunciate.codehaus.org/).
This has the advantage to keep the source code and documentation
## Example
```
@Path("/user")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class UserService {
...
@GET
@Path("/{userId}")
public User getUserById(@PathParam("userId") String userId) {
...
}
@POST
public User createUser(User user) {
...
}
```
## Technologies used
- Maven 2.2.1 (Build tool)
- Java 1.7
- Jersey 6 (JAX-RS)
- Jetty 6 (Server)
- Enunciate 1.28 (API Documentation)
# Enunciate Integration
To automatically document the REST endpoints and the data model, i added Enunciate from Codehaus to the maven configuration.
In order to generate and view the Enunciate documentation follow these steps. Enunicate parses the JAX-WS/RS annotation and JavaDoc
to generate the REST API. This way you keep the documentation and source code in one location.
```
mvn install
mvn jetty:run-exploded
```
You can find the Enunciate under: http://localhost:8080/server-example/
## Enunciate Screenshots

# REST Server
You can run the RESTful Server using jetty:run. After that you can use curl or your browser to test the different services.
## Automatic smoketests
Use *smoketests/run-smoketests.sh* to execute a list of smoketests, against the REST Services.
## Manual tests with curl
Here are a couple of test cases you can try locally on your maschine. All you need is a shell with curl installed.
### Ping Service
*1. Request: Plain Text*
```
curl -I http://localhost:8080/server-example/rest/ping/ -H'Accept:text/plain'
```
*1. Response*
```
HTTP/1.1 200 OK
Content-Length: 0
Content-Type: text/plain
Server: Jetty(6.1.26)
```
*2. Request: XML*
```
curl -I http://localhost:8080/server-example/rest/ping/ -H'Accept:text/xml'
```
*2. Response*
```
HTTP/1.1 200 OK
Content-Length: 0
Content-Type: text/xml
Server: Jetty(6.1.26)
```
*3. Request: HTML*
```
curl -I http://localhost:8080/server-example/rest/ping/ -H'Accept:text/html'
```
*3. Response*
```
HTTP/1.1 200 OK
Content-Length: 0
Content-Type: text/html
Server: Jetty(6.1.26)
```
*4. Request: Plain Text*
```
curl http://localhost:8080/server-example/rest/ping/ -H'Accept:text/plain'
```
*4. Response*
```
Ping: System OK
```
*5. Request: XML*
```
curl http://localhost:8080/server-example/rest/ping/ -H'Accept:text/xml'
```
*5. Response*
```