Editing server.properties programmatically causes no change? - java

I am trying to implement a simple database configuration editor (to change host, port, user, etc.), but after saving the /WEB-INF/classes/server.properties file, changes do not seem to be recognized (the old configuration is still there when I access the built-in database configuration page). How can I tell SmartGWT to reload the database configuration?

Usually Application reads properties at sturtup and sets theese properties to java objects. So if you are changing properties during your application lifetime you need to take care about rereading them after your change and recreating (refreshing) objects that use them.
For more specific example please provide some code.

You can use the Config class to do this. Simply call the following static method to reload the global config.
Config.initGlobalConfig();
See http://www.smartclient.com/smartgwtee-latest/server/javadoc/com/isomorphic/base/Config.html for more information.

Related

What is the point of creating external configuration file in spring boot?

I am new to spring. But here a concept is confusing me and am also not getting a clear answer. I am not sure what is the point of creating an external configuration file? Like, what is the point of application.properties ? We can also use the features via code right? Also, if we make a change to the configuration file then we also have to rerun the application right? Then what is the point of doing such a thing?
Thanks in advance.
The point of application.properties is to be able to change some properties without re-compiling your code. So in big companies no QA phase, delivery needed
You just change some properties, restart the application and ready to go.
The application.properties or application.yml file contains the environment variables. This is quite similar with constants in your application. The importance of externalizing it is to minimize updating the source code when some configuration changes.
Example: Your app's database migrated to another server.
You can just update your application.properties file instead of opening your DBConfig.java.
Another benefit is if your team is using Spring Cloud Config Server where your app connects and fetches the testing/staging/production configurations. This means that your configurations are not tightly coupled into your app's source code.
Whereas if you do it directly into your source code, then every time there's a change in the configuration (be it database connection, connection to other services, etc) you'll have to update your code then rebuild and deploy.

How to set "web application properties" so HSQLDB can use them?

I want to use HSQLdb for my Spring-based web application, and I want to have the data persistent (so in-memory is out). According to the hsqldb documentation, I can use variables in the connection URL - but the document doesn't say how to set these.
I've read this question, and there are some interesting tactics, such as creating a listener to set properties when the context loads.
This question explains how to get an appropriate location, so I've combined the two approaches. I've tried using a listener to set a new property with the path lifted from javax.servlet.context.tempdir (it's a File), I've tried using that property directly. Neither approach works.
One punter has commented that one could set user.home via a listener, then use ~ in the HSQLdb URL. I've not tried this, but even if it does work, it strikes me as a little yuck, as I redefine something I potentially don't want to. I'm looking for the "proper" way. How do I set that which the HSQLdb calls "web application properties"? (Or is there one that would be suitable?)
From the documentation:
If the database URL contains a string in the form of ${propname}
then the sequence of characters is replaced with the system property
with the given name. For example you can use this in the URL of a
database that is used in a web application and define the system
property, "propname" in the web application properties. In the example
below, the string ${mydbpath} is replaced with the value of the
property, mydbpath
From reading the source code, System.setProperty(key, value)
Kicking myself - my issue was first an ancient version of HSQLdb then it wasn't unloading - a restart of Tomcat, and everything started working.

Centralized Application properties for multiple system

I am looking for a open-source solutions which allow hosting different properties for different applications and allow changes. On any change of properties it should notify or push the change to the application appropriately.
So, instead every application managing the properties in physical file and deploying physically; these properties can be pushed to a single system. User will have GUI to load and change the properties as per right. Should allow push as mentioned.
If you have already similar open source solutions in mind please advice.
Is this something that Puppet can manage for you?
I don't think what you've described (as nice as it would be) will be likely to exist in an app server. If a program is looking for a file, it's either going to load it with a FileReader (or similar), or it will use ClassLoader.getResourceAsStream(). It might be looking for data that is returned in properties, format, XML properties format, or even something completely different like RDF with which to configure itself. Also many programs read their config on start-up and then hold the values in memory, so you would still need to reboot them to get them to change.
To get something like this to work there would need to be a standard for configuration provisioning and live updates. Once that existed the webapp authors and server vendors would each need to add support for the standard.
If you are the one writing the programs to be managed however, then you can write your programs to request configuration from a service, and have a configuration push feature.... there may be packages out there that can speed up adding that to your code, but I get the impression you are looking to manage programs written by others.
Have you considered to use JMX? I think he could be a good starting point to implement your requirements.
MBeans's attributes can store your application's properties, the MBeanServer will allow you to make them available from remotting, JConsole offers you an GUI to update properties values.
You also can write within the MBean some code that notify the corrrespondig application when a user change any properties using the GUI.

Pass properties to log4j before it loads

Is there a way to pass data or setting to log4j before it loads and then use that property within the config file.
I was assuming there is a system properties I could use:
log4j.appender.R.File=/usr/local/pfs/logs/${ws.host}/log4j.log
Where ws.host is the property I want to use.
But how can I set that value?
Also, I am in a web environment. How can I know at what point to set the property setting before log4j loads.
The default log4j PropertiesConfigurator supports variable substitution.
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PropertyConfigurator.html
So, you could pass system properties like this "-DmyProject.logFile="/temp/test.log" to your Java startup, and then in the properties files have "log4j.appender.R.File=${myProject.logFile}".
If working from a web environment, you might want to check out Spring's Log4jConfigListener. It uses a listener (Servlet API 2.4+) to initialization log4j ahead of other components. Even if not using Spring, you should be able to use the source as an example to easily create your own listener.

Application configuration save to file or object serialization

I am working on a project and I need to save user configuration. The configuration is a set of Jchechboxes I need to store their state (true, false). Which do you think is the better way of saving it, in a file and if yes in what (ini, cfg, txt), or it is better to serialize the object with the states?? Or if there is another way, please tell me :)
Cheers
It depends if you need to access the variables many times, and when: at the start of the application or during runtime?
If this configuration is user-related maybe you want to keep separate configuration for each user serialized on a Database so you can load them dynamically when a user loads the form that displays the checkboxes.
If there's just one possible configuration for one user (or such) maybe you should just put everything in a text file (the extension doesn't matter: ini,cfg,txt,lol anything you want) just simplify your life by using standard Java configuration access using the Properties class: http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html
How about a Properties file?
If you decided to store the properties as a serialized object then you will make changing the implementation of the gui much harder and thus less portable. If you save them in a text file then you are free to change the GUI implementation without any disruption to the user, whilst allowing the user to keep their saved properties.
As such, I would always recommend storing preferences in a properties type file. The Properties API, and related commons classes are pretty simple to use.
The best method is to use java.util.prefs to store user preferences

Categories

Resources