Skip to content

stdunbar/jaxrs-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JAX-RS Sample application for Wildfly

A very simple JAX-RS sample application that implements a few services. The services are meant purely as a demonstration and are not "real" services.

Deployment

To build, simply run

mvn clean package

This will compile, run the unit tests, and create a war file that can be deployed into an JEE app server. I've only tested with Wildfly at this point.

The war file can be deployed to Wildfly and possibly other JEE application servers. For Wildlfy, there are many options to deploy listed on the application deployment page that can help deploy.

Sample Service Info

There are a total of three service endpoints:

GET /v1/heartbeat - returns a "text/plain" HTTP body of "OK" if the service is up and running. A heartbeat service like this is commonly used in load balancing environments so that a load balancer can validate that an application is healthy.

POST /v1/product - puts a "product" in the catalog. The product is a simple JSON formatted object:

{"description": "The Product Description"}

This creates a product in the catalog. The response will look like:

{
  "productId": 96361,
  "description": "The Product Description",
  "createDate": "2017-04-10T02:51:12.772Z"
}

Note that the productId is simply a random integer between 10000 and 1000000. The createDate is when the product was added to the catalog. Note that you can also send your own product id in the POST:

{
  "productId": 123456,
  "description": "The Product Description"
}

in which case the id that is given will be used.

If the product id is already in use a 409 (Conflict) HTTP error will be returned with the body

{
  "message": "product id 123456 already exists"
}

GET /v1/product/{productId} gets an existing product with the given product id. The response body looks the same as the call to create a new product. A call with a product id that doesn't exist will return an HTTP 404 error with the body:

{
  "message": "productId not found - 123456"
}

GET /v1/version gets a long description of the current version. Note that in a production environment this could give out a bit more (or perhaps alot more) information than you might like to. This call takes advantage of the Accepts header - if you don't specify anything then you'll get an XML response. Pass application/json to get back JSON.

GET /v1/version/summary gets a short description of the current version. This is a text/plain response that gets just a quick summary of the version information. Again, it may give out more information than you'd like.

Logging

The two product services are annotated with @Logged which means that the input and output of them will be logged to the loggers. This is a nice way to get the input and output of the web service calls without using any proprietary libraries.

Copyright (c) 2020 by Xigole Systems Licensed under the MIT License - see the file LICENSE for details.

About

A very simple JAX-RS sample application

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages