diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java index 01f21af9566..7a086939524 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java @@ -758,12 +758,14 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu /* ------------------------------------------------------------ */ protected void callContextInitialized (ServletContextListener l, ServletContextEvent e) { + LOG.debug("contextInitialized: {}->{}",e,l); l.contextInitialized(e); } /* ------------------------------------------------------------ */ protected void callContextDestroyed (ServletContextListener l, ServletContextEvent e) { + LOG.debug("contextDestroyed: {}->{}",e,l); l.contextDestroyed(e); } diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterHolder.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterHolder.java index 6a8d41776b1..bcc3b5c648a 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterHolder.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterHolder.java @@ -114,6 +114,7 @@ public class FilterHolder extends Holder } _config=new Config(); + LOG.debug("Filter.init {}",_filter); _filter.init(_config); } diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java index d5bef18aaf8..538821c1027 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java @@ -367,6 +367,7 @@ public class ServletHolder extends Holder implements UserIdentity.Scope } /* ------------------------------------------------------------ */ + @Override public void destroyInstance (Object o) throws Exception { @@ -510,7 +511,8 @@ public class ServletHolder extends Holder implements UserIdentity.Scope } initMultiPart(); - + + LOG.debug("Filter.init {}",_servlet); _servlet.init(_config); } catch (UnavailableException e) @@ -591,6 +593,7 @@ public class ServletHolder extends Holder implements UserIdentity.Scope /** * @see org.eclipse.jetty.server.UserIdentity.Scope#getContextPath() */ + @Override public String getContextPath() { return _config.getServletContext().getContextPath(); @@ -600,6 +603,7 @@ public class ServletHolder extends Holder implements UserIdentity.Scope /** * @see org.eclipse.jetty.server.UserIdentity.Scope#getRoleRefMap() */ + @Override public Map getRoleRefMap() { return _roleMap; @@ -719,6 +723,7 @@ public class ServletHolder extends Holder implements UserIdentity.Scope protected class Config extends HolderConfig implements ServletConfig { /* -------------------------------------------------------- */ + @Override public String getServletName() { return getName(); @@ -733,6 +738,7 @@ public class ServletHolder extends Holder implements UserIdentity.Scope { protected MultipartConfigElement _multipartConfig; + @Override public Set addMapping(String... urlPatterns) { illegalStateIfContextStarted(); @@ -765,6 +771,7 @@ public class ServletHolder extends Holder implements UserIdentity.Scope return Collections.emptySet(); } + @Override public Collection getMappings() { ServletMapping[] mappings =_servletHandler.getServletMappings(); @@ -839,6 +846,7 @@ public class ServletHolder extends Holder implements UserIdentity.Scope { Stack _stack=new Stack(); + @Override public void destroy() { synchronized(this) @@ -848,16 +856,19 @@ public class ServletHolder extends Holder implements UserIdentity.Scope } } + @Override public ServletConfig getServletConfig() { return _config; } + @Override public String getServletInfo() { return null; } + @Override public void init(ServletConfig config) throws ServletException { synchronized(this) @@ -882,6 +893,7 @@ public class ServletHolder extends Holder implements UserIdentity.Scope } } + @Override public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { Servlet s; diff --git a/test-jetty-webapp/src/main/java/com/acme/TestFilter.java b/test-jetty-webapp/src/main/java/com/acme/TestFilter.java index 5f07dee404b..7045c6c3adb 100644 --- a/test-jetty-webapp/src/main/java/com/acme/TestFilter.java +++ b/test-jetty-webapp/src/main/java/com/acme/TestFilter.java @@ -56,6 +56,7 @@ public class TestFilter implements Filter /* * @see javax.servlet.Filter#init(javax.servlet.FilterConfig) */ + @Override public void init(FilterConfig filterConfig) throws ServletException { _context= filterConfig.getServletContext(); @@ -70,6 +71,7 @@ public class TestFilter implements Filter /* * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) */ + @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { @@ -121,6 +123,7 @@ public class TestFilter implements Filter /* * @see javax.servlet.Filter#destroy() */ + @Override public void destroy() { } diff --git a/test-jetty-webapp/src/main/java/com/acme/TestListener.java b/test-jetty-webapp/src/main/java/com/acme/TestListener.java index 79767d27b04..a63abaf2a09 100644 --- a/test-jetty-webapp/src/main/java/com/acme/TestListener.java +++ b/test-jetty-webapp/src/main/java/com/acme/TestListener.java @@ -18,6 +18,8 @@ package com.acme; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; import javax.servlet.DispatcherType; import javax.servlet.ServletContextAttributeEvent; import javax.servlet.ServletContextAttributeListener; @@ -40,96 +42,131 @@ import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener; import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; import java.util.Set; public class TestListener implements HttpSessionListener, HttpSessionAttributeListener, HttpSessionActivationListener, ServletContextListener, ServletContextAttributeListener, ServletRequestListener, ServletRequestAttributeListener { + Map _called=new HashMap<>(); + + public TestListener() + { + _called.put("TestListener",new Throwable()); + } + + @PostConstruct + public void postConstruct() + { + _called.put("postConstruct",new Throwable()); + } + + @PreDestroy + public void preDestroy() + { + _called.put("preDestroy",new Throwable()); + } + @Override public void attributeAdded(HttpSessionBindingEvent se) { // System.err.println("attributedAdded "+se); + + _called.put("attributeAdded",new Throwable()); } @Override public void attributeRemoved(HttpSessionBindingEvent se) { // System.err.println("attributeRemoved "+se); + _called.put("attributeRemoved",new Throwable()); } @Override public void attributeReplaced(HttpSessionBindingEvent se) { // System.err.println("attributeReplaced "+se); + _called.put("attributeReplaced",new Throwable()); } @Override public void sessionWillPassivate(HttpSessionEvent se) { // System.err.println("sessionWillPassivate "+se); + _called.put("sessionWillPassivate",new Throwable()); } @Override public void sessionDidActivate(HttpSessionEvent se) { // System.err.println("sessionDidActivate "+se); + _called.put("sessionDidActivate",new Throwable()); } @Override public void contextInitialized(ServletContextEvent sce) { + // System.err.println("contextInitialized "+sce); + _called.put("contextInitialized",new Throwable()); + //configure programmatic security ServletRegistration.Dynamic rego = sce.getServletContext().addServlet("RegoTest", RegTest.class.getName()); rego.addMapping("/rego/*"); HttpConstraintElement constraintElement = new HttpConstraintElement(ServletSecurity.EmptyRoleSemantic.PERMIT, - ServletSecurity.TransportGuarantee.NONE, new String[]{"admin"}); + ServletSecurity.TransportGuarantee.NONE, new String[]{"admin"}); ServletSecurityElement securityElement = new ServletSecurityElement(constraintElement, null); Set unchanged = rego.setServletSecurity(securityElement); - //System.err.println("Security constraints registered: "+unchanged.isEmpty()); + //// System.err.println("Security constraints registered: "+unchanged.isEmpty()); //Test that a security constraint from web.xml can't be overridden programmatically ServletRegistration.Dynamic rego2 = sce.getServletContext().addServlet("RegoTest2", RegTest.class.getName()); rego2.addMapping("/rego2/*"); securityElement = new ServletSecurityElement(constraintElement, null); unchanged = rego2.setServletSecurity(securityElement); - //System.err.println("Overridding web.xml constraints not possible:" +!unchanged.isEmpty()); + //// System.err.println("Overridding web.xml constraints not possible:" +!unchanged.isEmpty()); - /* For servlet 3.0 */ - FilterRegistration.Dynamic registration = sce.getServletContext().addFilter("TestFilter",TestFilter.class.getName()); - registration.setInitParameter("remote", "false"); - registration.setAsyncSupported(true); - registration.addMappingForUrlPatterns( - EnumSet.of(DispatcherType.ERROR,DispatcherType.ASYNC,DispatcherType.FORWARD,DispatcherType.INCLUDE,DispatcherType.REQUEST), - true, - new String[]{"/*"}); + /* For servlet 3.0 */ + FilterRegistration.Dynamic registration = sce.getServletContext().addFilter("TestFilter",TestFilter.class.getName()); + registration.setInitParameter("remote", "false"); + registration.setAsyncSupported(true); + registration.addMappingForUrlPatterns( + EnumSet.of(DispatcherType.ERROR,DispatcherType.ASYNC,DispatcherType.FORWARD,DispatcherType.INCLUDE,DispatcherType.REQUEST), + true, + new String[]{"/*"}); } @Override public void contextDestroyed(ServletContextEvent sce) { + _called.put("contextDestroyed",new Throwable()); // System.err.println("contextDestroyed "+sce); } @Override public void attributeAdded(ServletContextAttributeEvent scab) { + _called.put("attributeAdded",new Throwable()); // System.err.println("attributeAdded "+scab); } @Override public void attributeRemoved(ServletContextAttributeEvent scab) { + _called.put("attributeRemoved",new Throwable()); // System.err.println("attributeRemoved "+scab); } @Override public void attributeReplaced(ServletContextAttributeEvent scab) { + _called.put("attributeReplaced",new Throwable()); // System.err.println("attributeReplaced "+scab); } @Override public void requestDestroyed(ServletRequestEvent sre) { + _called.put("requestDestroyed",new Throwable()); ((HttpServletRequest)sre.getServletRequest()).getSession(false); sre.getServletRequest().setAttribute("requestInitialized",null); // System.err.println("requestDestroyed "+sre); @@ -138,6 +175,7 @@ public class TestListener implements HttpSessionListener, HttpSessionAttributeL @Override public void requestInitialized(ServletRequestEvent sre) { + _called.put("requestInitialized",new Throwable()); sre.getServletRequest().setAttribute("requestInitialized","'"+sre.getServletContext().getContextPath()+"'"); // System.err.println("requestInitialized "+sre); } @@ -145,30 +183,35 @@ public class TestListener implements HttpSessionListener, HttpSessionAttributeL @Override public void attributeAdded(ServletRequestAttributeEvent srae) { + _called.put("attributeAdded",new Throwable()); // System.err.println("attributeAdded "+srae); } @Override public void attributeRemoved(ServletRequestAttributeEvent srae) { + _called.put("attributeRemoved",new Throwable()); // System.err.println("attributeRemoved "+srae); } @Override public void attributeReplaced(ServletRequestAttributeEvent srae) { + _called.put("attributeReplaced",new Throwable()); // System.err.println("attributeReplaced "+srae); } @Override public void sessionCreated(HttpSessionEvent se) { + _called.put("sessionCreated",new Throwable()); // System.err.println("sessionCreated "+se); } @Override public void sessionDestroyed(HttpSessionEvent se) { + _called.put("sessionDestroyed",new Throwable()); // System.err.println("sessionDestroyed "+se); }