public final void start(int port) throws Exception { String nodeId = registerForNotifications(); port = setPort(port); System.out.println("DSO SharedQueue (node " + nodeId + ")"); System.out.println( "Open your browser and go to - http://" + getHostName() + ":" + port + "/webapp\n"); Server server = new Server(); Connector connector = new SocketConnector(); connector.setPort(port); server.setConnectors(new Connector[] {connector}); queue = new Queue(port); worker = queue.createWorker(nodeId); ResourceHandler resourceHandler = new ResourceHandler(); resourceHandler.setResourceBase("."); ContextHandler ajaxContext = new ContextHandler(); ajaxContext.setContextPath(SimpleHttpHandler.ACTION); ajaxContext.setResourceBase(cwd.getPath()); ajaxContext.setClassLoader(Thread.currentThread().getContextClassLoader()); ajaxContext.addHandler(new SimpleHttpHandler(queue)); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers(new Handler[] {ajaxContext, resourceHandler}); server.setHandler(handlers); startReaper(); server.start(); server.join(); }
public JettyHttpServer() { _server = new Server(); HandlerCollection handlerCollection = new HandlerCollection(); _contextCollection = new ContextHandlerCollection(); handlerCollection.setHandlers(new Handler[] {_contextCollection, new DefaultHandler()}); _server.setHandler(handlerCollection); }
protected void configureHandlers() { if (server != null) { HandlerCollection handlers = new HandlerCollection(); contexts = new ContextHandlerCollection(); handlers.setHandlers(new Handler[] {contexts, new DefaultHandler()}); server.setHandler(handlers); } }
public LiquidityServer() throws IOException { server = new Server(valueOf(getenv("PORT"))); AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); applicationContext.register(ProductionContext.class); applicationContext.refresh(); URL resource = this.getClass().getClassLoader().getResource("webapp"); String webapp = resource.toExternalForm(); WebAppContext handler = new WebAppContext(webapp, CONTEXT); handler.setAttribute( WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext); handler.setResourceBase(webapp); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers(new Handler[] {handler, new DefaultHandler()}); server.addHandler(handlers); }
/** temp main - just to help testing */ public static void main(String[] args) throws Exception { Server server = new Server(); Connector connector = new GrizzlyConnector(); connector.setPort(8080); server.setConnectors(new Connector[] {connector}); HandlerCollection handlers = new HandlerCollection(); ContextHandlerCollection contexts = new ContextHandlerCollection(); handlers.setHandlers(new Handler[] {contexts, new DefaultHandler()}); server.setHandler(handlers); // TODO add javadoc context to contexts WebAppContext.addWebApplications( server, "../../webapps", "org/mortbay/jetty/webapp/webdefault.xml", true, false); HashUserRealm userRealm = new HashUserRealm(); userRealm.setName("Test Realm"); userRealm.setConfig("../../etc/realm.properties"); server.setUserRealms(new UserRealm[] {userRealm}); server.start(); server.join(); }
public static void main(String[] args) throws Exception { String name = args.length > 0 ? args[0] : "app"; Mocker mocker = Mocker.init(name); String webXml = mocker.getWebXml(); int port = mocker.getPort(); File fapp = new File(APP_PATH); final Connector conn = new SelectChannelConnector(); conn.setPort(port); conn.setMaxIdleTime(60000); conn.setHeaderBufferSize(20480); // 缺省4K, Chrome下可能会报错: 413 FULL head Listener listerner = new Listener() { @Override public void lifeCycleFailure(LifeCycle arg0, Throwable arg1) { logger.info("YDJT SYSTEM {} FAILED!!!", Application.VERSION); } @Override public void lifeCycleStarted(LifeCycle arg0) { logger.info("YDJT SYSTEM {} STARTED!", Application.VERSION); } @Override public void lifeCycleStarting(LifeCycle arg0) { logger.info("YDJT SYSTEM {} STARTING...", Application.VERSION); } @Override public void lifeCycleStopped(LifeCycle arg0) { logger.info("YDJT SYSTEM {} STOPPED!", Application.VERSION); } @Override public void lifeCycleStopping(LifeCycle arg0) { logger.info("YDJT SYSTEM {} STOPPING...", Application.VERSION); } }; Server server = new Server(); server.addLifeCycleListener(listerner); server.addConnector(conn); WebAppContext wapp = new WebAppContext(server, fapp.getCanonicalPath(), CONTEXT_PATH); HandlerCollection hc = new HandlerCollection(); ContextHandlerCollection chc = new ContextHandlerCollection(); hc.setHandlers(new Handler[] {chc, new DefaultHandler()}); ContextDeployer cd = new ContextDeployer(); cd.setContexts(chc); cd.setConfigurationDir(APP_PATH); cd.setDirectory(APP_PATH); cd.setScanInterval(5); wapp.setClassLoader(ClassLoader.getSystemClassLoader()); wapp.setParentLoaderPriority(false); wapp.setExtractWAR(false); // setDescriptor() -- 使用其他文件作为web.xml // wapp.setDefaultsDescriptor(WEB_XML); // setWelcomeFiles()和web.xml中的welcome-file-list都没有用, // 因为/已定义在test-mvc的servlet-mapping中?? wapp.setDescriptor(APP_PATH + "/WEB-INF/" + webXml); // server.addLifeCycle(wapp); server.addHandler(hc); server.start(); server.join(); wapp.start(); server.addLifeCycle(cd); }
/** * Starts the container and hence the embedded jetty server. * * @throws Exception if there is an issue while starting the server */ @PostConstruct public void init() throws Exception { try { if (alreadyInited.compareAndSet(false, true)) { initAdminContainerConfigIfNeeded(); initAdminRegistryIfNeeded(); if (!adminContainerConfig.shouldEnable()) { return; } if (adminContainerConfig.shouldScanClassPathForPluginDiscovery()) { adminPageRegistry.registerAdminPagesWithClasspathScan(); } Injector adminResourceInjector; if (shouldShareResourcesWithParentInjector()) { adminResourceInjector = appInjector.createChildInjector(buildAdminPluginsGuiceModules()); } else { adminResourceInjector = LifecycleInjector.builder() .inStage(Stage.DEVELOPMENT) .usingBasePackages("com.netflix.explorers") .withModules(buildAdminPluginsGuiceModules()) .build() .createInjector(); adminResourceInjector.getInstance(LifecycleManager.class).start(); } server = new Server(adminContainerConfig.listenPort()); // redirect filter based on configurable RedirectRules final Context rootHandler = new Context(); rootHandler.setContextPath("/"); rootHandler.addFilter( new FilterHolder(adminResourceInjector.getInstance(RedirectFilter.class)), "/*", Handler.DEFAULT); rootHandler.addServlet(new ServletHolder(new DefaultServlet()), "/*"); // admin page template resources AdminResourcesFilter arfTemplatesResources = adminResourceInjector.getInstance(AdminResourcesFilter.class); arfTemplatesResources.setPackages(adminContainerConfig.jerseyViewableResourcePkgList()); final Context adminTemplatesResHandler = new Context(); adminTemplatesResHandler.setContextPath(adminContainerConfig.templateResourceContext()); adminTemplatesResHandler.setSessionHandler(new SessionHandler()); adminTemplatesResHandler.addFilter(LoggingFilter.class, "/*", Handler.DEFAULT); adminTemplatesResHandler.addFilter( new FilterHolder(adminResourceInjector.getInstance(RedirectFilter.class)), "/*", Handler.DEFAULT); adminTemplatesResHandler.addFilter( new FilterHolder(arfTemplatesResources), "/*", Handler.DEFAULT); adminTemplatesResHandler.addServlet(new ServletHolder(new DefaultServlet()), "/*"); // admin page data resources final String jerseyPkgListForAjaxResources = appendCoreJerseyPackages(adminPageRegistry.buildJerseyResourcePkgListForAdminPages()); AdminResourcesFilter arfDataResources = adminResourceInjector.getInstance(AdminResourcesFilter.class); arfDataResources.setPackages(jerseyPkgListForAjaxResources); final Context adminDataResHandler = new Context(); adminDataResHandler.setContextPath(adminContainerConfig.ajaxDataResourceContext()); adminDataResHandler.addFilter( new FilterHolder(adminResourceInjector.getInstance(RedirectFilter.class)), "/*", Handler.DEFAULT); adminDataResHandler.addFilter(new FilterHolder(arfDataResources), "/*", Handler.DEFAULT); adminDataResHandler.addServlet(new ServletHolder(new DefaultServlet()), "/*"); QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setDaemon(true); server.setThreadPool(threadPool); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers( new Handler[] {adminTemplatesResHandler, adminDataResHandler, rootHandler}); server.setHandler(handlers); server.start(); final Connector connector = server.getConnectors()[0]; serverPort = connector.getLocalPort(); } } catch (Exception e) { logger.error("Exception in building AdminResourcesContainer ", e); } }
private synchronized void enableRemoteAccess() throws Exception { if (remoteAccessForward == null) { logger.fine("enabling remote access"); Connector connector = new SelectChannelConnector(); connector.setHost(LOCALHOST); connector.setPort(Constants.LOCAL_WEB_SERVER_PORT_AUTH); authenticatedServer = new Server(); authenticatedServer.addConnector(connector); // sets the thread pool (just so it is deamon=true) QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setMinThreads(5); // threadPool.setMaxThreads(10); threadPool.setName("Auth Jetty thread pool"); threadPool.setDaemon(true); authenticatedServer.setThreadPool(threadPool); Constraint constraint = new Constraint(); constraint.setName(Constraint.__BASIC_AUTH); constraint.setRoles(new String[] {"remote_user"}); constraint.setAuthenticate(true); ConstraintMapping cm = new ConstraintMapping(); cm.setConstraint(constraint); cm.setPathSpec("/*"); SecurityHandler securityHandler = new SecurityHandler(); securityHandler.setUserRealm( new ExtraSaltHashUserRealm( RemoteAccessConfig.usesMD5Sha1Password(), "OneSwarm Remote", RemoteAccessConfig.REMOTE_ACCESS_FILE.getCanonicalPath())); securityHandler.setConstraintMappings(new ConstraintMapping[] {cm}); ContextHandlerCollection contexts = new ContextHandlerCollection(); authenticatedServer.setHandler(contexts); Context root = new Context(contexts, "/", Context.NO_SESSIONS); root.addFilter(new FilterHolder(new GzipFilter()), "/*", Handler.ALL); MultiHandler mh = new MultiHandler(coreInterface, true); if (System.getProperty("com.sun.management.jmxremote") != null) { RequestLogHandler requestLogHandler = new RequestLogHandler(); NCSARequestLog requestLog = new NCSARequestLog("/tmp/jetty-yyyy_mm_dd.remoterequest.log"); requestLog.setRetainDays(1); requestLog.setAppend(false); requestLog.setExtended(true); requestLog.setLogTimeZone("GMT"); requestLogHandler.setRequestLog(requestLog); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers(new Handler[] {mh, requestLogHandler}); root.setHandler(handlers); } else { root.setHandler(mh); } root.addHandler(securityHandler); // make sure that the class loader can find all classes in the // osgwtui // plugin dir... root.setClassLoader(pluginInterface.getPluginClassLoader()); authenticatedServer.start(); remoteAccessForward = new RemoteAccessForward(); remoteAccessForward.start(); logger.fine("remote access enabled"); } coreInterface.setRemoteAccess(remoteAccessForward); }
public void initialize(PluginInterface pluginInterface) throws PluginException { this.coreInterface = new CoreInterface(pluginInterface); // make sure to unload in case of shutdown this.pluginInterface = pluginInterface; logger.fine("oneswarm ui plugin loaded"); Connector connector = new SelectChannelConnector(); connector.setHost(LOCALHOST); connector.setPort(Constants.LOCAL_WEB_SERVER_PORT); server = new Server(); /** If we're running with jconsole support, start the MBean server */ if (System.getProperty("com.sun.management.jmxremote") != null) { connector.setStatsOn(true); logger.info("Starting managemenat bean"); // MBeanServer mBeanServer = // ManagementFactory.getPlatformMBeanServer(); // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer); // server.getContainer().addEventListener(mBeanContainer); // mBeanContainer.start(); } checkAutoStartRegistry(); server.addConnector(connector); // sets the thread pool (just so it is deamon=true) BoundedThreadPool threadPool = new BoundedThreadPool(); threadPool.setMinThreads(5); // threadPool.setMaxThreads(10); threadPool.setName("Jetty thread pool"); threadPool.setDaemon(true); server.setThreadPool(threadPool); ContextHandlerCollection contexts = new ContextHandlerCollection(); server.setHandler(contexts); Context root = new Context(contexts, "/", Context.NO_SESSIONS); MultiHandler mh = new MultiHandler(coreInterface, false); if (System.getProperty("com.sun.management.jmxremote") != null) { RequestLogHandler requestLogHandler = new RequestLogHandler(); NCSARequestLog requestLog = new NCSARequestLog("/tmp/jetty-yyyy_mm_dd.request.log"); requestLog.setRetainDays(1); requestLog.setAppend(false); requestLog.setExtended(true); requestLog.setLogTimeZone("GMT"); requestLogHandler.setRequestLog(requestLog); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers(new Handler[] {mh, requestLogHandler}); root.setHandler(handlers); } else { root.setHandler(mh); } // make sure that the class loader can find all classes in the osgwtui // plugin dir... root.setClassLoader(pluginInterface.getPluginClassLoader()); root.setVirtualHosts(new String[] {LOCALHOST}); try { server.start(); if (isRemoteAccessAllowed()) { enableRemoteAccess(); } installRemoteAccessPropertyListener(); // Thread.sleep(10000); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } CommunityServerManager.get(); // check to see if we can parse a planetlab-style experiment config file try { Class expConfigManagerClass = Class.forName("edu.washington.cs.oneswarm.planetlab.ExperimentConfigManager"); if (expConfigManagerClass != null) { Method getMethod = expConfigManagerClass.getMethod("get"); Object configManager = getMethod.invoke(null, new Object[] {}); if (configManager != null) { logger.info("Got experimental manager"); Method setCore = expConfigManagerClass.getMethod("setCore", new Class[] {CoreInterface.class}); setCore.invoke(configManager, coreInterface); logger.info("Set core"); Method startHeartbeats = expConfigManagerClass.getMethod("startHeartbeats"); startHeartbeats.invoke(configManager); logger.info("startHeartbeats"); } else { logger.info("configManager is null -- classes found but experimental mode not enabled"); } } } catch (ClassNotFoundException e) { logger.info("PlanetLab classes not found -- not running in experimental mode."); } catch (Exception e) { System.err.println(e); logger.info("PlanetLab classes failed to load -- not running in experimental mode."); } // make sure community server refreshes whether we load the web UI or // not. CommunityServerManager.get(); /* * add the listener to the sha1 hasher manager */ Sha1HashManager.getInstance() .addJobListener( new Sha1HashJobListener() { public Sha1CalcListener jobAdded(String name) { final int taskID = BackendTaskManager.get() .createTask( "Hashing: " + name, new CancellationListener() { public void cancelled(int inID) { Sha1HashManager.getInstance().stop(); } }); final BackendTask task = BackendTaskManager.get().getTask(taskID); task.setSummary("Calculating SHA1 and ED2K hashes of " + name); return new Sha1CalcListener() { public void progress(double fraction) { int percent = (int) Math.round(100 * fraction); task.setProgress(percent + "%"); } public void errorOccured(Throwable cause) { BackendTaskManager.get().removeTask(taskID); } public void completed(Sha1Result result) { BackendTaskManager.get().removeTask(taskID); } }; } }); /** Start health checking */ HealthChecker health = new HealthChecker(); health.start(); }