Java Code Examples for org.eclipse.jetty.server.Server#setAttribute()
The following examples show how to use
org.eclipse.jetty.server.Server#setAttribute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProxyAllHttpServer.java From sylph with Apache License 2.0 | 6 votes |
public void start() throws Exception { int maxFormContentSize = 100; // 创建Server Server server = new Server(proxyHttpPort); server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", maxFormContentSize); ServletContextHandler contextHandler = new ServletContextHandler( ServletContextHandler.NO_SESSIONS); contextHandler.setContextPath("/"); contextHandler.addServlet(ProxyAll.class, "/*"); server.setHandler(contextHandler); server.start(); logger.info("Web proxy Server started... the port " + proxyHttpPort); }
Example 2
Source File: JettyServer.java From freeacs with MIT License | 5 votes |
/** * Creates a Jetty server with supplied thread pool. * * @param threadPool thread pool * @return a new jetty server instance */ @Override public Server create(ThreadPool threadPool) { Server server = threadPool != null ? new Server(threadPool) : new Server(); server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", maxPostSize); server.setAttribute("org.eclipse.jetty.server.Request.maxFormKeys", maxFormKeys); return server; }
Example 3
Source File: YanagishimaServer.java From yanagishima with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { Properties properties = loadProperties(args, new OptionParser()); YanagishimaConfig config = new YanagishimaConfig(properties); Injector injector = createInjector(properties); createTables(injector.getInstance(TinyORM.class), config.getDatabaseType()); Server server = new Server(config.getServerPort()); server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", -1); ServletContextHandler servletContextHandler = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS); servletContextHandler.addFilter(new FilterHolder(new YanagishimaFilter(config.corsEnabled(), config.getAuditHttpHeaderName())), "/*", EnumSet.of(DispatcherType.REQUEST)); servletContextHandler.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class)); servletContextHandler.addServlet(DefaultServlet.class, "/"); servletContextHandler.setResourceBase(properties.getProperty("web.resource.dir", "web")); LOGGER.info("Yanagishima Server started..."); server.start(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { LOGGER.info("Shutting down Yanagishima Server..."); try { server.stop(); server.destroy(); } catch (Exception e) { LOGGER.error("Error while shutting down Yanagishima Server", e); } } }); LOGGER.info("Yanagishima Server running port " + config.getServerPort()); }
Example 4
Source File: MultiSessionAttributeAdapter.java From brooklyn-server with Apache License 2.0 | 5 votes |
protected SessionHandler findPreferredBundleHandler(Session localSession, Server server, Handler[] handlers) { if (PREFERRED_SYMBOLIC_NAME==null) return null; SessionHandler preferredHandler = null; if (handlers != null) { for (Handler handler: handlers) { SessionHandler sh = (SessionHandler) handler; ContextHandler.Context ctx = getContext(sh); if (ctx!=null) { BundleContext bundle = (BundleContext) ctx.getAttribute("osgi-bundlecontext"); if (bundle!=null) { if (PREFERRED_SYMBOLIC_NAME.equals(bundle.getBundle().getSymbolicName())) { if (preferredHandler==null) { preferredHandler = sh; server.setAttribute(KEY_PREFERRED_SESSION_HANDLER_INSTANCE, sh); log.trace("Recording "+info(sh)+" as server-wide preferred session handler"); } else { log.warn("Multiple preferred session handlers detected; keeping "+info(preferredHandler)+", ignoring "+info(sh)); } } } } } } if (preferredHandler==null) { log.warn("Did not find handler in bundle "+PREFERRED_SYMBOLIC_NAME+"; not using server-wide handler; check whether bundle is installed!"); } return preferredHandler; }
Example 5
Source File: VRaptorServer.java From mamute with Apache License 2.0 | 5 votes |
private static Server createServer() { String webPort = getPort(); if (webPort == null || webPort.isEmpty()) { webPort = System.getProperty("server.port", "8080"); } Server server = new Server(Integer.valueOf(webPort)); String webHost = getHost(); if (webHost == null || webHost.isEmpty()) { webHost = System.getProperty("server.host", "0.0.0.0"); } server.getConnectors()[0].setHost(webHost); server.setAttribute("jetty.host", webHost); return server; }
Example 6
Source File: CenterServerTools.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
public static Server start(CenterServer centerServer) throws Exception { cleanWorkDirectory(); HandlerList handlers = new HandlerList(); File war = new File(Config.dir_store(), x_program_center.class.getSimpleName() + ".war"); File dir = new File(Config.dir_servers_centerServer_work(true), x_program_center.class.getSimpleName()); if (war.exists()) { modified(war, dir); QuickStartWebApp webApp = new QuickStartWebApp(); webApp.setAutoPreconfigure(false); webApp.setDisplayName(x_program_center.class.getSimpleName()); webApp.setContextPath("/" + x_program_center.class.getSimpleName()); webApp.setResourceBase(dir.getAbsolutePath()); webApp.setDescriptor(new File(dir, "WEB-INF/web.xml").getAbsolutePath()); webApp.setExtraClasspath(calculateExtraClassPath(x_program_center.class)); webApp.getInitParams().put("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false"); webApp.getInitParams().put("org.eclipse.jetty.jsp.precompiled", "true"); webApp.getInitParams().put("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); /* stat */ if (centerServer.getStatEnable()) { FilterHolder statFilterHolder = new FilterHolder(new WebStatFilter()); statFilterHolder.setInitParameter("exclusions", centerServer.getStatExclusions()); webApp.addFilter(statFilterHolder, "/*", EnumSet.of(DispatcherType.REQUEST)); ServletHolder statServletHolder = new ServletHolder(StatViewServlet.class); statServletHolder.setInitParameter("sessionStatEnable", "false"); webApp.addServlet(statServletHolder, "/druid/*"); } /* stat end */ handlers.addHandler(webApp); } else { throw new Exception("centerServer war not exist."); } QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setMinThreads(CENTERSERVER_THREAD_POOL_SIZE_MIN); threadPool.setMaxThreads(CENTERSERVER_THREAD_POOL_SIZE_MAX); Server server = new Server(threadPool); server.setAttribute("maxFormContentSize", centerServer.getMaxFormContent() * 1024 * 1024); if (centerServer.getSslEnable()) { addHttpsConnector(server, centerServer.getPort()); } else { addHttpConnector(server, centerServer.getPort()); } GzipHandler gzipHandler = new GzipHandler(); gzipHandler.setHandler(handlers); server.setHandler(gzipHandler); server.setDumpAfterStart(false); server.setDumpBeforeStop(false); server.setStopAtShutdown(true); server.start(); Thread.sleep(1000); System.out.println("****************************************"); System.out.println("* center server start completed."); System.out.println("* port: " + centerServer.getPort() + "."); System.out.println("****************************************"); return server; }
Example 7
Source File: JettyLauncher.java From JobX with Apache License 2.0 | 4 votes |
@Override public void start(boolean devMode, int port) throws Exception { Server server = new Server(new QueuedThreadPool(Constants.WEB_THREADPOOL_SIZE)); WebAppContext appContext = new WebAppContext(); String resourceBasePath = ""; //开发者模式 if (devMode) { String artifact = MavenUtils.get(Thread.currentThread().getContextClassLoader()).getArtifactId(); resourceBasePath = artifact + "/src/main/webapp"; } appContext.setDescriptor(resourceBasePath + "WEB-INF/web.xml"); appContext.setResourceBase(resourceBasePath); appContext.setExtractWAR(true); //init param appContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); if (CommonUtils.isWindows()) { appContext.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false"); } //for jsp support appContext.addBean(new JettyJspParser(appContext)); appContext.addServlet(JettyJspServlet.class, "*.jsp"); appContext.setContextPath("/"); appContext.getServletContext().setExtendedListenerTypes(true); appContext.setParentLoaderPriority(true); appContext.setThrowUnavailableOnStartupException(true); appContext.setConfigurationDiscovered(true); appContext.setClassLoader(Thread.currentThread().getContextClassLoader()); ServerConnector connector = new ServerConnector(server); connector.setHost("localhost"); connector.setPort(port); server.setConnectors(new Connector[]{connector}); server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", 1024 * 1024 * 1024); server.setDumpAfterStart(false); server.setDumpBeforeStop(false); server.setStopAtShutdown(true); server.setHandler(appContext); logger.info("[JobX] JettyLauncher starting..."); server.start(); }
Example 8
Source File: JettyServerWrapper.java From cougar with Apache License 2.0 | 4 votes |
public void initialiseConnectors() throws Exception { threadPool = new QueuedThreadPool(); threadPool.setMaxThreads(maxThreads); threadPool.setMinThreads(minThreads); threadPool.setName("JettyThread"); jettyServer = new Server(threadPool); jettyServer.setStopAtShutdown(true); MBeanContainer container = new MBeanContainer(mbeanServer); jettyServer.addBean(container); LowResourceMonitor lowResourcesMonitor = new LowResourceMonitor(jettyServer); lowResourcesMonitor.setPeriod(lowResourcesPeriod); lowResourcesMonitor.setLowResourcesIdleTimeout(lowResourcesIdleTime); lowResourcesMonitor.setMonitorThreads(lowResourcesMonitorThreads); lowResourcesMonitor.setMaxConnections(lowResourcesMaxConnections); lowResourcesMonitor.setMaxMemory(lowResourcesMaxMemory); lowResourcesMonitor.setMaxLowResourcesTime(lowResourcesMaxTime); jettyServer.addBean(lowResourcesMonitor); // US24803 - Needed for preventing Hashtable key collision DoS CVE-2012-2739 jettyServer.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", maxFormContentSize); List<Connector> connectors = new ArrayList<Connector>(); if (httpPort != -1) { httpConfiguration = createHttpConfiguration(); setBufferSizes(httpConfiguration); if (httpForwarded) { httpConfiguration.addCustomizer(new ForwardedRequestCustomizer()); } httpConnector = createHttpConnector(jettyServer, httpConfiguration, httpAcceptors, httpSelectors); httpConnector.setPort(httpPort); httpConnector.setReuseAddress(httpReuseAddress); httpConnector.setIdleTimeout(httpMaxIdle); httpConnector.setAcceptQueueSize(httpAcceptQueueSize); httpConnector.addBean(new ConnectorStatistics()); connectors.add(httpConnector); } if (httpsPort != -1) { SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStorePath(httpsKeystore.getFile().getCanonicalPath()); sslContextFactory.setKeyStoreType(httpsKeystoreType); sslContextFactory.setKeyStorePassword(httpsKeyPassword); if (StringUtils.isNotBlank(httpsCertAlias)) { sslContextFactory.setCertAlias(httpsCertAlias); } sslContextFactory.setKeyManagerPassword(httpsKeyPassword); // if you need it then you defo want it sslContextFactory.setWantClientAuth(httpsNeedClientAuth || httpsWantClientAuth); sslContextFactory.setNeedClientAuth(httpsNeedClientAuth); sslContextFactory.setRenegotiationAllowed(httpsAllowRenegotiate); httpsConfiguration = createHttpConfiguration(); setBufferSizes(httpsConfiguration); if (httpsForwarded) { httpsConfiguration.addCustomizer(new ForwardedRequestCustomizer()); } httpsConnector = createHttpsConnector(jettyServer, httpsConfiguration, httpsAcceptors, httpsSelectors, sslContextFactory); httpsConnector.setPort(httpsPort); httpsConnector.setReuseAddress(httpsReuseAddress); httpsConnector.setIdleTimeout(httpsMaxIdle); httpsConnector.setAcceptQueueSize(httpsAcceptQueueSize); httpsConnector.addBean(new ConnectorStatistics()); mbeanServer.registerMBean(getKeystoreCertificateChains(), new ObjectName("CoUGAR.https:name=keyStore")); // truststore is not required if we don't want client auth if (httpsWantClientAuth) { sslContextFactory.setTrustStorePath(httpsTruststore.getFile().getCanonicalPath()); sslContextFactory.setTrustStoreType(httpsTruststoreType); sslContextFactory.setTrustStorePassword(httpsTrustPassword); mbeanServer.registerMBean(getTruststoreCertificateChains(), new ObjectName("CoUGAR.https:name=trustStore")); } connectors.add(httpsConnector); } if (connectors.size() == 0) { throw new IllegalStateException("HTTP transport requires at least one port enabled to function correctly."); } jettyServer.setConnectors(connectors.toArray(new Connector[connectors.size()])); }