Server server = new Server(8080); WebSocketHandler wsHandler = new WebSocketHandler() { @Override public void configure(WebSocketServletFactory factory) { factory.register(MyEchoSocket.class); } }; ContextHandler context = new ContextHandler(); context.setContextPath("/echo"); context.setHandler(wsHandler); server.addHandler(context); server.start(); server.join();
sch.setHandler(new JettyHandler(handler, webSocketServerFactory, conf .getString("application.tmpdir"), conf.getBytes("jetty.FileSizeThreshold").intValue()));
@Signature public void addWebSocket(Environment env, String path, ArrayMemory _handlers) { WebSocketParam param = _handlers.toBean(env, WebSocketParam.class); ContextHandler contextHandler = new ContextHandler(path); contextHandler.setHandler(new WebSocketHandler() { @Override public void configure(WebSocketServletFactory factory) { factory.setCreator(new WebSocketCreator() { @Override public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) { return new WebSocket(env, param); } }); } }); handlers.addHandler(contextHandler); }
@Override public void start() { writeTimeToFile("startingAt"); ContextHandler context = new ContextHandler(); context.setContextPath("/"); context.setClassLoader(Thread.currentThread().getContextClassLoader()); server.setHandler(context); context.setHandler(new AbstractHandler() { @Override public void handle(String target, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException { if ("/ping".equals(target)) { request.setHandled(true); httpServletResponse.getWriter().print("ping"); } else if ("/restart".equals(target)) { writeTimeToFile("restartAskedAt"); request.setHandled(true); processCommands.askForRestart(); httpServletResponse.getWriter().print("ok"); } else if ("/kill".equals(target)) { writeTimeToFile("killedAt"); System.exit(0); } } }); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Fail to start Jetty", e); } }
context.setHandler(sessions);
sendGcodeContext.setBaseResource(getBaseResource()); sendGcodeContext.setClassLoader(Thread.currentThread().getContextClassLoader()); sendGcodeContext.setHandler(new SendGcodeHandler()); adjustManualLocationContext.setBaseResource(getBaseResource()); adjustManualLocationContext.setClassLoader(Thread.currentThread().getContextClassLoader()); adjustManualLocationContext.setHandler(new AdjustManualLocationHandler()); getSystemStateContext.setBaseResource(getBaseResource()); getSystemStateContext.setClassLoader(Thread.currentThread().getContextClassLoader()); getSystemStateContext.setHandler(new GetSystemStateHandler()); configContext.setBaseResource(getBaseResource()); configContext.setClassLoader(Thread.currentThread().getContextClassLoader()); configContext.setHandler(new ConfigHandler()); configContext.setInitParameter("cacheControl", "max-age=0, public");
contextHandler.setHandler(resourceHandler); contextHandler.addAliasCheck(new ContextHandler.ApproveAliases());
@Override public void setHandler(Handler handler) { if (handler!=null) LOG.warn("ServletContextHandler.setHandler should not be called directly. Use insertHandler or setSessionHandler etc."); super.setHandler(handler); }
@Override public void setHandler(Handler handler) { if (handler!=null) LOG.warn("ServletContextHandler.setHandler should not be called directly. Use insertHandler or setSessionHandler etc."); super.setHandler(handler); }
private ContextHandler newContext(String path, Handler handler) { ContextHandler context = new ContextHandler(); context.setContextPath(path); context.setHandler(handler); return context; } }
ServerConnector httpConnector = new ServerConnector(server); httpConnector.setName("unsecured"); // named connector httpConnector.setPort(80); ContextHandler helloHandler = new ContextHandler(); helloHandler.setContextPath("/hello"); helloHandler.setHandler(new HelloHandler("Hello World")); helloHandler.setVirtualHosts(new String[]{"@unsecured"});
protected void registerWebapp(GlobalContext context, String path) { ResourceHandler bb = new ResourceHandler(); bb.setResourceBase(this.getClass().getResource("webapp").toExternalForm()); ContextHandler ctx = new ContextHandler(path); ctx.setHandler(bb); context.getServiceRegistrationCallback().registerHandler(ctx); } }
private void addContext(ContextHandlerCollection contexts, String contextPath, Handler handler) { ContextHandler contextHandler = contexts.addContext(contextPath, ""); contextHandler.setHandler(handler); contextHandler.addAliasCheck(new AllowSymLinkAliasChecker()); }
ContextHandlerCollection contexts = new ContextHandlerCollection(); server.setHandler(contexts); ContextHandler stock = new ContextHandler("/stock"); stock.setHandler(new Class2HTTPMessageHandler()); contexts.add(stock);
ResourceHandler staticResource = new ResourceHandler(); staticResource.setDirectoriesListed(true); staticResource.setWelcomeFiles(new String[] { "index.html" }); staticResource.setResourceBase("/path/to/your/files"); ContextHandler staticContextHandler = new ContextHandler(); staticContextHandler.setContextPath("/*"); staticContextHandler.setHandler(staticResource); Server server = new Server(8080); server.setHandler(staticContextHandler);
ContextHandler capHandler = new ContextHandler(); capHandler.setContextPath("/clientaccesspolicy.xml"); ResourceHandler resHandler = new ResourceHandler(); resHandler.setBaseResource(Resource.newClassPathResource("clientaccesspolicy.xml")); capHandler.setHandler(resHandler);
public void addStaticResources(String basePath, String resourcePath) { ContextHandler capHandler = new ContextHandler(); capHandler.setContextPath(basePath); ResourceHandler resHandler = new ResourceHandler(); resHandler.setBaseResource(Resource.newClassPathResource(resourcePath)); resHandler.setEtags(true); resHandler.setCacheControl(WebService.HANDLER_CACHE_CONTROL); capHandler.setHandler(resHandler); handlers.add(capHandler); }
public void addStaticResources(String basePath, String resourcePath) { ContextHandler capHandler = new ContextHandler(); capHandler.setContextPath(basePath); ResourceHandler resHandler = new ResourceHandler(); resHandler.setBaseResource(Resource.newClassPathResource(resourcePath)); resHandler.setEtags(true); resHandler.setCacheControl(WebService.HANDLER_CACHE_CONTROL); capHandler.setHandler(resHandler); handlers.add(capHandler); }
public void addResourceContext(String context, File directory) throws MalformedURLException, IOException { ContextHandler contextHandler = new ContextHandler(); ResourceHandler contentResourceHandler = new ResourceHandler(); contextHandler.setBaseResource(Resource.newResource(directory)); contextHandler.setHandler(contentResourceHandler); contextHandler.setContextPath(context); addContextHandler(contextHandler); }
private ContextHandler createStaticContextHandler(String contextPath, String fsPath) { ResourceHandler resourceHandler = new ResourceHandler(); resourceHandler.setDirectoriesListed(true); resourceHandler.setWelcomeFiles(new String[]{"index.htm", "index.html"}); resourceHandler.setResourceBase(fsPath); ContextHandler ch = new ContextHandler(); ch.setContextPath(contextPath); ch.setHandler(resourceHandler); return ch; }