Java Code Examples for org.mortbay.jetty.nio.SelectChannelConnector#setPort()
The following examples show how to use
org.mortbay.jetty.nio.SelectChannelConnector#setPort() .
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: JettyLauncher.java From nextreports-server with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { Server server = new Server(); SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(PORT); server.addConnector(connector); server.setStopAtShutdown(true); // the orders of handlers is very important! ContextHandler contextHandler = new ContextHandler(); contextHandler.setContextPath("/reports"); contextHandler.setResourceBase("./reports/"); contextHandler.addHandler(new ResourceHandler()); server.addHandler(contextHandler); server.addHandler(new WebAppContext("webapp", "/nextreports-server")); long t = System.currentTimeMillis(); server.start(); t = System.currentTimeMillis() - t; String version = server.getClass().getPackage().getImplementationVersion(); System.out.println("Started Jetty Server " + version + " on port " + PORT + " in " + t / 1000 + "s"); server.join(); }
Example 2
Source File: Jetty6PluginServer.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public Object createDefaultConnector(int port) throws Exception { SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(port); connector.setMaxIdleTime(DEFAULT_MAX_IDLE_TIME); return connector; }
Example 3
Source File: ProxyHttpServer.java From hadoop-gpu with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ protected Connector createBaseListener(Configuration conf) throws IOException { final String sAddr; if (null == (sAddr = conf.get("proxy.http.test.listener.addr"))) { SslSocketConnector sslListener = new SslSocketConnector(); sslListener.setKeystore(conf.get("ssl.server.keystore.location")); sslListener.setPassword(conf.get("ssl.server.keystore.password", "")); sslListener.setKeyPassword(conf.get("ssl.server.keystore.keypassword", "")); sslListener.setKeystoreType(conf.get("ssl.server.keystore.type", "jks")); sslListener.setNeedClientAuth(true); System.setProperty("javax.net.ssl.trustStore", conf.get("ssl.server.truststore.location", "")); System.setProperty("javax.net.ssl.trustStorePassword", conf.get("ssl.server.truststore.password", "")); System.setProperty("javax.net.ssl.trustStoreType", conf.get("ssl.server.truststore.type", "jks")); return sslListener; } // unit test InetSocketAddress proxyAddr = NetUtils.createSocketAddr(sAddr); SelectChannelConnector testlistener = new SelectChannelConnector(); testlistener.setUseDirectBuffers(false); testlistener.setHost(proxyAddr.getHostName()); testlistener.setPort(proxyAddr.getPort()); return testlistener; }
Example 4
Source File: ProxyHttpServer.java From RDFS with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ protected Connector createBaseListener(Configuration conf) throws IOException { final String sAddr; if (null == (sAddr = conf.get("proxy.http.test.listener.addr"))) { SslSocketConnector sslListener = new SslSocketConnector(); sslListener.setKeystore(conf.get("ssl.server.keystore.location")); sslListener.setPassword(conf.get("ssl.server.keystore.password", "")); sslListener.setKeyPassword(conf.get("ssl.server.keystore.keypassword", "")); sslListener.setKeystoreType(conf.get("ssl.server.keystore.type", "jks")); sslListener.setNeedClientAuth(true); System.setProperty("javax.net.ssl.trustStore", conf.get("ssl.server.truststore.location", "")); System.setProperty("javax.net.ssl.trustStorePassword", conf.get("ssl.server.truststore.password", "")); System.setProperty("javax.net.ssl.trustStoreType", conf.get("ssl.server.truststore.type", "jks")); return sslListener; } // unit test InetSocketAddress proxyAddr = NetUtils.createSocketAddr(sAddr); SelectChannelConnector testlistener = new SelectChannelConnector(); testlistener.setUseDirectBuffers(false); testlistener.setHost(proxyAddr.getHostName()); testlistener.setPort(proxyAddr.getPort()); return testlistener; }
Example 5
Source File: JettyServer.java From fiware-cygnus with GNU Affero General Public License v3.0 | 5 votes |
/** * Constructor. * @param mgmtIfPort * @param guiPort * @param handler * @param ipv6 */ public JettyServer(int mgmtIfPort, int guiPort, AbstractHandler handler, boolean ipv6) { // create the server server = new Server(); // add the Management Interface connector SelectChannelConnector conn1 = new SelectChannelConnector(); if (ipv6) { conn1.setHost("::0"); } else { conn1.setHost("0.0.0.0"); } // if else conn1.setPort(mgmtIfPort); server.addConnector(conn1); if (guiPort != 0) { // add the GUI connector SelectChannelConnector conn2 = new SelectChannelConnector(); if (ipv6) { conn2.setHost("::0"); } else { conn2.setHost("0.0.0.0"); } // if else conn2.setPort(guiPort); server.addConnector(conn2); } // if // set the handler server.setHandler(handler); }
Example 6
Source File: DevServer.java From yawp with MIT License | 5 votes |
private SelectChannelConnector createConnector() throws IOException { SelectChannelConnector connector = new SelectChannelConnector(); connector.setHost(mojo.getAddress()); connector.setPort(mojo.getPort()); connector.setSoLingerTime(0); connector.open(); return connector; }
Example 7
Source File: HttpConnectorProvider.java From incubator-myriad with Apache License 2.0 | 5 votes |
@Override public Connector get() { SelectChannelConnector ret = new SelectChannelConnector(); ret.setName("Myriad"); ret.setHost("0.0.0.0"); ret.setPort(myriadConf.getRestApiPort()); return ret; }
Example 8
Source File: JettyContainer.java From dubbox with Apache License 2.0 | 5 votes |
public void start() { String serverPort = ConfigUtils.getProperty(JETTY_PORT); int port; if (serverPort == null || serverPort.length() == 0) { port = DEFAULT_JETTY_PORT; } else { port = Integer.parseInt(serverPort); } connector = new SelectChannelConnector(); connector.setPort(port); ServletHandler handler = new ServletHandler(); String resources = ConfigUtils.getProperty(JETTY_DIRECTORY); if (resources != null && resources.length() > 0) { FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT); resourceHolder.setInitParameter("resources", resources); } ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*"); pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES)); pageHolder.setInitOrder(2); Server server = new Server(); server.addConnector(connector); server.addHandler(handler); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e); } }
Example 9
Source File: Jetty6PluginServer.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public Object createDefaultConnector(int port) throws Exception { SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(port); connector.setMaxIdleTime(DEFAULT_MAX_IDLE_TIME); return connector; }
Example 10
Source File: JettyContainer.java From dubbox with Apache License 2.0 | 5 votes |
public void start() { String serverPort = ConfigUtils.getProperty(JETTY_PORT); int port; if (serverPort == null || serverPort.length() == 0) { port = DEFAULT_JETTY_PORT; } else { port = Integer.parseInt(serverPort); } connector = new SelectChannelConnector(); connector.setPort(port); ServletHandler handler = new ServletHandler(); String resources = ConfigUtils.getProperty(JETTY_DIRECTORY); if (resources != null && resources.length() > 0) { FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT); resourceHolder.setInitParameter("resources", resources); } ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*"); pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES)); pageHolder.setInitOrder(2); Server server = new Server(); server.addConnector(connector); server.addHandler(handler); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e); } }
Example 11
Source File: JettyContainer.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public void start() { String serverPort = ConfigUtils.getProperty(JETTY_PORT); int port; if (serverPort == null || serverPort.length() == 0) { port = DEFAULT_JETTY_PORT; } else { port = Integer.parseInt(serverPort); } connector = new SelectChannelConnector(); connector.setPort(port); ServletHandler handler = new ServletHandler(); String resources = ConfigUtils.getProperty(JETTY_DIRECTORY); if (resources != null && resources.length() > 0) { FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT); resourceHolder.setInitParameter("resources", resources); } ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*"); pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES)); pageHolder.setInitOrder(2); Server server = new Server(); server.addConnector(connector); server.addHandler(handler); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e); } }
Example 12
Source File: JettyContainer.java From dubbox with Apache License 2.0 | 5 votes |
public void start() { String serverPort = ConfigUtils.getProperty(JETTY_PORT); int port; if (serverPort == null || serverPort.length() == 0) { port = DEFAULT_JETTY_PORT; } else { port = Integer.parseInt(serverPort); } connector = new SelectChannelConnector(); connector.setPort(port); ServletHandler handler = new ServletHandler(); String resources = ConfigUtils.getProperty(JETTY_DIRECTORY); if (resources != null && resources.length() > 0) { FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT); resourceHolder.setInitParameter("resources", resources); } ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*"); pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES)); pageHolder.setInitOrder(2); Server server = new Server(); server.addConnector(connector); server.addHandler(handler); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e); } }
Example 13
Source File: Jetty6PluginServer.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public Object createDefaultConnector(int port) throws Exception { SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(port); connector.setMaxIdleTime(DEFAULT_MAX_IDLE_TIME); return connector; }
Example 14
Source File: Jetty6PluginServer.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public Object createDefaultConnector(int port) throws Exception { SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(port); connector.setMaxIdleTime(DEFAULT_MAX_IDLE_TIME); return connector; }
Example 15
Source File: SubsonicDeployer.java From subsonic with GNU General Public License v3.0 | 4 votes |
private void deployWebApp() { try { Server server = new Server(); SelectChannelConnector connector = new SelectChannelConnector(); connector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS); connector.setHeaderBufferSize(HEADER_BUFFER_SIZE); connector.setHost(getHost()); connector.setPort(getPort()); if (isHttpsEnabled()) { connector.setConfidentialPort(getHttpsPort()); } server.addConnector(connector); if (isHttpsEnabled()) { SslSocketConnector sslConnector = new SslSocketConnector(); sslConnector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS); sslConnector.setHeaderBufferSize(HEADER_BUFFER_SIZE); sslConnector.setHost(getHost()); sslConnector.setPort(getHttpsPort()); sslConnector.setKeystore(System.getProperty("subsonic.ssl.keystore", getClass().getResource("/subsonic.keystore").toExternalForm())); sslConnector.setPassword(System.getProperty("subsonic.ssl.password", "subsonic")); server.addConnector(sslConnector); } WebAppContext context = new WebAppContext(); context.setTempDirectory(getJettyDirectory()); context.setContextPath(getContextPath()); context.setWar(getWar()); context.setOverrideDescriptor("/web-jetty.xml"); if (isHttpsEnabled()) { // Allow non-https for streaming and cover art (for Chromecast, UPnP, Sonos etc) context.getSecurityHandler().setConstraintMappings(new ConstraintMapping[]{ createConstraintMapping("/stream", Constraint.DC_NONE), createConstraintMapping("/coverArt.view", Constraint.DC_NONE), createConstraintMapping("/ws/*", Constraint.DC_NONE), createConstraintMapping("/sonos/*", Constraint.DC_NONE), createConstraintMapping("/", Constraint.DC_CONFIDENTIAL) }); } server.addHandler(context); server.start(); System.err.println("Subsonic running on: " + getUrl()); if (isHttpsEnabled()) { System.err.println(" and: " + getHttpsUrl()); } } catch (Throwable x) { x.printStackTrace(); exception = x; } }
Example 16
Source File: JettyHttpServer.java From dubbox with Apache License 2.0 | 4 votes |
public JettyHttpServer(URL url, final HttpHandler handler){ super(url, handler); // modified by lishen this.url = url; // TODO we should leave this setting to slf4j Log.setLog(new StdErrLog()); Log.getLog().setDebugEnabled(false); DispatcherServlet.addHttpHandler(url.getPort(), handler); int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS); QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setDaemon(true); threadPool.setMaxThreads(threads); threadPool.setMinThreads(threads); SelectChannelConnector connector = new SelectChannelConnector(); if (! url.isAnyHost() && NetUtils.isValidLocalHost(url.getHost())) { connector.setHost(url.getHost()); } connector.setPort(url.getPort()); server = new Server(); server.setThreadPool(threadPool); server.addConnector(connector); ServletHandler servletHandler = new ServletHandler(); ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*"); servletHolder.setInitOrder(2); // modified by lishen // dubbo's original impl can't support the use of ServletContext // server.addHandler(servletHandler); // TODO Context.SESSIONS is the best option here? Context context = new Context(server, "/", Context.SESSIONS); context.setServletHandler(servletHandler); ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext()); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: " + e.getMessage(), e); } }
Example 17
Source File: JettyHttpServer.java From dubbox with Apache License 2.0 | 4 votes |
public JettyHttpServer(URL url, final HttpHandler handler){ super(url, handler); // modified by lishen this.url = url; // TODO we should leave this setting to slf4j Log.setLog(new StdErrLog()); Log.getLog().setDebugEnabled(false); DispatcherServlet.addHttpHandler(url.getPort(), handler); int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS); QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setDaemon(true); threadPool.setMaxThreads(threads); threadPool.setMinThreads(threads); SelectChannelConnector connector = new SelectChannelConnector(); if (! url.isAnyHost() && NetUtils.isValidLocalHost(url.getHost())) { connector.setHost(url.getHost()); } connector.setPort(url.getPort()); server = new Server(); server.setThreadPool(threadPool); server.addConnector(connector); ServletHandler servletHandler = new ServletHandler(); ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*"); servletHolder.setInitOrder(2); // modified by lishen // dubbo's original impl can't support the use of ServletContext // server.addHandler(servletHandler); // TODO Context.SESSIONS is the best option here? Context context = new Context(server, "/", Context.SESSIONS); context.setServletHandler(servletHandler); ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext()); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: " + e.getMessage(), e); } }
Example 18
Source File: JettyHttpServer.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
public JettyHttpServer(URL url, final HttpHandler handler){ super(url, handler); // modified by lishen this.url = url; // TODO we should leave this setting to slf4j Log.setLog(new StdErrLog()); Log.getLog().setDebugEnabled(false); DispatcherServlet.addHttpHandler(url.getPort(), handler); int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS); QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setDaemon(true); threadPool.setMaxThreads(threads); threadPool.setMinThreads(threads); SelectChannelConnector connector = new SelectChannelConnector(); if (! url.isAnyHost() && NetUtils.isValidLocalHost(url.getHost())) { connector.setHost(url.getHost()); } connector.setPort(url.getPort()); server = new Server(); server.setThreadPool(threadPool); server.addConnector(connector); ServletHandler servletHandler = new ServletHandler(); ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*"); servletHolder.setInitOrder(2); // modified by lishen // dubbo's original impl can't support the use of ServletContext // server.addHandler(servletHandler); // TODO Context.SESSIONS is the best option here? Context context = new Context(server, "/", Context.SESSIONS); context.setServletHandler(servletHandler); ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext()); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: " + e.getMessage(), e); } }
Example 19
Source File: JettyHttpServer.java From dubbox with Apache License 2.0 | 4 votes |
public JettyHttpServer(URL url, final HttpHandler handler){ super(url, handler); // modified by lishen this.url = url; // TODO we should leave this setting to slf4j Log.setLog(new StdErrLog()); Log.getLog().setDebugEnabled(false); DispatcherServlet.addHttpHandler(url.getPort(), handler); int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS); QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setDaemon(true); threadPool.setMaxThreads(threads); threadPool.setMinThreads(threads); SelectChannelConnector connector = new SelectChannelConnector(); if (! url.isAnyHost() && NetUtils.isValidLocalHost(url.getHost())) { connector.setHost(url.getHost()); } connector.setPort(url.getPort()); server = new Server(); server.setThreadPool(threadPool); server.addConnector(connector); ServletHandler servletHandler = new ServletHandler(); ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*"); servletHolder.setInitOrder(2); // modified by lishen // dubbo's original impl can't support the use of ServletContext // server.addHandler(servletHandler); // TODO Context.SESSIONS is the best option here? Context context = new Context(server, "/", Context.SESSIONS); context.setServletHandler(servletHandler); ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext()); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: " + e.getMessage(), e); } }
Example 20
Source File: JettyServer.java From athena-rest with Apache License 2.0 | 3 votes |
protected void doStart() throws Exception { server = new Server(); if (this.minThreads != -1 && this.maxThreads != -1) { BoundedThreadPool btp = new BoundedThreadPool(); server.setThreadPool(btp); } SelectChannelConnector connector = new SelectChannelConnector(); // Set some timeout options to make debugging easier. connector.setSoLingerTime(-1); connector.setPort(port); server.setConnectors(new Connector[] { connector }); WebAppContext wac = new WebAppContext(); wac.setServer(server); wac.setContextPath(contextPath); wac.setWar(webappPath); server.setHandler(wac); log.info("Starting jetty server actually."); server.start(); }