@Override protected void startUp() throws Exception { LOGGER.info("Starting the admin web server"); this.server = new Server(new InetSocketAddress(this.serverUri.getHost(), this.serverUri.getPort())); HandlerCollection handlerCollection = new HandlerCollection(); handlerCollection.addHandler(buildSettingsHandler()); handlerCollection.addHandler(buildStaticResourceHandler()); this.server.setHandler(handlerCollection); this.server.start(); }
final Server server = new Server(port); final ContextHandlerCollection contexts = new ContextHandlerCollection(); final ServletContextHandler context = new ServletContextHandler(contexts, "/", ServletContextHandler.SESSIONS); context.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.INCLUDE, DispatcherType.REQUEST)); contexts.addHandler(requestLogHandler); final HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers(new Handler[] { contexts }); server.setHandler(handlers); server.start();
/** * Add the given handler to the front of the list of handlers. * * @param handler The handler to add */ public void addHandlerAtFront(Handler handler) { Handler[] h = ArrayUtil.prependToArray( handler, this.handlers.getHandlers(), Handler.class); handlers.setHandlers(h); }
public void clearHandlers() { HandlerCollection hc = (HandlerCollection) jetty.getHandler(); Handler[] ha = hc.getHandlers(); if (ha != null) { for (Handler h : ha) { hc.removeHandler(h); } } }
protected static void startServers(String port) throws Exception { server = new org.eclipse.jetty.server.Server(Integer.parseInt(port)); WebAppContext webappcontext = new WebAppContext(); String contextPath = null; try { contextPath = JAXRSClientServerWebSocketSpringWebAppTest.class .getResource("/jaxrs_websocket").toURI().getPath(); } catch (URISyntaxException e1) { e1.printStackTrace(); } webappcontext.setContextPath("/webapp"); webappcontext.setWar(contextPath); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers(new Handler[] {webappcontext, new DefaultHandler()}); server.setHandler(handlers); server.start(); }
protected void run() { System.setProperty("java.naming.factory.url", "org.eclipse.jetty.jndi"); System.setProperty("java.naming.factory.initial", "org.eclipse.jetty.jndi.InitialContextFactory"); server = new Server(port); try { if (resourcePath == null) { // Register and map the dispatcher servlet final ServletHolder servletHolder = new ServletHolder(new CXFCdiServlet()); final ServletContextHandler context = new ServletContextHandler(); context.setContextPath(contextPath); context.addEventListener(listener); context.addServlet(servletHolder, "/rest/*"); server.setHandler(context); } else { final WebAppContext context = new WebAppContext(); context.setContextPath(contextPath); context.setWar(getClass().getResource(resourcePath).toURI().getPath()); context.setServerClasses(new String[] { "org.eclipse.jetty.servlet.ServletContextHandler.Decorator" }); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers(new Handler[] {context, new DefaultHandler()}); server.setHandler(handlers); } server.start(); } catch (final Exception ex) { ex.printStackTrace(); fail(ex.getMessage()); } }
File me = new File(((JarURLConnection) classFile.openConnection()).getJarFile().getName()); System.out.println(" - using warfile file : " + me); jettyServer = new Server(port); WebAppContext webappcontext = new WebAppContext(); webappcontext.setContextPath(contextPath); webappcontext.setWar(me.getAbsolutePath()); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers(new Handler[]{webappcontext, new DefaultHandler()}); jettyServer.setHandler(handlers); jettyServer.start(); serverUri = new URI("http://localhost:" + port + contextPath + startSuffixPath); } catch (URISyntaxException e) { e.printStackTrace();
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.xml.XmlConfiguration; ... public static void main(String[] args) throws Exception { ... Server server = new Server(port); HandlerCollection handlers = new HandlerCollection(); WebAppContext frontEndWebappContext = new WebAppContext( "src/main/webapp", "/test" ); handlers.addHandler(frontEndWebappContext); String serviceWebappBasePath = {absolute_path_to_other_webapp}; WebAppContext serviceWebappContext = new WebAppContext( serviceWebappBasePath + "/main/webapp", "/" ); handlers.addHandler(serviceWebappContext); XmlConfiguration conf = new XmlConfiguration(new File( serviceWebappBasePath + "test/webapp/WEB-INF/jetty-web.xml") .toURI().toURL().openStream()); conf.configure(serviceWebappContext); server.setHandler(handlers); server.start(); ...
final WebAppContext staticContext = new WebAppContext(); staticContext.setServer( getJetty() ); staticContext.setContextPath( mountPoint ); staticContext.setSessionHandler( sessionHandler ); staticContext.setInitParameter( "org.eclipse.jetty.servlet.Default.dirAllowed", "false" ); if ( resourceLoc != null ) URL url = resourceLoc.toURI().toURL(); final Resource resource = Resource.newResource( url ); staticContext.setBaseResource( resource ); EnumSet.of( DispatcherType.REQUEST, DispatcherType.FORWARD ) ); handlers.addHandler( staticContext );
protected void run() { //System.out.println("Starting Server"); server = new org.eclipse.jetty.server.Server(Integer.parseInt(PORT)); WebAppContext webappcontext = new WebAppContext(); webappcontext.setContextPath("/"); webappcontext.setBaseResource(Resource.newClassPathResource("/webapp")); server.setHandler(new HandlerCollection(webappcontext, new DefaultHandler())); try { server.start(); } catch (Exception e) { throw new RuntimeException(e); } } public void tearDown() throws Exception {
Server server = new Server(conf.net_http_port); HandlerCollection handlers = new HandlerCollection(); NCSARequestLog requestLog = new NCSARequestLog(); requestLog.setFilename(conf.log_dir + "/http-request-yyyy_mm_dd.log"); handlers.addHandler(requestLogHandler); context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); context.addServlet(new ServletHolder(CounterServlet.class), "/counter/*"); context.addServlet(new ServletHolder(RegisterServlet.class), "/register/*"); context.addServlet(new ServletHolder(TelegrafInputServlet.class), "/telegraf/*"); gzipHandler.setMinGzipSize(1024); gzipHandler.setHandler(context); handlers.addHandler(gzipHandler); } else { handlers.addHandler(context); server.setHandler(handlers); server.start(); server.join(); } catch (Exception e) {
Server server = new Server(); // Note: if you don't want control over type of connector, etc. you can simply // call new Server(<port>); ServerConnector connector = new ServerConnector(server); connector.setHost("0.0.0.0"); connector.setPort(8085); // Setting the name allows you to serve different app contexts from different connectors. connector.setName("main"); server.addConnector(connector); WebAppContext context = new WebAppContext(); context.setContextPath("/"); // For development within an IDE like Eclipse, you can directly point to the web.xml context.setWar("src/main/webapp"); context.addFilter(MyFilter.class, "/", 1); HandlerCollection collection = new HandlerCollection(); RequestLogHandler rlh = new RequestLogHandler(); // Slf4j - who uses anything else? Slf4jRequestLog requestLog = new Slf4jRequestLog(); requestLog.setExtended(false); rlh.setRequestLog(requestLog); collection.setHandlers(new Handler[] { context, rlh }); server.setHandler(collection); try { server.start(); server.join(); } catch (Exception e) { // Google guava way throw Throwables.propagate(e); }
public static void main(String[] args) throws Exception { WebAppMain.standAloneMode = true; Logo.print(true); initializeLogDir(); final ConfigureAdaptor conf = ConfigureManager.getConfigure(); connectScouterCollector(); final Server server = new Server(conf.getNetHttpPort()); HandlerCollection handlers = new HandlerCollection(); RequestLogHandler requestLogHandler = setRequestLogHandler(); handlers.addHandler(requestLogHandler); ServletContextHandler servletContextHandler = setWebAppContext(); if (conf.isNetHttpApiGzipEnabled()) { GzipHandler gzipHandler = new GzipHandler(); gzipHandler.setIncludedMethods("GET", "POST", "PUT", "DELETE"); gzipHandler.setMinGzipSize(1024); gzipHandler.setHandler(servletContextHandler); handlers.addHandler(gzipHandler); } else { handlers.addHandler(servletContextHandler); } server.setHandler(handlers); setWebSocketServer(servletContextHandler); try { server.start(); waitOnExit(server); } catch (Exception e) { e.printStackTrace(); } }
public final StandardLauncher start() throws Exception { final int port = propertyResolver.getProperty(CONFIG_KEY_PORT, Integer.class, DEFAULT_PORT); getLogger().info("About to start server. Use port={}", port); final Server server = new Server(port); setServerSettings(server); contextHandler = new ServletContextHandler(servletContextOptions); contextHandler.setContextPath("/"); //contextHandler.setSessionHandler(); initSpringContext(); final HandlerCollection handlerList = new HandlerCollection(); final List<Handler> handlers = getHandlers(); handlerList.setHandlers(handlers.toArray(new Handler[handlers.size()])); server.setHandler(handlerList); setShutdownStrategy(server); server.start(); server.join(); return this; }
tp.setName("Jetty-QTP-AdminConsole"); adminServer = new Server(tp); adminServer.addBean(jmx.getContainer()); httpConnector.setHost(bindInterface); httpConnector.setPort(adminPort); adminServer.addConnector(httpConnector); HandlerCollection collection = new HandlerCollection(); adminServer.setHandler(collection); collection.setHandlers(new Handler[] { contexts, new DefaultHandler() });
WebAppContext webapp = new WebAppContext(); webapp.setContextPath(webAppContext); webapp.setWar(warFilePath); webapp.setParentLoaderPriority(false); webapp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); webapp.setTempDirectory(tmpPath); logger.info("Adding webapp " + webAppContext); ((HandlerCollection) httpServer.getHandler()).addHandler(webapp); if (!httpServer.isStarted()) { logger.info("Attempting to start HTTP service on port ({}) at bind-address ({})...", this.port, this.bindAddress); httpServer.start(); } else { webapp.start();
jetty = new Server( createQueuedThreadPool( jettyThreadCalculator ) ); jetty.addConnector( httpConnector ); jetty.addConnector( httpsConnector ); jetty.setHandler( handlers ); handlers.addHandler( new MovedContextHandler() );
private void createServer(final Map<String, String> sslProperties) { jetty = new Server(); // create the unsecure connector createConnector(); // create the secure connector if sslProperties are specified if (sslProperties != null) { createSecureConnector(sslProperties); } jetty.setHandler(new HandlerCollection(true)); }
private void loadJAXRSResource( String mountPoint, JaxRsServletHolderFactory jaxRsServletHolderFactory ) { SessionHandler sessionHandler = new SessionHandler(); sessionHandler.setServer( getJetty() ); log.debug( "Mounting servlet at [%s]", mountPoint ); ServletContextHandler jerseyContext = new ServletContextHandler(); jerseyContext.setServer( getJetty() ); jerseyContext.setErrorHandler( new NeoJettyErrorHandler() ); jerseyContext.setContextPath( mountPoint ); jerseyContext.setSessionHandler( sessionHandler ); jerseyContext.addServlet( jaxRsServletHolderFactory.create( defaultInjectables, wadlEnabled ), "/*" ); addFiltersTo( jerseyContext ); handlers.addHandler( jerseyContext ); }
this.httpServer = new Server(); httpServer.setHandler(new HandlerCollection(true)); ServerConnector connector = null; httpServer.setConnectors(new Connector[] {connector});