/** Starts the server for end-to-end tests. */ private Server createServer(int port) throws Exception { Server newServer = new Server(port); // Attach the test resources in /endtoend as static content for the test ResourceHandler resources = new ResourceHandler(); URL resource = EndToEndTest.class.getResource("/endtoend"); resources.setBaseResource(Resource.newResource(resource)); newServer.addHandler(resources); Context context = new Context(newServer, "/", Context.SESSIONS); context.addEventListener(new GuiceServletContextListener()); Map<String, String> initParams = Maps.newHashMap(); String modules = Joiner.on(":") .join( SampleModule.class.getName(), DefaultGuiceModule.class.getName(), PropertiesModule.class.getName(), OAuthModule.class.getName()); initParams.put(GuiceServletContextListener.MODULES_ATTRIBUTE, modules); context.setInitParams(initParams); // Attach the gadget rendering servlet ServletHolder gadgetServletHolder = new ServletHolder(new GadgetRenderingServlet()); context.addServlet(gadgetServletHolder, GADGET_BASE); // Attach DataServiceServlet, wrapped in a proxy to fake errors ServletHolder restServletHolder = new ServletHolder(new ForceErrorServlet(new DataServiceServlet())); restServletHolder.setInitParameter("handlers", "org.apache.shindig.social.handlers"); context.addServlet(restServletHolder, REST_BASE); context.addFilter(AuthenticationServletFilter.class, REST_BASE, 0); // Attach JsonRpcServlet, wrapped in a proxy to fake errors ServletHolder rpcServletHolder = new ServletHolder(new ForceErrorServlet(new JsonRpcServlet())); rpcServletHolder.setInitParameter("handlers", "org.apache.shindig.social.handlers"); context.addServlet(rpcServletHolder, JSON_RPC_BASE); context.addFilter(AuthenticationServletFilter.class, JSON_RPC_BASE, 0); // Attach the ConcatProxyServlet - needed for rewritten JS ServletHolder concatHolder = new ServletHolder(new ConcatProxyServlet()); context.addServlet(concatHolder, CONCAT_BASE); // Attach the JsServlet - needed for rewritten JS ServletHolder jsHolder = new ServletHolder(new JsServlet()); context.addServlet(jsHolder, JS_BASE); // Attach MakeRequestServlet ServletHolder makeRequestHolder = new ServletHolder(new MakeRequestServlet()); context.addServlet(makeRequestHolder, MAKE_REQUEST_BASE); // Attach an EchoServlet, used to test proxied rendering ServletHolder echoHolder = new ServletHolder(new EchoServlet()); context.addServlet(echoHolder, "/echo"); return newServer; }
public void init() throws Exception { initializeEmitter(); initializeMonitors(); initializeMergerConfig(); initializeTaskToolbox(); initializeJacksonInjections(); initializeJacksonSubtypes(); initializeCuratorFramework(); initializeCuratorCoordinator(); initializeTaskMonitor(); initializeServer(); final ScheduledExecutorFactory scheduledExecutorFactory = ScheduledExecutors.createFactory(lifecycle); final ScheduledExecutorService globalScheduledExec = scheduledExecutorFactory.create(1, "Global--%d"); final MonitorScheduler monitorScheduler = new MonitorScheduler( configFactory.build(MonitorSchedulerConfig.class), globalScheduledExec, emitter, monitors); lifecycle.addManagedInstance(monitorScheduler); final Context root = new Context(server, "/", Context.SESSIONS); root.addServlet(new ServletHolder(new StatusServlet()), "/status"); root.addServlet(new ServletHolder(new DefaultServlet()), "/mmx/*"); root.addFilter(GuiceFilter.class, "/mmx/indexer/worker/v1/*", 0); }
/** Run couchdb-lucene. */ public static void main(String[] args) throws Exception { final HierarchicalINIConfiguration configuration = new HierarchicalINIConfiguration( Main.class.getClassLoader().getResource("couchdb-lucene.ini")); configuration.setReloadingStrategy(new FileChangedReloadingStrategy()); final File dir = new File(configuration.getString("lucene.dir", "indexes")); if (dir == null) { LOG.error("lucene.dir not set."); System.exit(1); } if (!dir.exists() && !dir.mkdir()) { LOG.error("Could not create " + dir.getCanonicalPath()); System.exit(1); } if (!dir.canRead()) { LOG.error(dir + " is not readable."); System.exit(1); } if (!dir.canWrite()) { LOG.error(dir + " is not writable."); System.exit(1); } LOG.info("Index output goes to: " + dir.getCanonicalPath()); final Server server = new Server(); final SelectChannelConnector connector = new SelectChannelConnector(); connector.setHost(configuration.getString("lucene.host", "localhost")); connector.setPort(configuration.getInt("lucene.port", 5985)); LOG.info("Accepting connections with " + connector); server.setConnectors(new Connector[] {connector}); server.setStopAtShutdown(true); server.setSendServerVersion(false); HttpClientFactory.setIni(configuration); final HttpClient httpClient = HttpClientFactory.getInstance(); final LuceneServlet servlet = new LuceneServlet(httpClient, dir, configuration); final Context context = new Context(server, "/", Context.NO_SESSIONS | Context.NO_SECURITY); context.addServlet(new ServletHolder(servlet), "/*"); context.addFilter(new FilterHolder(new GzipFilter()), "/*", Handler.DEFAULT); context.setErrorHandler(new JSONErrorHandler()); server.setHandler(context); server.start(); server.join(); }
/** Creates and starts the shutdown service. */ public synchronized void start() { if (adminService.isRunning()) { throw new IllegalStateException("Admin service is already running"); } Context commandContext = new Context(adminService, "/", false, false); adminCommands.add(buildShutdownCommand()); ServletHolder servletHolder; for (AbstractAdminCommand command : adminCommands) { servletHolder = new ServletHolder(command); commandContext.addServlet(servletHolder, command.getCommandPath()); } if (adminPassword != null) { FilterHolder passwordFiler = new FilterHolder(new PasswordProtectFilter(adminPassword)); commandContext.addFilter(passwordFiler, "/*", Handler.REQUEST); } JettyRunThread shutdownServiceRunThread = new JettyRunThread(adminService); shutdownServiceRunThread.start(); }
/** * 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); }