Java Code Examples for org.eclipse.jetty.servlet.ServletContextHandler#setHandler()

The following examples show how to use org.eclipse.jetty.servlet.ServletContextHandler#setHandler() . 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: JettyAppServer.java    From selenium with Apache License 2.0 6 votes vote down vote up
protected ServletContextHandler addResourceHandler(String contextPath, Path resourceBase) {
  ServletContextHandler context = new ServletContextHandler();

  ResourceHandler staticResource = new ResourceHandler();
  staticResource.setDirectoriesListed(true);
  staticResource.setWelcomeFiles(new String[] { "index.html" });
  staticResource.setResourceBase(resourceBase.toAbsolutePath().toString());
  MimeTypes mimeTypes = new MimeTypes();
  mimeTypes.addMimeMapping("appcache", "text/cache-manifest");
  staticResource.setMimeTypes(mimeTypes);

  context.setContextPath(contextPath);
  context.setAliasChecks(Arrays.asList(new ApproveAliases(), new AllowSymLinkAliasChecker()));

  HandlerList allHandlers = new HandlerList();
  allHandlers.addHandler(staticResource);
  allHandlers.addHandler(context.getHandler());
  context.setHandler(allHandlers);

  handlers.addHandler(context);

  return context;
}
 
Example 2
Source File: TestServerUtil.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private static ServletContextHandler getServletContextHandler(AnnotationConfigWebApplicationContext context) throws IOException {
  ServletContextHandler contextHandler = new ServletContextHandler();
  WebConfigurer configurer = new WebConfigurer();
  configurer.setContext(context);
  contextHandler.addEventListener(configurer);

  // Create the SessionHandler (wrapper) to handle the sessions
  HashSessionManager manager = new HashSessionManager();
  SessionHandler sessions = new SessionHandler(manager);
  contextHandler.setHandler(sessions);

  return contextHandler;
}
 
Example 3
Source File: BaseJPARestTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private static ServletContextHandler getServletContextHandler(AnnotationConfigWebApplicationContext context) throws IOException {
  ServletContextHandler contextHandler = new ServletContextHandler();
  JPAWebConfigurer configurer = new JPAWebConfigurer();
  configurer.setContext(context);
  contextHandler.addEventListener(configurer);

  // Create the SessionHandler (wrapper) to handle the sessions
  HashSessionManager manager = new HashSessionManager();
  SessionHandler sessions = new SessionHandler(manager);
  contextHandler.setHandler(sessions);

  return contextHandler;
}
 
Example 4
Source File: TestServerUtil.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private static ServletContextHandler getServletContextHandler(AnnotationConfigWebApplicationContext context) throws IOException {
  ServletContextHandler contextHandler = new ServletContextHandler();
  WebConfigurer configurer = new WebConfigurer();
  configurer.setContext(context);
  contextHandler.addEventListener(configurer);
  
  // Create the SessionHandler (wrapper) to handle the sessions
  HashSessionManager manager = new HashSessionManager();
  SessionHandler sessions = new SessionHandler(manager);
  contextHandler.setHandler(sessions);
  
  return contextHandler;
}
 
Example 5
Source File: TestHttpTask.java    From conductor with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void init() throws Exception {
    Map<String, Object> map = new HashMap<>();
    map.put("key", "value1");
    map.put("num", 42);
    map.put("SomeKey", null);
    JSON_RESPONSE = objectMapper.writeValueAsString(map);

    server = new Server(7009);
    ServletContextHandler servletContextHandler = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
    servletContextHandler.setHandler(new EchoHandler());
    server.start();
}
 
Example 6
Source File: TestServerUtil.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private static ServletContextHandler getServletContextHandler(AnnotationConfigWebApplicationContext context) throws IOException {
    ServletContextHandler contextHandler = new ServletContextHandler();
    WebConfigurer configurer = new WebConfigurer();
    configurer.setContext(context);
    contextHandler.addEventListener(configurer);

    // Create the SessionHandler (wrapper) to handle the sessions
    HashSessionManager manager = new HashSessionManager();
    SessionHandler sessions = new SessionHandler(manager);
    contextHandler.setHandler(sessions);

    return contextHandler;
}
 
Example 7
Source File: TestServerUtil.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private static ServletContextHandler getServletContextHandler(AnnotationConfigWebApplicationContext context) throws IOException {
    ServletContextHandler contextHandler = new ServletContextHandler();
    WebConfigurer configurer = new WebConfigurer();
    configurer.setContext(context);
    contextHandler.addEventListener(configurer);

    // Create the SessionHandler (wrapper) to handle the sessions
    HashSessionManager manager = new HashSessionManager();
    SessionHandler sessions = new SessionHandler(manager);
    contextHandler.setHandler(sessions);

    return contextHandler;
}
 
Example 8
Source File: TestServerUtil.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private static ServletContextHandler getServletContextHandler(AnnotationConfigWebApplicationContext context) throws IOException {
    ServletContextHandler contextHandler = new ServletContextHandler();
    WebConfigurer configurer = new WebConfigurer();
    configurer.setContext(context);
    contextHandler.addEventListener(configurer);

    // Create the SessionHandler (wrapper) to handle the sessions
    HashSessionManager manager = new HashSessionManager();
    SessionHandler sessions = new SessionHandler(manager);
    contextHandler.setHandler(sessions);

    return contextHandler;
}
 
Example 9
Source File: TestServerUtil.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private static ServletContextHandler getServletContextHandler(AnnotationConfigWebApplicationContext context) throws IOException {
    ServletContextHandler contextHandler = new ServletContextHandler();
    WebConfigurer configurer = new WebConfigurer();
    configurer.setContext(context);
    contextHandler.addEventListener(configurer);

    // Create the SessionHandler (wrapper) to handle the sessions
    HashSessionManager manager = new HashSessionManager();
    SessionHandler sessions = new SessionHandler(manager);
    contextHandler.setHandler(sessions);

    return contextHandler;
}
 
Example 10
Source File: TestServerUtil.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private static ServletContextHandler getServletContextHandler(AnnotationConfigWebApplicationContext context) throws IOException {
    ServletContextHandler contextHandler = new ServletContextHandler();
    WebConfigurer configurer = new WebConfigurer();
    configurer.setContext(context);
    contextHandler.addEventListener(configurer);

    // Create the SessionHandler (wrapper) to handle the sessions
    HashSessionManager manager = new HashSessionManager();
    SessionHandler sessions = new SessionHandler(manager);
    contextHandler.setHandler(sessions);

    return contextHandler;
}
 
Example 11
Source File: TestServerUtil.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private static ServletContextHandler getServletContextHandler(AnnotationConfigWebApplicationContext context) throws IOException {
    ServletContextHandler contextHandler = new ServletContextHandler();
    WebConfigurer configurer = new WebConfigurer();
    configurer.setContext(context);
    contextHandler.addEventListener(configurer);

    // Create the SessionHandler (wrapper) to handle the sessions
    HashSessionManager manager = new HashSessionManager();
    SessionHandler sessions = new SessionHandler(manager);
    contextHandler.setHandler(sessions);

    return contextHandler;
}
 
Example 12
Source File: AtlasAPIV2ServerEmulator.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void createServer() throws Exception {
    server = new Server();
    final ContextHandlerCollection handlerCollection = new ContextHandlerCollection();

    final ServletContextHandler staticContext = new ServletContextHandler();
    staticContext.setContextPath("/");

    final ServletContextHandler atlasApiV2Context = new ServletContextHandler();
    atlasApiV2Context.setContextPath("/api/atlas/v2/");

    handlerCollection.setHandlers(new Handler[]{staticContext, atlasApiV2Context});

    server.setHandler(handlerCollection);

    final ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setBaseResource(Resource.newClassPathResource("public", false, false));
    staticContext.setHandler(resourceHandler);

    final ServletHandler servletHandler = new ServletHandler();
    atlasApiV2Context.insertHandler(servletHandler);

    httpConnector = new ServerConnector(server);
    httpConnector.setPort(21000);

    server.setConnectors(new Connector[]{httpConnector});

    servletHandler.addServletWithMapping(TypeDefsServlet.class, "/types/typedefs/");
    servletHandler.addServletWithMapping(EntityBulkServlet.class, "/entity/bulk/");
    servletHandler.addServletWithMapping(EntityGuidServlet.class, "/entity/guid/*");
    servletHandler.addServletWithMapping(SearchByUniqueAttributeServlet.class, "/entity/uniqueAttribute/type/*");
    servletHandler.addServletWithMapping(SearchBasicServlet.class, "/search/basic/");
    servletHandler.addServletWithMapping(LineageServlet.class, "/debug/lineage/");

    notificationServerEmulator = new AtlasNotificationServerEmulator();
}
 
Example 13
Source File: DataServer.java    From dawnsci with Eclipse Public License 1.0 4 votes vote down vote up
public void start(boolean block) throws Exception {
	
	this.server = new Server();
	ServerConnector connector = new ServerConnector(server);
	connector.setPort(getPort());
	connector.setReuseAddress(true);
	server.addConnector(connector);   
	
	// We enable sessions on the server so that 
	// we can cache LoaderFactories to a given session.
	// The loader factory therefore needs a non-global 
	// data soft reference cache.
	ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
	context.setContextPath("/");
	server.setHandler(context);
     
       // Make individual servlets
       // Slicing (large data in binary http)
	ServletHolder holderSlice = new ServletHolder("slice", SliceServlet.class);
	context.addServlet(holderSlice, "/slice/*");
	
	// Doing events, like data changing shape.
	// FIXME Should not be needed
	WebSocketHandler wsHandler = new WebSocketHandler() {
		@Override
		public void configure(WebSocketServletFactory factory) {
			factory.register(FileMonitorSocket.class);
		}
	};
	context.setHandler(wsHandler);
	// FIXME End should not be needed.		
	
	ServletHolder holderInfo = new ServletHolder("info", InfoServlet.class);
	context.addServlet(holderInfo, "/info/*");
	
	ServletHolder holderTree = new ServletHolder("tree", TreeServlet.class);
	context.addServlet(holderTree, "/tree/*");

    
	// Events json objects to notify of problems.
	ServletHolder holderEvent = new ServletHolder("event", EventServlet.class);
	context.addServlet(holderEvent, "/event/*");
	
    server.start();
    if (block) server.join();

}
 
Example 14
Source File: WebDAVServer.java    From MtgDesktopCompanion with GNU General Public License v3.0 3 votes vote down vote up
@Override
public void start() throws IOException {
	server = new Server(getInt(SERVER_PORT));
	
	
	log = getString(LOGIN);
	pas = getString(PASS);
	
	
	ServletContextHandler ctx = new ServletContextHandler(ServletContextHandler.SESSIONS);
	ctx.setContextPath("/");
	
	ServletHandler handler = new ServletHandler();
	
	ctx.addServlet(new ServletHolder("default", new MiltonServlet()),"/");
	
	
	FilterHolder fh = handler.addFilterWithMapping(MiltonFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
				 fh.setInitParameter("resource.factory.class", WebDavMTGResourceFactory.class.getCanonicalName());
				 

	ctx.addFilter(fh, "/*", EnumSet.of(DispatcherType.REQUEST));
				 
	logger.trace(ctx.dump());

	ctx.setHandler(handler);
	server.setHandler(ctx);
	
	try {
		server.start();
		logger.info("Webdav start on port http://"+InetAddress.getLocalHost().getHostName() + ":"+getInt(SERVER_PORT));

	} catch (Exception e) {
		throw new IOException(e);
	}
}