org.eclipse.jetty.servlet.Source Java Examples

The following examples show how to use org.eclipse.jetty.servlet.Source. 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: JettyTransport.java    From data-transfer-project with Apache License 2.0 5 votes vote down vote up
public void registerServlet(String path, Servlet servletContainer) {
  ServletHolder servletHolder = new ServletHolder(Source.EMBEDDED);
  servletHolder.setName("Data Transfer Project");
  servletHolder.setServlet(servletContainer);
  servletHolder.setInitOrder(1);

  ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
  handler.setContextPath("/");

  handlers.add(handler);

  handler.getServletHandler().addServletWithMapping(servletHolder, path);
}
 
Example #2
Source File: ServletHolderMapper.java    From hammock with Apache License 2.0 5 votes vote down vote up
@Override
public ServletHolder apply(ServletDescriptor servletDescriptor) {
    ServletHolder servletHolder = servletHandler.newServletHolder(Source.EMBEDDED);
    servletHolder.setHeldClass(servletDescriptor.servletClass());
    servletHolder.setName(servletDescriptor.name());
    if(servletDescriptor.initParams() != null) {
        Arrays.stream(servletDescriptor.initParams())
                .forEach(p -> servletHolder.setInitParameter(p.name(), p.value()));
    }
    for(String pattern : servletDescriptor.urlPatterns()) {
        servletHandler.addServletWithMapping(servletHolder, pattern);
    }
    return servletHolder;
}
 
Example #3
Source File: ServletHolderMapperTest.java    From hammock with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCreateServletHolder() {
    when(servletHandler.newServletHolder(Source.EMBEDDED)).thenReturn(new ServletHolder(Source.EMBEDDED));
    ServletDescriptor servletDescriptor = new ServletDescriptor("name", new String[]{"uri"}, new String[]{"uri"},
            1,null,true, DefaultServlet.class);
    ServletHolder holder = mapper.apply(servletDescriptor);
    assertThat(holder.getName()).isEqualTo("name");
    assertThat(holder.getClassName()).isEqualTo(DefaultServlet.class.getName());
    verify(servletHandler).addServletWithMapping(holder, "uri");
}
 
Example #4
Source File: ServletHolderMapperTest.java    From hammock with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCreateServletHolderWithParams() {
    when(servletHandler.newServletHolder(Source.EMBEDDED)).thenReturn(new ServletHolder(Source.EMBEDDED));
    ServletDescriptor servletDescriptor = new ServletDescriptor("name", new String[]{"uri"}, new String[]{"uri"},
            1,new WebInitParam[]{new WebParam("key","value")},true, DefaultServlet.class);
    ServletHolder holder = mapper.apply(servletDescriptor);
    assertThat(holder.getInitParameters()).isEqualTo(singletonMap("key","value"));
}