Search in sources :

Example 51 with Servlet

use of javax.servlet.Servlet in project dropwizard by dropwizard.

the class ServletEnvironmentTest method addsServletInstances.

@Test
public void addsServletInstances() throws Exception {
    final Servlet servlet = mock(Servlet.class);
    final ServletRegistration.Dynamic builder = environment.addServlet("servlet", servlet);
    assertThat(builder).isNotNull();
    final ArgumentCaptor<ServletHolder> holder = ArgumentCaptor.forClass(ServletHolder.class);
    verify(servletHandler).addServlet(holder.capture());
    assertThat(holder.getValue().getName()).isEqualTo("servlet");
    assertThat(holder.getValue().getServlet()).isEqualTo(servlet);
}
Also used : ServletRegistration(javax.servlet.ServletRegistration) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) Servlet(javax.servlet.Servlet) GenericServlet(javax.servlet.GenericServlet) Test(org.junit.Test)

Example 52 with Servlet

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

the class MultiPartConfigAnnotationHandler method doHandle.

/** 
     * @see org.eclipse.jetty.annotations.AnnotationIntrospector.AbstractIntrospectableAnnotationHandler#doHandle(java.lang.Class)
     */
public void doHandle(Class clazz) {
    if (!Servlet.class.isAssignableFrom(clazz))
        return;
    MultipartConfig multi = (MultipartConfig) clazz.getAnnotation(MultipartConfig.class);
    if (multi == null)
        return;
    MetaData metaData = _context.getMetaData();
    //TODO: The MultipartConfigElement needs to be set on the ServletHolder's Registration.
    //How to identify the correct Servlet?  If the Servlet has no WebServlet annotation on it, does it mean that this MultipartConfig
    //annotation applies to all declared instances in web.xml/programmatically?
    //Assuming TRUE for now.
    ServletHolder holder = getServletHolderForClass(clazz);
    if (holder != null) {
        Descriptor d = metaData.getOriginDescriptor(holder.getName() + ".servlet.multipart-config");
        //let the annotation override it
        if (d == null) {
            metaData.setOrigin(holder.getName() + ".servlet.multipart-config", multi, clazz);
            holder.getRegistration().setMultipartConfig(new MultipartConfigElement(multi));
        }
    }
}
Also used : MultipartConfigElement(javax.servlet.MultipartConfigElement) MultipartConfig(javax.servlet.annotation.MultipartConfig) MetaData(org.eclipse.jetty.webapp.MetaData) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) Servlet(javax.servlet.Servlet) Descriptor(org.eclipse.jetty.webapp.Descriptor)

Example 53 with Servlet

use of javax.servlet.Servlet in project hudson-2.x by hudson.

the class ServletRegistrationFilterAdapter method createServlet.

private Servlet createServlet() throws Exception {
    Servlet servlet = registration.getServlet();
    if (servlet != null) {
        return servlet;
    }
    Class<? extends Servlet> type = registration.getServletType();
    if (type != null) {
        return type.newInstance();
    }
    throw new IllegalArgumentException("Registration missing servlet or servlet type");
}
Also used : Servlet(javax.servlet.Servlet)

Example 54 with Servlet

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

the class DispatcherServletTests method servletHandlerAdapter.

@Test
public void servletHandlerAdapter() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/servlet.do");
    MockHttpServletResponse response = new MockHttpServletResponse();
    complexDispatcherServlet.service(request, response);
    assertEquals("body", response.getContentAsString());
    Servlet myServlet = (Servlet) complexDispatcherServlet.getWebApplicationContext().getBean("myServlet");
    assertEquals("complex", myServlet.getServletConfig().getServletName());
    assertEquals(getServletContext(), myServlet.getServletConfig().getServletContext());
    complexDispatcherServlet.destroy();
    assertNull(myServlet.getServletConfig());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Servlet(javax.servlet.Servlet) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 55 with Servlet

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

the class AnnotationConfigServletWebServerApplicationContextTests 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) MockServlet(org.springframework.boot.testutil.MockServlet) GenericServlet(javax.servlet.GenericServlet)

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