tree: a6f11987b58bafeeae5a0c535adc5243ebf6a133 [path history] [tgz]
  1. src/
  2. pom.xml
  3. README.MD
  4. resources
examples/reload/README.MD

Resource Configuration Reload Example

This example demonstrates how to create a simple Jersey application with resource reloading capability using Grizzly HTTP Server container.

Contents

The mapping of the URI path space is presented in the following table:

URI pathResource classContentHTTP methods
/flights/arrivalsorg.glassfish.jersey.examples.reload.ArrivalsResourceDummy Arrivals InformationGET
/flights/departuresorg.glassfish.jersey.examples.reload.DeparturesResourceDummy Departures InformationGET
/flights/statsorg.glassfish.jersey.examples.reload.StatsResourceStatistics on application resource utilizationGET

The application gets configured via a plain text file named resources. The file contains a list of resource classes to be published by the application. After the application gets started, it watches the file system and reloads the application as file updates are being detected. Changes in JAX-RS resource source files and updates of the above mentioned resources file are being detected. Java code re-compilation is done as required.

Running the Example

Run the example as follows:

mvn clean compile exec:java

This deploys current example usingGrizzly container. StatsResource should be available at http://localhost:8080/flights/stats

You may want to check the other resources as well:

Updated information on number of hits should be available at http://localhost:8080/flights/stats. Now you can try to edit the resources file and comment the stats resource out by using the # prefix. The point is you leave the application running while editing the file. The changes wil get picked up automatically. No need to manually restart the application. The resource file content should now look like follows:

org.glassfish.jersey.examples.reload.DeparturesResource
org.glassfish.jersey.examples.reload.ArrivalsResource
#org.glassfish.jersey.examples.reload.StatsResource

Once you save the change, the stats resource should not be available, but the other, departures/arrivals, resources should remain functional.

Now you can revert the change back and check the stats resource is back providing actual statistics information.

You can also try to change the JAX-RS resources source code. These changes will be also picked up automatically.