Example usage for javax.servlet Servlet destroy

List of usage examples for javax.servlet Servlet destroy

Introduction

In this page you can find the example usage for javax.servlet Servlet destroy.

Prototype


public void destroy();

Source Link

Document

Called by the servlet container to indicate to a servlet that the servlet is being taken out of service.

Usage

From source file:net.lightbody.bmp.proxy.jetty.jetty.servlet.ServletHolder.java

public void stop() {
    Principal user = null;//from  ww w. j ava 2s  .  c  om
    try {
        // Handle run as
        if (_runAs != null && _realm != null)
            user = _realm.pushRole(null, _runAs);

        if (_servlet != null)
            _servlet.destroy();
        _servlet = null;

        while (_servlets != null && _servlets.size() > 0) {
            Servlet s = (Servlet) _servlets.pop();
            s.destroy();
        }
        _config = null;
    } finally {
        super.stop();
        // pop run-as role
        if (_runAs != null && _realm != null && user != null)
            _realm.popRole(user);
    }
}

From source file:org.ops4j.pax.web.service.internal.FilterTest.java

@Test
public void filterIsCalledOnUrlPattern() throws NamespaceException, ServletException, IOException {
    Servlet servlet = createMock(Servlet.class);
    servlet.init((ServletConfig) notNull());
    servlet.destroy();

    Filter filter = createMock(Filter.class);
    filter.init((FilterConfig) notNull());
    filter.doFilter((ServletRequest) notNull(), (ServletResponse) notNull(), (FilterChain) notNull());
    filter.destroy();/*from  w  w  w.  j  ava2  s  .c om*/

    replay(servlet, filter);

    HttpContext context = m_httpService.createDefaultHttpContext();
    m_httpService.registerServlet("/test", servlet, null, context);
    m_httpService.registerFilter(filter, new String[] { "/*" }, null, context);

    HttpMethod method = new GetMethod("http://localhost:8080/test");
    m_client.executeMethod(method);
    method.releaseConnection();

    m_httpService.unregister("/test");
    m_httpService.unregisterFilter(filter);

    verify(servlet, filter);
}

From source file:org.ops4j.pax.web.service.internal.FilterTest.java

@Test
public void filterIsCalledOnServlet() throws NamespaceException, ServletException, IOException {
    Servlet servlet = createMock(Servlet.class);
    servlet.init((ServletConfig) notNull());
    servlet.destroy();

    Filter filter = createMock(Filter.class);
    filter.init((FilterConfig) notNull());
    filter.doFilter((ServletRequest) notNull(), (ServletResponse) notNull(), (FilterChain) notNull());
    filter.destroy();/*from   w  w  w.j  av a 2s  .c om*/

    replay(servlet, filter);

    HttpContext context = m_httpService.createDefaultHttpContext();
    m_httpService.registerServlet("/test", servlet, null, context);
    m_httpService.registerFilter(filter, null, new String[] { "/test" }, context);

    HttpMethod method = new GetMethod("http://localhost:8080/test");
    m_client.executeMethod(method);
    method.releaseConnection();

    m_httpService.unregister("/test");
    m_httpService.unregisterFilter(filter);

    verify(servlet, filter);
}