private ServletContextHandler buildServletContextHandler() { ServletContextHandler result = new ServletContextHandler(ServletContextHandler.SESSIONS); result.setContextPath("/"); return result; }
/** * Gets the {@link ServletContextHandler} of the metrics servlet. * * @return the {@link ServletContextHandler} object */ public ServletContextHandler getHandler() { ServletContextHandler contextHandler = new ServletContextHandler(); contextHandler.setContextPath(SERVLET_PATH); contextHandler.addServlet(new ServletHolder(createServlet()), "/"); return contextHandler; }
Server server = new Server(8080); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); context.addServlet(org.eclipse.jetty.servlet.DefaultServlet.class, "/"); context.addFilter(AppFilter.class, "/*", EnumSet.of(DispatcherType.INCLUDE,DispatcherType.REQUEST)); server.setHandler(context); server.start(); server.join();
/** * Gets the {@link ServletContextHandler} of the metrics servlet. * * @return the {@link ServletContextHandler} object */ public ServletContextHandler getHandler() { ServletContextHandler contextHandler = new ServletContextHandler(); contextHandler.setContextPath(SERVLET_PATH); contextHandler.addServlet(new ServletHolder(new MetricsServlet(mCollectorRegistry)), "/"); return contextHandler; }
public void start() { server = new Server(); ServerConnector connector = new ServerConnector(server); connector.setPort(port); server.addConnector(connector); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); server.setHandler(context); try { ServerContainer wscontainer = WebSocketServerContainerInitializer.configureContext(context); wscontainer.addEndpoint(new RPDEndpointConfig()); server.start(); server.join(); } catch (Exception e) { throw new RuntimeException(e); } }
public class ExampleServer { public static void main(String[] args) throws Exception { Server server = new Server(9998); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); server.setHandler(context); ServletHolder jerseyServlet = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/*"); jerseyServlet.setInitOrder(0); /*This parameter tells the Jersey Servlet which of your REST resources to load. In this example we're adding the TestResource class. Jersey will then invoke this class for requests coming into paths denoted by the @Path parameter within the TestResource class. If you have multiple classes, you can either list them all comma separated, of use "jersey.config.server.provider.packages" and list the package name instead */ jerseyServlet.setInitParameter("jersey.config.server.provider.classnames", "foo.bar.TestResource"); server.start(); server.join(); } }
@Override synchronized public void registerServlet(String contextPath, Servlet servlet) { if (server.getHandler() != null) { return; } log.info("Registering UPnP servlet under context path: " + contextPath); ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); if (contextPath != null && contextPath.length() > 0) servletHandler.setContextPath(contextPath); ServletHolder s = new ServletHolder(servlet); servletHandler.addServlet(s, "/*"); server.setHandler(servletHandler); }
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); }
ResourceConfig resourceConfig = new ResourceConfig(); // Add your resources and Swagger resources (ApiListingResource package) resourceConfig.packages(YourJerseyResourceClass.class.getPackage().getName(), ApiListingResource.class.getPackage().getName()); ServletContainer servletContainer = new ServletContainer(resourceConfig); ServletHolder servletHolder = new ServletHolder(servletContainer); ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); servletContextHandler.setContextPath("/"); servletContextHandler.addServlet(servletHolder, "/*");
public JettyAdminServer(String address, int port, int timeout, String commandUrl) { this.port = port; this.idleTimeout = timeout; this.commandUrl = commandUrl; this.address = address; server = new Server(); ServerConnector connector = new ServerConnector(server); connector.setHost(address); connector.setPort(port); connector.setIdleTimeout(idleTimeout); server.addConnector(connector); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/*"); server.setHandler(context); context.addServlet(new ServletHolder(new CommandServlet()), commandUrl + "/*"); }
/** recreates the server so that it uses the supplied trace configuration */ public final void init() { stop(); server = newServer(port); ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); server.setHandler(context); init(context); try { server.start(); port = getLocalPort(server); } catch (Exception e) { throw new IllegalStateException("Failed to start server.", e); } }
/** * Start the server. * @param port the port it shuld listen on, or null/<= 0 to pick a free ephemeral port. */ public void serve(Integer port) { try { if (server != null) { throw new RuntimeException("The server is already running"); } if (port == null || port <= 0) { ServerSocket s = new ServerSocket(0); port = s.getLocalPort(); s.close(); } server = new Server(port); this.port = port; url = "http://" + InetAddress.getLocalHost().getHostName() + ":" + this.port + "/"; ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); server.setHandler(context); context.addServlet(new ServletHolder(new MetricsCollectionServlet()),"/*"); server.start(); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
mServletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); mServletContextHandler.setContextPath(AlluxioURI.SEPARATOR);
public static void main(String[] args) throws Exception { final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); context.setResourceBase(System.getProperty("java.io.tmpdir")); DynamicConfig config = DynamicConfigLoader.load("gateway.properties"); context.addServlet(PullServlet.class, "/pull/*"); context.addServlet(SendServlet.class, "/send/*"); int port = config.getInt("gateway.port", 8080); final Server server = new Server(port); server.setHandler(context); server.start(); server.join(); } }
public EmbeddedWebServer(String host, int port) { server = new Server(); final AccumuloConfiguration conf = Monitor.getContext().getConfiguration(); connector = new ServerConnector(server, getConnectionFactories(conf)); connector.setHost(host); connector.setPort(port); handler = new ServletContextHandler( ServletContextHandler.SESSIONS | ServletContextHandler.SECURITY); handler.getSessionHandler().getSessionCookieConfig().setHttpOnly(true); handler.setContextPath("/"); }
private void initJettyContextHandler(final CoreConfigure cfg) { final ServletContextHandler context = new ServletContextHandler(NO_SESSIONS); final String contextPath = "/sandbox/" + cfg.getNamespace(); context.setContextPath(contextPath); context.setClassLoader(getClass().getClassLoader()); // web-socket-servlet final String wsPathSpec = "/module/websocket/*"; logger.info("initializing ws-http-handler. path={}", contextPath + wsPathSpec); context.addServlet(new ServletHolder(new WebSocketAcceptorServlet(coreModuleManager, moduleResourceManager)), wsPathSpec); // module-http-servlet final String pathSpec = "/module/http/*"; logger.info("initializing http-handler. path={}", contextPath + pathSpec); context.addServlet(new ServletHolder(new ModuleHttpServlet(coreModuleManager, moduleResourceManager)), pathSpec); httpServer.setHandler(context); }
private ServletContextHandler getContext(HandlerContainer pContainer, MuleAgentConfig pConfig) { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/jolokia"); server.setHandler(context); if (pConfig.getUser() != null && pConfig.getPassword() != null) { context.setSecurityHandler( getSecurityHandler(pConfig.getUser(), pConfig.getPassword(), "jolokia-role")); } return context; }
public void start() throws Exception { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); jettyServer.setHandler(context); context.addEventListener(new HealthCheckServletContextListener(healthCheckRegistry)); context.addEventListener(new MetricsServletContextListener(metricRegistry)); context.addServlet(new ServletHolder(new AdminServlet()), "/*"); jettyServer.start(); }
= new ServletContextHandler(); boolean b = false; servletContextHandler.setContextPath("/");
httpsTsPath, httpsTsPassword, httpsTsType, httpsNeedClientAuth, httpsWantClientAuth); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); context.setContextPath("/"); ret.setHandler(context); ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, "/*"); jerseyServlet.setInitOrder(1); jerseyServlet.setInitParameter("javax.ws.rs.Application", DRPCApplication.class.getName());