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);
}
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));
}
}
}
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");
}
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());
}
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);
}
Aggregations