RE: Automatically detecting struts-config changes and reload app.
Seems like somebody ought to point out that calling lifecycle methods (like Servlet.init and Servlet.destroy) from app code is generally a bad idea. OTOH, if it works for you... Quoting Pady Srinivasan <[EMAIL PROTECTED]>: > > I made a small change to the code where setting WEB-INF in the classpath is > not required. > > private long lastModified = 0; > private void reloadConfig(HttpServletRequest request) { > if ( System.getProperty("DEVELOPMENT_MODE") != null ) { > try { > File f = new > File(request.getSession().getServletContext().getRealPath("/WEB-INF/struts-c > onfig.xml")); > 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: Pady Srinivasan [mailto:[EMAIL PROTECTED] > Sent: Thursday, March 25, 2004 9:37 AM > To: Struts Users Mailing List > Subject: RE: Automatically detecting struts-config changes and reload app. > > > 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 > >
RE: Automatically detecting struts-config changes and reload app.
I made a small change to the code where setting WEB-INF in the classpath is not required. private long lastModified = 0; private void reloadConfig(HttpServletRequest request) { if ( System.getProperty("DEVELOPMENT_MODE") != null ) { try { File f = new File(request.getSession().getServletContext().getRealPath("/WEB-INF/struts-c onfig.xml")); 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: Pady Srinivasan [mailto:[EMAIL PROTECTED] Sent: Thursday, March 25, 2004 9:37 AM To: Struts Users Mailing List Subject: RE: Automatically detecting struts-config changes and reload app. 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 Messag
RE: Automatically detecting struts-config changes and reload app.
The parseModuleConfigFile method in ActionServlet ( called by init() ) seems to get the resource and reparse the information. Unless there is a screw up somewhere there, I don't know why the re-read should fail. I will see if that can be reproduced. Thanks -- pady [EMAIL PROTECTED] -Original Message- From: Leonardo Francalanci [mailto:[EMAIL PROTECTED] Sent: Thursday, March 25, 2004 8:53 AM To: Struts Users Mailing List Subject: R: Automatically detecting struts-config changes and reload app. > 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. just one thing: I'm not sure, but it seems that sometimes Tomcat does not re-read the file. It's like it keeps it cached somewhere. So beware: sometime you have to reload you application to reload the config. I think that happens because of the classLoader used by tomcat. - 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]
RE: Automatically detecting struts-config changes and reload app.
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]
RE: Automatically detecting struts-config changes and reload app.
I spent a few hours trying it out yesterday. There is a Tiles ReloadAction which I tried to set in the struts-config and tried to call it. But it didn't help. Finally I went with the Tomcat manager ( app reload ). If Tomcat recognizes class changes ( WEB-INF/classes ), maybe there is a way to make it recognize struts-config.xml changes. Thanks -- pady [EMAIL PROTECTED] -Original Message- From: Antony Paul [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 24, 2004 10:58 PM To: Struts Users Mailing List Subject: Re: Automatically detecting struts-config changes and reload app. I could not understand what is admin mappings. I am using Struts 1.1 downloaded few months ago. There is nothing like admin in struts-config.xml included with struts-blank.war. If you please explain it it will be usefule. I presume that it is similar to Tomcat manager application and I have to reload it every time by pointing the browser to it. I want it to automatically detect the change and reload the context . What are other developers doing to reload the context on struts-config change ?. Antony Paul - Original Message - From: "Geeta Ramani" <[EMAIL PROTECTED]> To: "Struts Users Mailing List" <[EMAIL PROTECTED]> Sent: Wednesday, March 24, 2004 7:01 PM Subject: Re: Automatically detecting struts-config changes and reload app. > Hey Antony: > > Check out the struts admin functionality: Make sure you have the admin > mappings in your struts-config.xml, then point your browser to > "/yourContext/admin/reload.do" and you'll see the magic..:) > > Regards, > Geeta > > Antony Paul wrote: > > > Is it possible to automatically detect changes in struts-config.xml and > > reload the application ?. I know that Log4J(or Tomcat) detects changes to > > log4j.properties and reload the application. > > > > Antony Paul > > > > - > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > - 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]
Re: Automatically detecting struts-config changes and reload app.
I could not understand what is admin mappings. I am using Struts 1.1 downloaded few months ago. There is nothing like admin in struts-config.xml included with struts-blank.war. If you please explain it it will be usefule. I presume that it is similar to Tomcat manager application and I have to reload it every time by pointing the browser to it. I want it to automatically detect the change and reload the context . What are other developers doing to reload the context on struts-config change ?. Antony Paul - Original Message - From: "Geeta Ramani" <[EMAIL PROTECTED]> To: "Struts Users Mailing List" <[EMAIL PROTECTED]> Sent: Wednesday, March 24, 2004 7:01 PM Subject: Re: Automatically detecting struts-config changes and reload app. > Hey Antony: > > Check out the struts admin functionality: Make sure you have the admin > mappings in your struts-config.xml, then point your browser to > "/yourContext/admin/reload.do" and you'll see the magic..:) > > Regards, > Geeta > > Antony Paul wrote: > > > Is it possible to automatically detect changes in struts-config.xml and > > reload the application ?. I know that Log4J(or Tomcat) detects changes to > > log4j.properties and reload the application. > > > > Antony Paul > > > > - > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Automatically detecting struts-config changes and reload app.
Anybody have an example of this ? I searched in the user/developer guides and Google and couldn't find much. Thanks -- pady [EMAIL PROTECTED] -Original Message- From: Geeta Ramani [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 24, 2004 8:32 AM To: Struts Users Mailing List Subject: Re: Automatically detecting struts-config changes and reload app. Hey Antony: Check out the struts admin functionality: Make sure you have the admin mappings in your struts-config.xml, then point your browser to "/yourContext/admin/reload.do" and you'll see the magic..:) Regards, Geeta Antony Paul wrote: > Is it possible to automatically detect changes in struts-config.xml and > reload the application ?. I know that Log4J(or Tomcat) detects changes to > log4j.properties and reload the application. > > Antony Paul > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] - 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 email has been scanned by the Heroix e-mail Security System __ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Automatically detecting struts-config changes and reload app.
Hey Antony: Check out the struts admin functionality: Make sure you have the admin mappings in your struts-config.xml, then point your browser to "/yourContext/admin/reload.do" and you'll see the magic..:) Regards, Geeta Antony Paul wrote: > Is it possible to automatically detect changes in struts-config.xml and > reload the application ?. I know that Log4J(or Tomcat) detects changes to > log4j.properties and reload the application. > > Antony Paul > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]