Search in sources :

Example 11 with Servlet

use of javax.servlet.Servlet in project jetty.project by eclipse.

the class ServletHolder method destroyInstance.

/* ------------------------------------------------------------ */
@Override
public void destroyInstance(Object o) throws Exception {
    if (o == null)
        return;
    Servlet servlet = ((Servlet) o);
    getServletHandler().destroyServlet(servlet);
    servlet.destroy();
}
Also used : Servlet(javax.servlet.Servlet)

Example 12 with Servlet

use of javax.servlet.Servlet in project jetty.project by eclipse.

the class ServletHolder method handle.

/* ------------------------------------------------------------ */
/**
     * Service a request with this servlet.
     *
     * @param baseRequest the base request
     * @param request the request
     * @param response the response
     * @throws ServletException if unable to process the servlet
     * @throws UnavailableException if servlet is unavailable
     * @throws IOException if unable to process the request or response
     */
public void handle(Request baseRequest, ServletRequest request, ServletResponse response) throws ServletException, UnavailableException, IOException {
    if (_class == null)
        throw new UnavailableException("Servlet Not Initialized");
    Servlet servlet = ensureInstance();
    // Service the request
    Object old_run_as = null;
    boolean suspendable = baseRequest.isAsyncSupported();
    try {
        // Handle aliased path
        if (_forcedPath != null)
            adaptForcedPathToJspContainer(request);
        // Handle run as
        if (_identityService != null)
            old_run_as = _identityService.setRunAs(baseRequest.getResolvedUserIdentity(), _runAsToken);
        if (baseRequest.isAsyncSupported() && !isAsyncSupported()) {
            try {
                baseRequest.setAsyncSupported(false, this.toString());
                servlet.service(request, response);
            } finally {
                baseRequest.setAsyncSupported(true, null);
            }
        } else
            servlet.service(request, response);
    } catch (UnavailableException e) {
        makeUnavailable(e);
        throw _unavailableEx;
    } finally {
        // Pop run-as role.
        if (_identityService != null)
            _identityService.unsetRunAs(old_run_as);
    }
}
Also used : UnavailableException(javax.servlet.UnavailableException) Servlet(javax.servlet.Servlet) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject)

Example 13 with Servlet

use of javax.servlet.Servlet in project qi4j-sdk by Qi4j.

the class JettyConfigurationHelper method addServlets.

static void addServlets(ServletContextHandler root, Iterable<ServiceReference<Servlet>> servlets) {
    // Iterate the available servlets and add it to the server
    for (ServiceReference<Servlet> servlet : servlets) {
        ServletInfo servletInfo = servlet.metaInfo(ServletInfo.class);
        String servletPath = servletInfo.getPath();
        Servlet servletInstance = servlet.get();
        ServletHolder holder = new ServletHolder(servletInstance);
        holder.setInitParameters(servletInfo.initParams());
        root.addServlet(holder, servletPath);
    }
}
Also used : ServletHolder(org.eclipse.jetty.servlet.ServletHolder) Servlet(javax.servlet.Servlet) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet)

Example 14 with Servlet

use of javax.servlet.Servlet in project spring-boot by spring-projects.

the class XmlServletWebServerApplicationContextTests method verifyContext.

private void verifyContext() {
    MockServletWebServerFactory factory = this.context.getBean(MockServletWebServerFactory.class);
    Servlet servlet = this.context.getBean(Servlet.class);
    verify(factory.getServletContext()).addServlet("servlet", servlet);
}
Also used : MockServletWebServerFactory(org.springframework.boot.web.servlet.server.MockServletWebServerFactory) Servlet(javax.servlet.Servlet)

Example 15 with Servlet

use of javax.servlet.Servlet in project spring-boot by spring-projects.

the class AnnotationConfigServletWebServerApplicationContextTests method sessionScopeAvailableToServlet.

@Test
public void sessionScopeAvailableToServlet() throws Exception {
    this.context = new AnnotationConfigServletWebServerApplicationContext(ExampleServletWebServerApplicationConfiguration.class, ExampleServletWithAutowired.class, SessionScopedComponent.class);
    Servlet servlet = this.context.getBean(ExampleServletWithAutowired.class);
    assertThat(servlet).isNotNull();
}
Also used : ExampleServletWebServerApplicationConfiguration(org.springframework.boot.web.servlet.context.config.ExampleServletWebServerApplicationConfiguration) Servlet(javax.servlet.Servlet) MockServlet(org.springframework.boot.testutil.MockServlet) GenericServlet(javax.servlet.GenericServlet) Test(org.junit.Test)

Aggregations

Servlet (javax.servlet.Servlet)86 Test (org.junit.Test)18 HttpServlet (javax.servlet.http.HttpServlet)16 ServletException (javax.servlet.ServletException)15 IOException (java.io.IOException)11 OptingServlet (org.apache.sling.api.servlets.OptingServlet)11 GenericServlet (javax.servlet.GenericServlet)10 DefaultErrorHandlerServlet (org.apache.sling.servlets.resolver.internal.defaults.DefaultErrorHandlerServlet)9 DefaultServlet (org.apache.sling.servlets.resolver.internal.defaults.DefaultServlet)9 ServletContext (javax.servlet.ServletContext)8 UnavailableException (javax.servlet.UnavailableException)8 Resource (org.apache.sling.api.resource.Resource)8 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)8 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)7 MockServletWebServerFactory (org.springframework.boot.web.servlet.server.MockServletWebServerFactory)7 ServletInfo (io.undertow.servlet.api.ServletInfo)6 ArrayList (java.util.ArrayList)5 Filter (javax.servlet.Filter)5 Context (org.apache.catalina.Context)5 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)5