Hook into webapp start and stop events

Questions and Answers on installation, deployment, management, locking, tranasactions of Servoy Application Server

Hook into webapp start and stop events

Postby vincent.schuurhof » Mon Jul 10, 2023 5:24 pm

We have an external JAR stored in the "plugins" folder which autonomously needs to execute code when the webapp is started or stopped. Normally, you could have your own implementation of the "ServletContextListener" and register as a listener in "web.xml" to make this happen. I tried a number of things but when using Servoy this doesn't seem to be as straightforward as I hoped it would be.

Is there a way to do such a thing without interfering with Servoy's own "WarClientServletContextListener"?
vincent.schuurhof
 
Posts: 5
Joined: Mon Jul 10, 2023 4:58 pm

Re: Hook into webapp start and stop events

Postby jcompagner » Mon Jul 10, 2023 5:36 pm

why does it interfere ?
what happens? is the WarClientServletContextListener always first and that is not what you want?
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8822
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Hook into webapp start and stop events

Postby vincent.schuurhof » Tue Jul 11, 2023 8:51 am

Actually my primary issue is that when I add another listener in "web.xml" like so:
Code: Select all
<listener>
    <listener-class>com.servoy.j2db.server.servlets.WarClientServletContextListener</listener-class>
</listener>
<listener>
    <listener-class>nl.smartaim.sam.ContextListener</listener-class>
</listener>


Tomcat logs a "ClassNotFoundException" for the second listener. I then tried moving the JAR to the "WEB-INF/lib" folder but then it already fails on the first listener (and logs some other issues).

So let me rephrase my question: how can I make sure this class is found which is located in a JAR stored in the "plugins" folder?
vincent.schuurhof
 
Posts: 5
Joined: Mon Jul 10, 2023 4:58 pm

Re: Hook into webapp start and stop events

Postby jcompagner » Tue Jul 11, 2023 9:27 am

thats impossible (jar only in \plugins folder in the WAR), for stuff that tomcat needs to find it must be in WEB-INF/lib
(that is by the way what we now do by default in the versions i think from 2022.09 or 12 on anyway)

So i don't get it what goes wrong if you make sure the jar is just in WEB-INF/lib that should work fine.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8822
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Hook into webapp start and stop events

Postby vincent.schuurhof » Tue Jul 11, 2023 11:56 am

Yes, that is what I thought as well. This is why I also tried to move it to "WEB-INF/lib". However, if I do that I am getting the following exception at startup:

Code: Select all
11-Jul-2023 11:41:24.560 SEVERE [main] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [com.servoy.j2db.server.servlets.WarClientServletContextListener]
        java.lang.RuntimeException: Error starting application server
                at com.servoy.j2db.server.servlets.WarClientServletContextListener.contextInitialized(WarClientServletContextListener.java:82)
                at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4678)
                at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5139)
                at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
                at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
                at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
                at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
                at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
                at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1847)
                at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
                at java.util.concurrent.FutureTask.run(FutureTask.java:266)
                at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
                at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
                at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:772)
                at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:427)
                at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1575)
                at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:309)
                at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
                at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
                at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:366)
                at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:936)
                at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
                at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
                at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
                at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
                at java.util.concurrent.FutureTask.run(FutureTask.java:266)
                at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
                at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
                at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
                at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
                at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
                at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
                at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
                at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
                at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
                at org.apache.catalina.startup.Catalina.start(Catalina.java:633)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:498)
                at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:343)
                at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:474)
        Caused by: javax.servlet.ServletException: Can't start the application server
                at com.servoy.j2db.server.servlets.WarClientServletContextListener.startAppServer(WarClientServletContextListener.java:173)
                at com.servoy.j2db.server.servlets.WarClientServletContextListener.contextInitialized(WarClientServletContextListener.java:32)
                ... 41 more
        Caused by: java.lang.IllegalArgumentException: Extension cannot accept null url
                at com.servoy.j2db.util.JarManager$ExtensionResource.<init>(JarManager.java:156)
                at com.servoy.j2db.server.servlets.WarClientServletContextListener.startAppServer(WarClientServletContextListener.java:246)
                ... 42 more


Not sure what is going wrong? I do see that my own listener gets executed. But perhaps good to mention that we are still using an older version at the moment (2021.12.0.3722).
vincent.schuurhof
 
Posts: 5
Joined: Mon Jul 10, 2023 4:58 pm

Re: Hook into webapp start and stop events

Postby jcompagner » Tue Jul 11, 2023 12:07 pm

do you still mark that "plugin" jar as a servoy plugin?
(which it really is not?)

The only difference you have is that you just move the jar with that context listener from the plugins into WEB-INF/lib right? everything else is the same?
besides that what servoy version are you using? because you don't seem to have this fix: https://support.servoy.com/browse/SVY-16945


But anyway that jar that you have should not be a plugin, marked as a plugin, but just a simple jar that doesn't really know servoy..

It could be that when you move the file the plugin.properties file still says it should be there but you removed it..
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8822
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Hook into webapp start and stop events

Postby vincent.schuurhof » Tue Jul 11, 2023 2:11 pm

I upgraded Servoy to version 2202.3.4.3746, tried it again by moving it into folder "WEB-INF/lib" and it works! I also don't get any exceptions I received previously. So thanks for that!

And I totally agree that this is not a plugin because it is not aware of anything related to Servoy. But how to deal with this when it comes to Servoy Developer? Because I can't seem to find any location other than "plugins" (and perhaps also "beans") where I can put the JAR without losing code completion. And even more important being able to execute the code.

So how should it be working in this environment?
vincent.schuurhof
 
Posts: 5
Joined: Mon Jul 10, 2023 4:58 pm

Re: Hook into webapp start and stop events

Postby jcompagner » Wed Jul 12, 2023 12:41 pm

ServoyCloud can i think add anything you want to it by configuration.

Also what you want is to drop the jar in: application_server\server\webapps\ROOT\WEB-INF\lib\x

we copy that whole ROOT dir into the war, in the same structure.

Its nice that you where already able to use a release so far in the future (2202), so that one is perfect? good to know where we are heading ;)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8822
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet


Return to Servoy Server

Who is online

Users browsing this forum: No registered users and 1 guest