Java Code Examples for javax.servlet.Servlet#destroy()

The following examples show how to use javax.servlet.Servlet#destroy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpServletProtocol.java    From spring-boot-protocol with Apache License 2.0 6 votes vote down vote up
/**
 * Destruction servlet
 */
protected void destroyServlet(){
    Map<String, ServletRegistration> servletRegistrationMap = servletContext.getServletRegistrations();
    for(ServletRegistration registration : servletRegistrationMap.values()){
        Servlet servlet = registration.getServlet();
        if(servlet == null) {
            continue;
        }
        if(registration.isInitServlet()){
            try {
                servlet.destroy();
            }catch (Exception e){
                logger.error("destroyServlet error={},servlet={}",e.toString(),servlet,e);
            }
        }
    }
}
 
Example 2
Source File: ManagedServlet.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public InstanceHandle<? extends Servlet> getServlet() throws ServletException {
    final InstanceHandle<? extends Servlet> instanceHandle;
    final Servlet instance;
    //TODO: pooling
    try {
        instanceHandle = factory.createInstance();
    } catch (Exception e) {
        throw UndertowServletMessages.MESSAGES.couldNotInstantiateComponent(servletInfo.getName(), e);
    }
    instance = instanceHandle.getInstance();
    new LifecyleInterceptorInvocation(servletContext.getDeployment().getDeploymentInfo().getLifecycleInterceptors(), servletInfo, instance, new ServletConfigImpl(servletInfo, servletContext)).proceed();

    return new InstanceHandle<Servlet>() {
        @Override
        public Servlet getInstance() {
            return instance;
        }

        @Override
        public void release() {
            try {
                instance.destroy();
            } catch (Throwable t) {
                UndertowServletLogger.REQUEST_LOGGER.failedToDestroy(instance, t);
            }
            instanceHandle.release();
        }
    };

}
 
Example 3
Source File: ManagedServlet.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public InstanceHandle<? extends Servlet> getServlet() throws ServletException {
    final InstanceHandle<? extends Servlet> instanceHandle;
    final Servlet instance;
    //TODO: pooling
    try {
        instanceHandle = factory.createInstance();
    } catch (Exception e) {
        throw UndertowServletMessages.MESSAGES.couldNotInstantiateComponent(servletInfo.getName(), e);
    }
    instance = instanceHandle.getInstance();
    new LifecyleInterceptorInvocation(servletContext.getDeployment().getDeploymentInfo().getLifecycleInterceptors(), servletInfo, instance, new ServletConfigImpl(servletInfo, servletContext)).proceed();

    return new InstanceHandle<Servlet>() {
        @Override
        public Servlet getInstance() {
            return instance;
        }

        @Override
        public void release() {
            try {
                instance.destroy();
            } catch (Throwable t) {
                UndertowServletLogger.REQUEST_LOGGER.failedToDestroy(instance, t);
            }
            instanceHandle.release();
        }
    };

}
 
Example 4
Source File: WorkbenchServlet.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void destroy() {
	for (Servlet servlet : repositories.values()) {
		servlet.destroy();
	}
	manager.shutDown();
}
 
Example 5
Source File: ServletRegistration.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void destroy()
{
  final Servlet servlet = dispatcher.getServlet();
  final ServletConfig cfg = servlet.getServletConfig();
  final ServletContext context = cfg != null ? cfg.getServletContext() : null;
  servlet.destroy();
  if (context != null) {
    contextManager.ungetServletContext(context);
  }
  registrations.removeServlet(servlet);
}
 
Example 6
Source File: ServletFilter.java    From lemon with Apache License 2.0 5 votes vote down vote up
public void destroy() {
    for (Map.Entry<UrlPatternMatcher, Servlet> entry : servletMap
            .entrySet()) {
        Servlet servlet = entry.getValue();
        servlet.destroy();
    }
}
 
Example 7
Source File: HttpUtil.java    From tomee with Apache License 2.0 5 votes vote down vote up
public static void removeServlet(final String mapping, final WebContext wc) {
    final HttpListenerRegistry registry = SystemInstance.get().getComponent(HttpListenerRegistry.class);
    if (registry == null || mapping == null) {
        return;
    }

    final Servlet servlet = ((ServletListener) registry.removeHttpListener(pattern(wc.getContextRoot(), mapping))).getDelegate();
    servlet.destroy();
    wc.destroy(servlet);
    if (servlet.getClass().equals("org.apache.jasper.servlet.JspServlet")) {
        SystemInstance.get().getComponent(ServletContext.class).removeAttribute("org.apache.tomcat.InstanceManager");
    }
}