-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LifeCycle.Listener not called for Filter/Servlet/Listener lifecycle events #5020
Comments
I would like to see a more detailed servlet component API for monitoring flows and timings. Something that would report ...
Currently this is really only possible by extending ...
|
@joakime I don't understand the problem. It is perfectly possible to add LifeCycle.Listeners for Servlets, Filters etc :
|
@janbartel the point of the issue is that this functionality is now broken for things that result in a BaseHolder. Example for Filter. package jetty;
import java.io.IOException;
import java.util.EnumSet;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
public class FilterLifeCycleListenerDemo
{
public static void main(String[] args) throws Exception
{
Server server = new Server(8080);
ServletContextHandler contextHandler = new ServletContextHandler();
contextHandler.addLifeCycleListener(new MyListener());
contextHandler.setContextPath("/");
contextHandler.addFilter(MyFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
contextHandler.addServlet(DefaultServlet.class, "/");
server.setHandler(contextHandler);
server.start();
server.join();
}
public static class MyListener implements LifeCycle.Listener
{
private static final Logger LOG = Log.getLogger(MyListener.class);
@Override
public void lifeCycleStarting(LifeCycle event)
{
LOG.info("STARTING {}", event);
}
@Override
public void lifeCycleStarted(LifeCycle event)
{
LOG.info("STARTED {}", event);
}
@Override
public void lifeCycleFailure(LifeCycle event, Throwable cause)
{
LOG.info("FAILURE {}", event, cause);
}
@Override
public void lifeCycleStopping(LifeCycle event)
{
LOG.info("STOPPING {}", event);
}
@Override
public void lifeCycleStopped(LifeCycle event)
{
LOG.info("STOPPED {}", event);
}
}
public static class MyFilter implements Filter
{
@Override
public void init(FilterConfig filterConfig)
{
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
chain.doFilter(request, response);
}
@Override
public void destroy()
{
}
}
} Results in output ...
I'm reasonably sure (not 100%) that in the past the LifeCycle.Listener on the ServletContextHandler would notify for events on Filter/Servlet/Listener and allow a single place to pay attention to all lifecycle events on that context, even if your embedded-jetty code wasn't the one adding/registering the the Filter or Servlet (from dynamic registration or annotations for example). With this behavior change and with the recent change in Decorator (see issue #5021) libraries like Guice no longer have visibility to all of the servlet components (like they used to). |
@joakime I don't see how that example would ever have worked because the What we do have is So now, we don't add the holders as beans, so nobody sees an Hmmm this also probably means that we can't have JMX beans for our holders either!!!! who made that silly change.... oh it was me :( So it would be good to have the holders as managed beans again.... but we have to work out why the change was made? Was it only to get the nice formatting on the dump? or was there another reason due to their complex lifecycles? So I think we should definitely make the Holder beans again and I note the start protection is still in |
I too feel that the current dump format for ServletContextHandler is superior to the old one. I'm good with this being the way it should be, and will shift my efforts to something that doesn't rely on The last commit I can find where Holder's were Managed Beans is ... This commit removed them as beans ... |
Signed-off-by: Jan Bartel <janb@webtide.com>
Signed-off-by: Jan Bartel <janb@webtide.com>
Signed-off-by: Jan Bartel <janb@webtide.com>
Signed-off-by: Jan Bartel <janb@webtide.com>
Merged. |
Jetty version
9.4.30
Description
The change to using BaseHolder and manually starting / stopping / destroying means that we no longer get LifeCycle.Listener events for the start/stop of the Filter/Servlet/Listeners on Jetty.
Example:
https://github.com/eclipse/jetty.project/blob/ae43b70a9f8907b8a2444f051bebab60f4a9162c/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java#L742-L757
The text was updated successfully, but these errors were encountered: