/* ------------------------------------------------------------ */ public ServletContextHandler( HandlerContainer parent, String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler, int options) { super((ContextHandler.Context) null); _options = options; _scontext = new Context(); _sessionHandler = sessionHandler; _securityHandler = securityHandler; _servletHandler = servletHandler; _objFactory = new DecoratedObjectFactory(); _objFactory.addDecorator(new DeprecationWarning()); if (contextPath != null) setContextPath(contextPath); if (parent instanceof HandlerWrapper) ((HandlerWrapper) parent).setHandler(this); else if (parent instanceof HandlerCollection) ((HandlerCollection) parent).addHandler(this); // Link the handlers relinkHandlers(); if (errorHandler != null) setErrorHandler(errorHandler); }
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/plain"); resp.setStatus(HttpServletResponse.SC_OK); PrintWriter out = resp.getWriter(); Object obj = req.getServletContext().getAttribute(DecoratedObjectFactory.ATTR); out.printf("Attribute[%s] = %s%n", DecoratedObjectFactory.ATTR, obj.getClass().getName()); if (obj instanceof DecoratedObjectFactory) { out.printf("Object is a DecoratedObjectFactory%n"); DecoratedObjectFactory objFactory = (DecoratedObjectFactory) obj; List<Decorator> decorators = objFactory.getDecorators(); out.printf("Decorators.size = [%d]%n", decorators.size()); for (Decorator decorator : decorators) { out.printf(" decorator[] = %s%n", decorator.getClass().getName()); } } else { out.printf("Object is NOT a DecoratedObjectFactory%n"); } }
@Override public void onWebSocketText(String message) { StringWriter str = new StringWriter(); PrintWriter out = new PrintWriter(str); if (objFactory != null) { out.printf("Object is a DecoratedObjectFactory%n"); List<Decorator> decorators = objFactory.getDecorators(); out.printf("Decorators.size = [%d]%n", decorators.size()); for (Decorator decorator : decorators) { out.printf(" decorator[] = %s%n", decorator.getClass().getName()); } } else { out.printf("DecoratedObjectFactory is NULL%n"); } getRemote().sendStringByFuture(str.toString()); }
/** * Finish constructing handlers and link them together. * * @see org.eclipse.jetty.server.handler.ContextHandler#startContext() */ @Override protected void startContext() throws Exception { ServletContainerInitializerCaller sciBean = getBean(ServletContainerInitializerCaller.class); if (sciBean != null) sciBean.start(); if (_servletHandler != null) { // Call decorators on all holders, and also on any EventListeners before // decorators are called on any other classes (like servlets and filters) if (_servletHandler.getListeners() != null) { for (ListenerHolder holder : _servletHandler.getListeners()) { _objFactory.decorate(holder.getListener()); } } } super.startContext(); // OK to Initialize servlet handler now that all relevant object trees have been started if (_servletHandler != null) _servletHandler.initialize(); }
/* ------------------------------------------------------------ */ void destroyFilter(Filter filter) { _objFactory.destroy(filter); }
/* ------------------------------------------------------------ */ void destroyServlet(Servlet servlet) { _objFactory.destroy(servlet); }
/** * @param decorator The decorator to add * @deprecated use the {@link DecoratedObjectFactory} from * getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") or {@link * #getObjectFactory()} instead */ @Deprecated public void addDecorator(Decorator decorator) { _objFactory.addDecorator(decorator); }
/** * @param decorators The list of {@link Decorator}s * @deprecated use the {@link DecoratedObjectFactory} from * getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") or {@link * #getObjectFactory()} instead */ @Deprecated public void setDecorators(List<Decorator> decorators) { _objFactory.setDecorators(decorators); }
/** @see org.eclipse.jetty.server.handler.ContextHandler#doStop() */ @Override protected void doStop() throws Exception { super.doStop(); _objFactory.clear(); }