@BeforeClass public static void beforeClass() throws Exception { ccowServer = new Server(serverPort); final CCOWContextListener c = new CCOWContextListener(commonContext, new InlinedContextAgentRepositoryModule()); final MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer()); ccowServer.addBean(mbContainer); final ServletContextHandler webSocketServletContextHandler = new ServletContextHandler(ccowServer, "/ws", ServletContextHandler.SESSIONS); webSocketServletContextHandler.addEventListener(c); WebSocketServerContainerInitializer.configureContext(webSocketServletContextHandler); final ServletContextHandler restServletContextHandler = new ServletContextHandler(ccowServer, "/"); restServletContextHandler.addEventListener(c); restServletContextHandler.addFilter(AppGuiceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); final ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.setHandlers(new Handler[] { webSocketServletContextHandler, restServletContextHandler}); ccowServer.setHandler(contexts); ccowServer.start(); }
public void start() throws Exception { RequestLogHandler requestLogHandler = new RequestLogHandler(); Slf4jRequestLog requestLog = new Slf4jRequestLog(); requestLog.setExtended(true); requestLog.setLogTimeZone(TimeZone.getDefault().getID()); requestLog.setLogLatency(true); requestLogHandler.setRequestLog(requestLog); handlers.add(0, new ContextHandlerCollection()); handlers.add(requestLogHandler); ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.setHandlers(handlers.toArray(new Handler[handlers.size()])); HandlerCollection handlerCollection = new HandlerCollection(); handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler }); server.setHandler(handlerCollection); server.start(); log.info("Server started at end point {}", getServiceUri()); }
public void start() throws PulsarServerException { log.info("Starting web socket proxy at port {}", conf.getWebServicePort()); try { RequestLogHandler requestLogHandler = new RequestLogHandler(); Slf4jRequestLog requestLog = new Slf4jRequestLog(); requestLog.setExtended(true); requestLog.setLogTimeZone(TimeZone.getDefault().getID()); requestLog.setLogLatency(true); requestLogHandler.setRequestLog(requestLog); handlers.add(0, new ContextHandlerCollection()); handlers.add(requestLogHandler); ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.setHandlers(handlers.toArray(new Handler[handlers.size()])); HandlerCollection handlerCollection = new HandlerCollection(); handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler }); server.setHandler(handlerCollection); server.start(); } catch (Exception e) { throw new PulsarServerException(e); } }
public void start() throws PulsarServerException { try { RequestLogHandler requestLogHandler = new RequestLogHandler(); Slf4jRequestLog requestLog = new Slf4jRequestLog(); requestLog.setExtended(true); requestLog.setLogTimeZone(TimeZone.getDefault().getID()); requestLog.setLogLatency(true); requestLogHandler.setRequestLog(requestLog); handlers.add(0, new ContextHandlerCollection()); handlers.add(requestLogHandler); ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.setHandlers(handlers.toArray(new Handler[handlers.size()])); HandlerCollection handlerCollection = new HandlerCollection(); handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler }); server.setHandler(handlerCollection); server.start(); log.info("Web Service started at {}", pulsar.getWebServiceAddress()); } catch (Exception e) { throw new PulsarServerException(e); } }
private void initializeServer() { ResourceConfig resourceConfig = new ResourceConfig(); resourceConfig.packages(GridServices.class.getPackage().getName()); resourceConfig.register(JacksonJaxbJsonProvider.class); final Grid grid = this; resourceConfig.register(new AbstractBinder() { @Override protected void configure() { bind(grid).to(Grid.class); bind(fileManager).to(FileProvider.class); } }); ServletContainer servletContainer = new ServletContainer(resourceConfig); ServletHolder sh = new ServletHolder(servletContainer); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); context.addServlet(sh, "/*"); server = new Server(port); ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.setHandlers(new Handler[] { context}); server.setHandler(contexts); }
/** * * @param webapp * @return */ private static ContextHandlerCollection setupHttpsRedirect(WebAppContext webapp) { /*HANDLERS BUSINESS*/ SecuredRedirectHandler securedRedirect = new SecuredRedirectHandler(); // Establish all handlers that have a context ContextHandlerCollection contextHandlers = new ContextHandlerCollection(); webapp.setVirtualHosts(new String[]{"@secured"}); // handles requests that come through the sslConnector connector ... ContextHandler redirectHandler = new ContextHandler(); redirectHandler.setContextPath("/"); redirectHandler.setHandler(securedRedirect); redirectHandler.setVirtualHosts(new String[]{"@unsecured"}); // handls requests that come through the Connector (unsecured) ... contextHandlers.setHandlers(new Handler[]{redirectHandler, webapp}); return contextHandlers; }
public static void main( String[] args ) throws Exception { Server server = new Server( 8080 ); WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/jaxrs" ); ContextHandlerCollection servlet_contexts = new ContextHandlerCollection(); webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() ); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } ); server.setHandler( handlers ); server.start(); server.join(); }
private Server initJettyServer(ComponentRepository repo) { SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(getPort()); connector.setConfidentialPort(getSecurePort()); connector.setRequestHeaderSize(16384); Server jettyServer = new Server(); jettyServer.setConnectors(new Connector[] {connector}); ContextHandlerCollection contexts = new ContextHandlerCollection(); HandlerCollection handlers = new HandlerCollection(); handlers.addHandler(contexts); addHandlers(repo, jettyServer, contexts); jettyServer.setHandler(handlers); jettyServer.setStopAtShutdown(true); jettyServer.setGracefulShutdown(2000); jettyServer.setSendDateHeader(true); jettyServer.setSendServerVersion(true); ComponentInfo info = new ComponentInfo(Server.class, "jetty"); repo.registerComponent(info, jettyServer); repo.registerLifecycle(new ServerLifecycle(jettyServer)); return jettyServer; }
@BeforeClass public void startServer() throws Exception { int port = 49152 + RandomUtils.nextInt(65535 - 49152); String serverUrl = "http://localhost:" + port + "/jax"; SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(port); _jettyServer = new Server(); _jettyServer.setConnectors(new Connector[]{connector}); ContextHandlerCollection contexts = new ContextHandlerCollection(); HandlerCollection handlers = new HandlerCollection(); handlers.addHandler(contexts); WebAppContext ogWebAppContext = new WebAppContext("RemoteViewRunnerTest", "/"); org.springframework.core.io.Resource resource = new ClassPathResource("web-engine"); ogWebAppContext.setBaseResource(Resource.newResource(resource.getFile())); DataViewRunnerResource viewRunnerResource = new DataViewRunnerResource(new TestViewRunner()); ComponentRepository repo = new ComponentRepository(ComponentLogger.Console.VERBOSE); repo.getRestComponents().publishResource(viewRunnerResource); repo.getRestComponents().publishHelper(new FudgeObjectBinaryConsumer()); repo.getRestComponents().publishHelper(new FudgeObjectBinaryProducer()); ogWebAppContext.setEventListeners(new EventListener[]{new ComponentRepositoryServletContextListener(repo)}); handlers.addHandler(ogWebAppContext); _jettyServer.setHandler(handlers); _jettyServer.start(); _remoteViewRunner = new RemoteViewRunner(URI.create(serverUrl)); }
public RestfulServer(boolean loopback, int port, String applicationName, boolean sslEnabled, String keyStoreAlias, String keyStorePassword, String keyStorePath, int maxNumberOfThreads, int maxQueuedRequests) { this.applicationName = applicationName; int maxThreads = maxNumberOfThreads + ACCEPTORS + SELECTORS; BlockingArrayQueue<Runnable> queue = new BlockingArrayQueue<>(MIN_THREADS, MIN_THREADS, maxQueuedRequests); this.queuedThreadPool = new QueuedThreadPool(maxThreads, MIN_THREADS, IDLE_TIMEOUT, queue); this.server = new Server(queuedThreadPool); this.handlers = new ContextHandlerCollection(); server.addEventListener(new MBeanContainer(ManagementFactory.getPlatformMBeanServer())); server.setHandler(handlers); if (sslEnabled) { server.addConnector(makeSslConnector(keyStoreAlias, keyStorePassword, keyStorePath, port)); } else { server.addConnector(makeConnector(loopback, port)); } }
private static HandlerCollection createHandlers( final GatewayConfig config, final GatewayServices services, final ContextHandlerCollection contexts) { HandlerCollection handlers = new HandlerCollection(); RequestLogHandler logHandler = new RequestLogHandler(); logHandler.setRequestLog(new AccessHandler()); TraceHandler traceHandler = new TraceHandler(); traceHandler.setHandler(contexts); traceHandler.setTracedBodyFilter(System.getProperty("org.apache.knox.gateway.trace.body.status.filter")); CorrelationHandler correlationHandler = new CorrelationHandler(); correlationHandler.setHandler(traceHandler); DefaultTopologyHandler defaultTopoHandler = new DefaultTopologyHandler(config, services, contexts); handlers.setHandlers(new Handler[]{correlationHandler, defaultTopoHandler, logHandler}); return handlers; }
private void applyHandle(final String contextPath, final String warPath) { final ContextHandlerCollection handler = new ContextHandlerCollection(); final WebAppContext webapp = new WebAppContext(); webapp.setContextPath(contextPath); webapp.setDefaultsDescriptor(WEB_DEFAULT); if (StringUtils.isEmpty(warPath)) { webapp.setResourceBase(DEFAULT_RESOURCE_BASE); webapp.setDescriptor(DEFAULT_WEB_XML_PATH); } else { webapp.setWar(warPath); } applySessionHandler(webapp); handler.addHandler(webapp); super.setHandler(handler); }
private ContextHandlerCollection attachHandlers(final File staticsFolder, final Module... overrides) { final MoodcatHandler moodcatHandler = new MoodcatHandler(this, staticsFolder, overrides); final ResourceHandler resources = new ResourceHandler(); resources.setBaseResource(Resource.newResource(staticsFolder)); resources.setDirectoriesListed(false); resources.setCacheControl("max-age=3600"); final HashSessionManager hashSessionManager = new HashSessionManager(); hashSessionManager.setMaxInactiveInterval(SESSION_KEEP_ALIVE); final ContextHandlerCollection handlers = new ContextHandlerCollection(); // CHECKSTYLE:OFF handlers.addContext("/", "/").setHandler(resources); handlers.addContext("/", "/").setHandler(moodcatHandler); // CHECKSTYLE:ON return handlers; }
public ManagerHandler( final String baseURL, final Server server, final ConnectorStatistics connectorStats, final StatisticsHandler statHandler, final ContextHandlerCollection handlers, final String thumbnailsDirectoryName ) throws IOException, URISyntaxException { this.baseURL = baseURL; this.server = server; this.handlers = handlers; this.statHandler = statHandler; this.connectorStats = connectorStats; this.thumbnailsDirectoryName = thumbnailsDirectoryName; setContextPath( "/" + Constants.MANAGER_CONTEXT_NAME ); }
private static ContextHandlerCollection createHandlers( final String baseURL, final Map< String, String > dataSet, final String thumbnailsDirectoryName ) throws SpimDataException, IOException { final ContextHandlerCollection handlers = new ContextHandlerCollection(); for ( final Entry< String, String > entry : dataSet.entrySet() ) { final String name = entry.getKey(); final String xmlpath = entry.getValue(); final String context = "/" + name; final CellHandler ctx = new CellHandler( baseURL + context + "/", xmlpath, name, thumbnailsDirectoryName ); ctx.setContextPath( context ); handlers.addHandler( ctx ); } return handlers; }
/** * Big hack for the moment, not using properties for directory and port * Go through all the Jetty servers, find the one serving port 7657, * requested and add the .war to that one */ private void startWebApp(String app) { ContextHandlerCollection s = WebAppStarter.getConsoleServer(); if (s != null) { try { File path = new File(_context.getBaseDir(), "webapps"); path = new File(path, app + ".war"); WebAppStarter.startWebApp(_context, s, app, path.getAbsolutePath()); addFormNoticeNoEscape(_("WebApp") + " <a href=\"/" + app + "/\">" + _(app) + "</a> " + _("started") + '.'); } catch (Throwable e) { addFormError(_("Failed to start") + ' ' + _(app) + " " + e + '.'); _log.error("Failed to start webapp " + app, e); } return; } addFormError(_("Failed to find server.")); }
/** * stop it and remove the context * @throws just about anything, caller would be wise to catch Throwable */ static void stopWebApp(String appName) { ContextHandler wac = getWebApp(appName); if (wac == null) return; try { // not graceful is default in Jetty 6? wac.stop(); } catch (Exception ie) {} ContextHandlerCollection server = getConsoleServer(); if (server == null) return; try { server.removeHandler(wac); server.mapContexts(); } catch (IllegalStateException ise) {} }
/** @since Jetty 6 */ static ContextHandler getWebApp(String appName) { ContextHandlerCollection server = getConsoleServer(); if (server == null) return null; Handler handlers[] = server.getHandlers(); if (handlers == null) return null; String path = '/'+ appName; for (int i = 0; i < handlers.length; i++) { if (!(handlers[i] instanceof ContextHandler)) continue; ContextHandler ch = (ContextHandler) handlers[i]; if (path.equals(ch.getContextPath())) return ch; } return null; }
@Override protected void doPreStart() { ContextHandler welcomeContext = new ContextHandler("/"); welcomeContext.setContextPath("/"); welcomeContext.setHandler(new WelcomeHandler(gpapProjectsFolder)); ContextHandler projectsListContext = new ContextHandler("/stage_gplist_download"); projectsListContext.setHandler(new ProjectListHandler(gpapProjectsFolder)); ContextHandler projectDownloadContext = new ContextHandler("/stage_gpproject_download"); projectDownloadContext.setHandler(new ProjectDownloadHandler(gpapProjectsFolder)); ContextHandler projectUploadContext = new ContextHandler("/stage_gpproject_upload"); projectUploadContext.setHandler(new ProjectUploadHandler(gpapProjectsFolder)); ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.setHandlers(new Handler[]{welcomeContext, projectDownloadContext, projectUploadContext, projectsListContext}); _server.setHandler(contexts); }
protected void execute1(String component) throws Exception { System.out.println("Starting codeine "+component+" at version " + CodeineVersion.get()); injector = Guice.createInjector(getModules(component)); FilterHolder guiceFilter = new FilterHolder(injector.getInstance(GuiceFilter.class)); ServletContextHandler handler = createServletContextHandler(); handler.setContextPath("/"); FilterHolder crossHolder = new FilterHolder(new CrossOriginFilter()); crossHolder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "GET, POST, PUT, DELETE"); crossHolder.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "X-Requested-With,Origin,Content-Type,Accept,api_token"); handler.addFilter(crossHolder, "/api/*", EnumSet.allOf(DispatcherType.class)); handler.addFilter(crossHolder, "/api-with-token/*", EnumSet.allOf(DispatcherType.class)); handler.addFilter(guiceFilter, "/*", EnumSet.allOf(DispatcherType.class)); createAdditionalServlets(handler); ContextHandlerCollection contexts = createFileServerContexts(); contexts.addHandler(handler); int port = startServer(contexts); log.info("jetty started on port " + port); injector.getInstance(CodeineRuntimeInfo.class).setPort(port); execute(); }
private HttpBindManager() { // JSP 2.0 uses commons-logging, so also override that implementation. System.setProperty("org.apache.commons.logging.LogFactory", "org.jivesoftware.util.log.util.CommonsLogFactory"); JiveGlobals.migrateProperty(HTTP_BIND_ENABLED); JiveGlobals.migrateProperty(HTTP_BIND_PORT); JiveGlobals.migrateProperty(HTTP_BIND_SECURE_PORT); JiveGlobals.migrateProperty(HTTP_BIND_THREADS); JiveGlobals.migrateProperty(HTTP_BIND_FORWARDED); JiveGlobals.migrateProperty(HTTP_BIND_FORWARDED_FOR); JiveGlobals.migrateProperty(HTTP_BIND_FORWARDED_SERVER); JiveGlobals.migrateProperty(HTTP_BIND_FORWARDED_HOST); JiveGlobals.migrateProperty(HTTP_BIND_FORWARDED_HOST_NAME); JiveGlobals.migrateProperty(HTTP_BIND_CORS_ENABLED); JiveGlobals.migrateProperty(HTTP_BIND_CORS_ALLOW_ORIGIN); PropertyEventDispatcher.addListener(new HttpServerPropertyListener()); this.httpSessionManager = new HttpSessionManager(); contexts = new ContextHandlerCollection(); // setup the cache for the allowed origins this.setupAllowedOriginsMap(); }
public synchronized void start() throws WebServerException { if (server.isStarted()) { return; } // Package up all of the handlers into a ContextHandlerCollection to serve as the handler for // the server. List<? extends Handler> handlers = createHandlers(); ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.setHandlers(handlers.toArray(new Handler[0])); server.setHandler(contexts); try { server.start(); } catch (Exception e) { throw new WebServerException("Cannot start Websocket server.", e); } }
/** * Post deploy * @exception Throwable Thrown if an error occurs */ public void postDeploy() throws Throwable { if (server != null && !server.isRunning() && handlers != null && handlers.getHandlers() != null && handlers.getHandlers().length > 0) { try { ContextHandlerCollection chc = new ContextHandlerCollection(); chc.setHandlers(handlers.getHandlers()); server.setHandler(chc); server.start(); } catch (Exception e) { log.error("Could not start Jetty webserver", e); } } }
/** * Update state and start the server if necessary. * * @param artifactCache cache to serve. * @throws WebServerException */ public synchronized void updateAndStartIfNeeded(Optional<ArtifactCache> artifactCache) throws WebServerException { artifactCacheHandler.setArtifactCache(artifactCache); if (server.isStarted()) { return; } // Package up all of the handlers into a ContextHandlerCollection to serve as the handler for // the server. ImmutableList<? extends Handler> handlers = createHandlers(); ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.setHandlers(handlers.toArray(new Handler[0])); server.setHandler(contexts); try { server.start(); } catch (Exception e) { throw new WebServerException("Cannot start Websocket server.", e); } }
/** * Start/run the server. */ public void start() throws Exception { long startTime = System.currentTimeMillis(); System.out.println("**** Starting Server (" + getClass().getSimpleName() + ")"); preStart(); ContextHandlerCollection handlers = new ContextHandlerCollection(); addModulesToJetty(handlers); // Create the server. int serverPort = serverPort(); server = new Server(serverPort); server.setHandler(handlers); server.start(); long endTime = System.currentTimeMillis(); System.out.println("******* Started in " + (endTime - startTime) + "ms"); }
/** * Start/run the server. * @throws Exception when any exception occurs */ public void start() throws Exception { long startTime = System.currentTimeMillis(); ContextHandlerCollection handlers = new ContextHandlerCollection(); addModulesToJetty(handlers); // Create the server. int serverPort = serverPort(); System.out.println("**** Starting Gateway (" + getClass().getSimpleName() + ") on port: " + serverPort); server = new Server(serverPort); server.setHandler(handlers); server.start(); long endTime = System.currentTimeMillis(); System.out.println("******* Started in " + (endTime - startTime) + "ms"); }
/** * Configure the web application(s). * @param handlers * @throws Exception */ protected void addModulesToJetty(ContextHandlerCollection handlers) throws Exception { /* ************* * Gateway * ************* */ ServletContextHandler server = new ServletContextHandler(ServletContextHandler.SESSIONS); server.setContextPath("/"); server.addEventListener(new WarGatewayBootstrapper()); ServletHolder servlet = new ServletHolder(new WarGatewayServlet()); server.addServlet(servlet, "/gateway/*"); servlet = new ServletHolder(new HttpServletDispatcher()); servlet.setInitParameter("javax.ws.rs.Application", TestGatewayApplication.class.getName()); servlet.setInitParameter("resteasy.servlet.mapping.prefix", "/api"); servlet.setInitOrder(1); server.addServlet(servlet, "/api/*"); // Add the web contexts to jetty handlers.addHandler(server); }
/** * Start/run the server. */ public EchoServer start() throws Exception { long startTime = System.currentTimeMillis(); System.out.println("**** Starting Server (" + getClass().getSimpleName() + ") on port " + port); //$NON-NLS-1$ //$NON-NLS-2$ preStart(); ContextHandlerCollection handlers = new ContextHandlerCollection(); addModulesToJetty(handlers); // Create the server. server = new Server(port); server.setHandler(handlers); server.start(); long endTime = System.currentTimeMillis(); System.out.println("******* Started in " + (endTime - startTime) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ return this; }
/** * Start/run the server. */ public void go() throws Exception { long startTime = System.currentTimeMillis(); System.out.println("**** Starting Development Server (" + getClass().getSimpleName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ preConfig(); DevServerEnvironment environment = createDevEnvironment(); addModules(environment); ContextHandlerCollection handlers = new ContextHandlerCollection(); addModulesToJetty(environment, handlers); environment.createAppConfigs(); // Create the server. int serverPort = serverPort(); Server server = new Server(serverPort); server.setHandler(handlers); server.start(); long endTime = System.currentTimeMillis(); System.out.println("******* Started in " + (endTime - startTime) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ postStart(environment); server.join(); }
/** * @see org.overlord.commons.dev.server.DevServer#addModulesToJetty(org.overlord.commons.dev.server.DevServerEnvironment, org.eclipse.jetty.server.handler.ContextHandlerCollection) */ @Override protected void addModulesToJetty(DevServerEnvironment environment, ContextHandlerCollection handlers) throws Exception { if (environment.isModuleInIDE(getErraiModuleId()) && !environment.isUsingClassHiderAgent()) { System.out.println("******************************************************************"); //$NON-NLS-1$ System.out.println("WARNING: we detected that you are running from within an IDE"); //$NON-NLS-1$ System.out.println(" but are not using the Errai class hiding agent. As"); //$NON-NLS-1$ System.out.println(" a result, you may see a number of Weld related errors "); //$NON-NLS-1$ System.out.println(" during startup. This is due to client-only classes"); //$NON-NLS-1$ System.out.println(" being included on the server classpath. To address"); //$NON-NLS-1$ System.out.println(" this issue, please see:"); //$NON-NLS-1$ System.out.println(" "); //$NON-NLS-1$ System.out.println(" https://github.com/jfuerth/client-local-class-hider"); //$NON-NLS-1$ System.out.println(" "); //$NON-NLS-1$ System.out.println(" The above is a Java Agent that will hide the client-"); //$NON-NLS-1$ System.out.println(" only classes from Weld, thereby suppressing the errors."); //$NON-NLS-1$ System.out.println("******************************************************************"); //$NON-NLS-1$ try {Thread.sleep(5000);} catch (InterruptedException e) {} } }
@Override public void run() { System.out.println("Creating ContextHandler"); ContextHandlerCollection contexts = new ContextHandlerCollection(); System.out.println("Building Web Application Context"); contexts.setHandlers(new Handler[] { new AppContextBuilder().buildWebAppContext()}); System.out.println("Setting Handler"); jettyServer.setHandler(contexts); try { System.out.println("Starting jetty"); jettyServer.start(); } catch (Exception e) { e.printStackTrace(); System.exit(0); } }
public static Server startControlledBounceproxy(String bpId) throws Exception { final int port = ServletUtil.findFreePort(); final String bpUrl = "http://localhost:" + port + "/bounceproxy/"; System.setProperty("joynr.bounceproxy.id", bpId); System.setProperty("joynr.bounceproxy.controller.baseurl", System.getProperty(MessagingPropertyKeys.BOUNCE_PROXY_URL)); System.setProperty("joynr.bounceproxy.url4cc", bpUrl); System.setProperty("joynr.bounceproxy.url4bpc", bpUrl); ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.setHandlers(new Handler[]{ createControlledBounceproxyWebApp("", null) }); Server server = startServer(contexts, port); System.clearProperty("joynr.bounceproxy.id"); System.clearProperty("joynr.bounceproxy.controller.baseurl"); System.clearProperty("joynr.bounceproxy.url4cc"); System.clearProperty("joynr.bounceproxy.url4bpc"); return server; }
private static Server startServer(ContextHandlerCollection contexts, int port) throws Exception { System.setProperty(MessagingPropertyKeys.PROPERTY_SERVLET_HOST_PATH, "http://localhost:" + port); setBounceProxyUrl(); setDirectoriesUrl(); logger.info("HOST PATH: {}", System.getProperty(MessagingPropertyKeys.PROPERTY_SERVLET_HOST_PATH)); final Server jettyServer = new Server(); ServerConnector connector = new ServerConnector(jettyServer, new HttpConnectionFactory(new HttpConfiguration())); connector.setPort(port); connector.setAcceptQueueSize(1); jettyServer.setConnectors(new Connector[]{ connector }); jettyServer.setHandler(contexts); jettyServer.start(); logger.trace("Started jetty server:\n{}", jettyServer.dump()); return jettyServer; }
public void registerServlet(String context, Servlet servlet, Dictionary dictionary, HttpContext httpContext) throws ServletException, NamespaceException { ContextHandlerCollection contexts = new ContextHandlerCollection(); server.setHandler(contexts); ServletContextHandler root = new ServletContextHandler(contexts, "/", ServletContextHandler.SESSIONS); ServletHolder servletHolder = new ServletHolder(servlet); root.addServlet(servletHolder, context); if (!server.getServer().getState().equals(server.STARTED)) { try { server.start(); } catch (Exception e) { e.printStackTrace(); } } }