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();
ContextHandler sch = new ContextHandler(); sch.setAttribute(DecoratedObjectFactory.ATTR, new DecoratedObjectFactory());
@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); } }
ContextHandler context = new ContextHandler("/"); server.setHandler(context);
resourceHandler.setDirectoriesListed(true); ContextHandler sendGcodeContext = new ContextHandler(); sendGcodeContext.setContextPath("/sendGcode"); sendGcodeContext.setBaseResource(getBaseResource()); sendGcodeContext.setHandler(new SendGcodeHandler()); ContextHandler adjustManualLocationContext = new ContextHandler(); adjustManualLocationContext.setContextPath("/adjustManualLocation"); adjustManualLocationContext.setBaseResource(getBaseResource()); adjustManualLocationContext.setHandler(new AdjustManualLocationHandler()); ContextHandler getSystemStateContext = new ContextHandler(); getSystemStateContext.setContextPath("/getSystemState"); getSystemStateContext.setBaseResource(getBaseResource()); getSystemStateContext.setHandler(new GetSystemStateHandler()); ContextHandler configContext = new ContextHandler(); configContext.setContextPath("/config"); configContext.setBaseResource(getBaseResource());
contextHandler = new ContextHandler(); contextHandler.setHandler(resourceHandler); contextHandler.addAliasCheck(new ContextHandler.ApproveAliases());
public static void main(String[] args) throws Exception { Server server = new Server(8080); // Add a single handler on context "/hello" ContextHandler context = new ContextHandler(); context.setContextPath("/hello"); context.setHandler(new HelloHandler()); // Can be accessed using http://localhost:8080/hello server.setHandler(context); // Start the server server.start(); server.join(); } }
private ContextHandler newContext(String path, Handler handler) { ContextHandler context = new ContextHandler(); context.setContextPath(path); context.setHandler(handler); return context; } }
private void installSwagger(HandlerList handlers) { LOGGER.debug("Adding Swagger documentation"); final ResourceHandler resourceHandler = new ResourceHandler(); resourceHandler.setDirectoriesListed(true); // resourceHandler.setResourceBase(getClass().getResource("/swagger").toExternalForm()); ContextHandler swaggerHandler = new ContextHandler("/swagger/*"); swaggerHandler.setHandler(resourceHandler); handlers.addHandler(swaggerHandler); }
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); } }
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 ContextHandler getHandler() { ContextHandler contextHandler = new ContextHandler(); contextHandler.setContextPath(contextPath); contextHandler.setHandler(wrappedHandler.getHandler()); contextHandler.setVirtualHosts(virtualHosts); return contextHandler; }
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; }