I used your code ( Thanks ) and I finally got it to work with a Filter. We
have a login filter in our app. So I added a method which runs only in
development mode.
* Set the DEVELOPMENT_MODE system property during development.
* Add the WEB-INF directory to the classpath. ( does Tomcat include this in
the classpath ? )
* Call this method from the doFilter() method in your filter.
private long lastModified = 0;
private void reloadConfig(HttpServletRequest request) {
if ( System.getProperty("DEVELOPMENT_MODE") != null ) {
try {
URL url = LoginFilter.class.getResource("/struts-config.xml");
if ( url == null )
return;
File f = new File(url.getFile());
if ( f.lastModified() != lastModified ) {
ActionServlet as = ( (ActionServlet)
request.getSession().getServletContext().getAttribute(
Globals.ACTION_SERVLET_KEY));
as.destroy();
request.getSession().getServletContext().removeAttribute(Globals.REQUEST_PRO
CESSOR_KEY);
as.init();
System.out.println("Reload ok.");
}
lastModified = f.lastModified();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
Thanks
-- pady
[EMAIL PROTECTED]
-----Original Message-----
From: Leonardo Francalanci [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 25, 2004 7:19 AM
To: Struts Users Mailing List
Subject: R: Automatically detecting struts-config changes and reload app.
I wrote the following on 01/23/2004 on the mailing list, but nobody cared...
I wrote a servlet to trigger off a reload of the struts-config.xml.
The servlet is:
protected void doGet(..) {
ActionServlet as =
((ActionServlet)request.getSession().getServletContext().getAttribute(Global
s.ACTION_SERVLET_KEY));
as.destroy();
request.getSession().getServletContext().removeAttribute(Globals.REQUEST_PRO
CESSOR_KEY);
as.init();
new PrintStream(response.getOutputStream()).println("Reload
ok.");
}
Now my questions...
1) Is there another way to trigger off a reload without using the Tomcat's
reload
function (which takes a very long time and leaves db connections open?)
2) I had to call removeAttribute(Globals.REQUEST_PROCESSOR_KEY) because the
destroy method
of the ActionServlet doesn't do it. Here is the code (from
ActionServlet.destroyModules()):
[..]
if (value instanceof ModuleConfig) {
ModuleConfig config = (ModuleConfig) value;
getRequestProcessor(config).destroy();
getServletContext().removeAttribute(name);
I think there should be something like
getServletContext().removeAttribute(Globals.REQUEST_PROCESSOR_KEY +
config.getPrefix());
If I don't remove the attribute following requests will not work (because of
the code
in ActionServlet.getRequestProcessor)
Is this a bug?
3) Don't you think that something like that could be useful? I mean, if
answer to 1) is NO,
wouldn't be useful to have a configuration reloader with struts?
4) Calling actionServlet.destroy() and actionServlet.init() is enough to
re-load the whole
struts-config.xml?
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
______________________________________________________________________
This e-mail has been scanned by the Heroix e-mail security system
______________________________________________________________________
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]