I'm trying to create a web app using Java Jersey. That project (dynamic web project), should have parameters changeable by the clients / server admins during run-time. Admins don't have any access to the database. Before transforming our app to the web-service we had properties file defined in the folder next to our main jar. Is there a way to have something like that with dynamic web app? My idea is to have a folder with properties file, accessible and changlable by server admins (so that web service can change it's work parameters in run-time). Storing properties in database instead of file is a no-go. It must be a config file :) Do you have any idea how should i put my properties file in a relative path so that server admins, using that file, can change certain web service parameters while WS is already deployed and working?
Asked
Active
Viewed 351 times
-3
-
Maybe you'll get some ideas from [this](http://stackoverflow.com/q/26386006/2587435) – Paul Samsotha Oct 23 '15 at 08:20
-
If you are using CDI, you could consider Apache DeltaSpike Configuration Mechanism. Have a look [here](http://stackoverflow.com/a/31361654/1426227). – cassiomolin Oct 23 '15 at 09:39
1 Answers
0
As per your requirement you can use Properties file but the thing is WS loads the properties file only when it starts. So you have to load that properties file in your program code. And you need to reload the file after some time interval. Refer following code for your reference :
public class ResourceHandler {
/** The service end points. Creates properties file object. */
Properties serviceEndPoints = new Properties();
/** The resource handler. */
private static ResourceHandler resourceHandler = new ResourceHandler();
/**
* Instantiates a new resource handler.
*/
ResourceHandler() {
try {
/* Load the properties file from class path, you can use reguler file path instead of this. */
serviceEndPoints.load(this.getClass().getResourceAsStream(
"serviceEndPoints.properties"));
} catch (IOException e) {
}
}
/**
* Instance.
*
* @return the resource handler
*/
public static synchronized ResourceHandler instance() {
if (resourceHandler == null)
resourceHandler = new ResourceHandler();
return resourceHandler;
}
/**
* Gets the service end points.
*
* @param key
* the key
* @return the service end points
* Use this method to get values of parameters from properties file.
*/
public String getServiceEndPoints(String key) {
return ((String) serviceEndPoints.get(key));
}
}
The above code is for loading the file at single time. As you want to fetch the parameters those have changed instantly then you have to load that file after some time of interval. But surely it is possible!

Manish Mane
- 64
- 3