Hello, so we have application that should get a new configuration, CORS in this 
case, on the fly, without restarting the application, because it can have 
thousands of active connections.
Currently the configuration is stored in this application configuration file

$CATALINA_HOME/conf/Catalina/localhost/app.xml

and application gets it on startup and implements CORS restrictions. We have a 
need to change the configuration every now and then.
For example, I could possibly read the file once a minute, parse XML etc. and 
update settings, unless Tomcat is prohibiting the file access.
Application does not necessarily know the file path though, so it should be 
hard coded, which would be bad.
Tomcat has the code somewhere to do it, but it is likely an internal class.
We can workaround this by saving the configuration elsewhere, like in Windows 
registry, and read it from there once a minute.
Or we could save it to database.
But currently the configuration is in this deployment descriptor file, so I am 
asking if this has come up before.
Is there any other "standard" way of having mutable configuration for Tomcat 
application?

-Harri

-----Original Message-----
From: Christopher Schultz <ch...@christopherschultz.net> 
Sent: keskiviikko 13. huhtikuuta 2022 19.20
To: users@tomcat.apache.org
Subject: Re: Reconfiguring Tomcat application without restart

Harri,

On 4/13/22 07:32, Harri Pesonen wrote:
> Hello, is it possible to change the context file in
> 
> $CATALINA_HOME/conf/Catalina/localhost/app.xml
> 
> so that application would get the new configuration without restarting?

Without restarting... what exactly? And what would you want to change? 
Usually the things in that deployment descriptor are pretty fundamental to how 
the application starts-up, etc.

> I could not find such thing in servlet specification.

The servlet spec doesn't have anything like this in there, but Tomcat does. 
Sort of, depending upon exactly what you are trying to accomplish.

> Or would it be possible to manually read the file from the application, for 
> example once a minute?
> Now the application gets the configuration from init():
> 
> javax.servlet.GenericServlet.java
> 
>      /**
>       * Called by the servlet container to indicate to a servlet that the
>       * servlet is being placed into service.  See {@link Servlet#init}.
>       *
>       * <p>This implementation stores the {@link ServletConfig}
>       * object it receives from the servlet container for later use.
>       * When overriding this form of the method, call
>       * <code>super.init(config)</code>.
>       *
>       * @param config                                                         
>                     the <code>ServletConfig</code> object
>       *                                                                       
>                                                                   that 
> contains configutation
>       *                                                                       
>                                                                   information 
> for this servlet
>       *
>       * @exception ServletException                    if an exception occurs 
> that
>       *                                                                       
>                                                                   interrupts 
> the servlet's normal
>       *                                                                       
>                                                                   operation
>       *
>       * @see                                                                  
>                               UnavailableException
>       */
>      public void init(ServletConfig config) throws ServletException {
>                               this.config = config;
>                               this.init();
>      }
> 
> I suppose that getServletConfig() returns the same cached data without 
> re-reading it from disk?
> 
>      /**
>       * Returns this servlet's {@link ServletConfig} object.
>       *
>       * @return ServletConfig    the <code>ServletConfig</code> object
>       *                                                                       
>                                      that initialized this servlet
>       */
>      public ServletConfig getServletConfig() {
>                               return config;
>      }

Can you be more specific about what you want to achieve? I have some ideas, but 
before I send you down a potentially confusing path, it would be good to 
understand your goals.

-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to