org.mortbay.jetty.Connector Java Examples
The following examples show how to use
org.mortbay.jetty.Connector.
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: HttpServer2.java From big-c with Apache License 2.0 | 6 votes |
@InterfaceAudience.Private public static Connector createDefaultChannelConnector() { SelectChannelConnector ret = new SelectChannelConnectorWithSafeStartup(); ret.setLowResourceMaxIdleTime(10000); ret.setAcceptQueueSize(128); ret.setResolveNames(false); ret.setUseDirectBuffers(false); if(Shell.WINDOWS) { // result of setting the SO_REUSEADDR flag is different on Windows // http://msdn.microsoft.com/en-us/library/ms740621(v=vs.85).aspx // without this 2 NN's can start on the same machine and listen on // the same port with indeterminate routing of incoming requests to them ret.setReuseAddress(false); } ret.setHeaderBufferSize(1024*64); return ret; }
Example #2
Source File: HttpServer.java From big-c with Apache License 2.0 | 6 votes |
@InterfaceAudience.Private public static Connector createDefaultChannelConnector() { SelectChannelConnector ret = new SelectChannelConnectorWithSafeStartup(); ret.setLowResourceMaxIdleTime(10000); ret.setAcceptQueueSize(128); ret.setResolveNames(false); ret.setUseDirectBuffers(false); if(Shell.WINDOWS) { // result of setting the SO_REUSEADDR flag is different on Windows // http://msdn.microsoft.com/en-us/library/ms740621(v=vs.85).aspx // without this 2 NN's can start on the same machine and listen on // the same port with indeterminate routing of incoming requests to them ret.setReuseAddress(false); } ret.setHeaderBufferSize(1024*64); return ret; }
Example #3
Source File: TestJettyHelper.java From big-c with Apache License 2.0 | 6 votes |
private Server createJettyServer() { try { InetAddress localhost = InetAddress.getByName("localhost"); String host = "localhost"; ServerSocket ss = new ServerSocket(0, 50, localhost); int port = ss.getLocalPort(); ss.close(); Server server = new Server(0); if (!ssl) { server.getConnectors()[0].setHost(host); server.getConnectors()[0].setPort(port); } else { SslSocketConnector c = new SslSocketConnectorSecure(); c.setHost(host); c.setPort(port); c.setNeedClientAuth(false); c.setKeystore(keyStore); c.setKeystoreType(keyStoreType); c.setKeyPassword(keyStorePassword); server.setConnectors(new Connector[] {c}); } return server; } catch (Exception ex) { throw new RuntimeException("Could not stop embedded servlet container, " + ex.getMessage(), ex); } }
Example #4
Source File: StaticHttpServer.java From incubator-tajo with Apache License 2.0 | 6 votes |
public static StaticHttpServer getInstance(Object containerObject, String name, String bindAddress, int port, boolean findPort, Connector connector, TajoConf conf, String[] pathSpecs) throws IOException { String addr = bindAddress; if(instance == null) { if(bindAddress == null || bindAddress.compareTo("") == 0) { if (containerObject instanceof TajoMaster) { addr = conf.getVar(ConfVars.TAJO_MASTER_UMBILICAL_RPC_ADDRESS).split(":")[0]; } else if (containerObject instanceof TajoWorker) { addr = Inet4Address.getLocalHost().getHostName(); } } instance = new StaticHttpServer(containerObject, name, addr, port, findPort, connector, conf, pathSpecs); instance.setAttribute("tajo.info.server.object", containerObject); instance.setAttribute("tajo.info.server.addr", addr); instance.setAttribute("tajo.info.server.conf", conf); instance.setAttribute("tajo.info.server.starttime", System.currentTimeMillis()); } return instance; }
Example #5
Source File: CustomLocalServerReceiver.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public String getRedirectUri() throws IOException { if ( this.port == -1 ) { this.port = getUnusedPort(); } this.server = new Server( this.port ); Connector[] arr$ = this.server.getConnectors(); int len$ = arr$.length; for ( int i$ = 0; i$ < len$; ++i$ ) { Connector c = arr$[i$]; c.setHost( this.host ); } this.server.addHandler( new CustomLocalServerReceiver.CallbackHandler() ); try { this.server.start(); } catch ( Exception var5 ) { Throwables.propagateIfPossible( var5 ); throw new IOException( var5 ); } return "http://" + this.host + ":" + this.port + "/Callback/success.html"; }
Example #6
Source File: HttpServer2.java From hadoop with Apache License 2.0 | 6 votes |
@InterfaceAudience.Private public static Connector createDefaultChannelConnector() { SelectChannelConnector ret = new SelectChannelConnectorWithSafeStartup(); ret.setLowResourceMaxIdleTime(10000); ret.setAcceptQueueSize(128); ret.setResolveNames(false); ret.setUseDirectBuffers(false); if(Shell.WINDOWS) { // result of setting the SO_REUSEADDR flag is different on Windows // http://msdn.microsoft.com/en-us/library/ms740621(v=vs.85).aspx // without this 2 NN's can start on the same machine and listen on // the same port with indeterminate routing of incoming requests to them ret.setReuseAddress(false); } ret.setHeaderBufferSize(1024*64); return ret; }
Example #7
Source File: TestJettyHelper.java From hadoop with Apache License 2.0 | 6 votes |
private Server createJettyServer() { try { InetAddress localhost = InetAddress.getByName("localhost"); String host = "localhost"; ServerSocket ss = new ServerSocket(0, 50, localhost); int port = ss.getLocalPort(); ss.close(); Server server = new Server(0); if (!ssl) { server.getConnectors()[0].setHost(host); server.getConnectors()[0].setPort(port); } else { SslSocketConnector c = new SslSocketConnectorSecure(); c.setHost(host); c.setPort(port); c.setNeedClientAuth(false); c.setKeystore(keyStore); c.setKeystoreType(keyStoreType); c.setKeyPassword(keyStorePassword); server.setConnectors(new Connector[] {c}); } return server; } catch (Exception ex) { throw new RuntimeException("Could not stop embedded servlet container, " + ex.getMessage(), ex); } }
Example #8
Source File: CustomLocalServerReceiver.java From hop with Apache License 2.0 | 6 votes |
public String getRedirectUri() throws IOException { if ( this.port == -1 ) { this.port = getUnusedPort(); } this.server = new Server( this.port ); Connector[] arr$ = this.server.getConnectors(); int len$ = arr$.length; for ( int i$ = 0; i$ < len$; ++i$ ) { Connector c = arr$[i$]; c.setHost( this.host ); } this.server.addHandler( new CustomLocalServerReceiver.CallbackHandler() ); try { this.server.start(); } catch ( Exception var5 ) { Throwables.propagateIfPossible( var5 ); throw new IOException( var5 ); } return "http://" + this.host + ":" + this.port + "/Callback/success.html"; }
Example #9
Source File: HttpServerImpl.java From reef with Apache License 2.0 | 6 votes |
private Server tryPort(final int portNumber) throws Exception { Server srv = new Server(); final Connector connector = new SocketConnector(); connector.setHost(this.hostAddress); connector.setPort(portNumber); srv.addConnector(connector); try { srv.start(); LOG.log(Level.INFO, "Jetty Server started with port: {0}", portNumber); } catch (final BindException ex) { srv = null; LOG.log(Level.FINEST, "Cannot use host: {0},port: {1}. Will try another", new Object[] {this.hostAddress, portNumber}); } return srv; }
Example #10
Source File: Main.java From hbase-indexer with Apache License 2.0 | 6 votes |
private void startHttpServer() throws Exception { server = new Server(); SelectChannelConnector selectChannelConnector = new SelectChannelConnector(); selectChannelConnector.setPort(11060); server.setConnectors(new Connector[]{selectChannelConnector}); PackagesResourceConfig packagesResourceConfig = new PackagesResourceConfig("com/ngdata/hbaseindexer/rest"); ServletHolder servletHolder = new ServletHolder(new ServletContainer(packagesResourceConfig)); servletHolder.setName("HBase-Indexer"); Context context = new Context(server, "/", Context.NO_SESSIONS); context.addServlet(servletHolder, "/*"); context.setContextPath("/"); context.setAttribute("indexerModel", indexerModel); context.setAttribute("indexerSupervisor", indexerSupervisor); server.setHandler(context); server.start(); }
Example #11
Source File: HttpServer.java From hadoop with Apache License 2.0 | 6 votes |
@InterfaceAudience.Private public static Connector createDefaultChannelConnector() { SelectChannelConnector ret = new SelectChannelConnectorWithSafeStartup(); ret.setLowResourceMaxIdleTime(10000); ret.setAcceptQueueSize(128); ret.setResolveNames(false); ret.setUseDirectBuffers(false); if(Shell.WINDOWS) { // result of setting the SO_REUSEADDR flag is different on Windows // http://msdn.microsoft.com/en-us/library/ms740621(v=vs.85).aspx // without this 2 NN's can start on the same machine and listen on // the same port with indeterminate routing of incoming requests to them ret.setReuseAddress(false); } ret.setHeaderBufferSize(1024*64); return ret; }
Example #12
Source File: Jetty6PluginServer.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
/** * @see Jetty6PluginServer#setConnectors(Object[]) */ public void setConnectors(Object[] connectors) { if (connectors == null || connectors.length == 0) { return; } for (int i = 0; i < connectors.length; i++) { Connector connector = (Connector) connectors[i]; LOGGER.debug("Setting Connector: " + connector.getClass().getName() + " on port " + connector.getPort()); this.server.addConnector(connector); } }
Example #13
Source File: HttpServer2.java From big-c with Apache License 2.0 | 5 votes |
@Override public String toString() { Preconditions.checkState(!listeners.isEmpty()); StringBuilder sb = new StringBuilder("HttpServer (") .append(isAlive() ? STATE_DESCRIPTION_ALIVE : STATE_DESCRIPTION_NOT_LIVE) .append("), listening at:"); for (Connector l : listeners) { sb.append(l.getHost()).append(":").append(l.getPort()).append("/,"); } return sb.toString(); }
Example #14
Source File: HttpServer2.java From hadoop with Apache License 2.0 | 5 votes |
/** * Get the address that corresponds to a particular connector. * * @return the corresponding address for the connector, or null if there's no * such connector or the connector is not bounded. */ public InetSocketAddress getConnectorAddress(int index) { Preconditions.checkArgument(index >= 0); if (index > webServer.getConnectors().length) return null; Connector c = webServer.getConnectors()[index]; if (c.getLocalPort() == -1) { // The connector is not bounded return null; } return new InetSocketAddress(c.getHost(), c.getLocalPort()); }
Example #15
Source File: RestServer.java From hraven with Apache License 2.0 | 5 votes |
@Override protected void startUp() throws Exception { // setup the jetty config ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter("com.sun.jersey.config.property.packages", "com.twitter.hraven.rest"); sh.setInitParameter(JSONConfiguration.FEATURE_POJO_MAPPING, "true"); server = new Server(); Connector connector = new SelectChannelConnector(); connector.setPort(this.port); connector.setHost(address); server.addConnector(connector); // TODO: in the future we may want to provide settings for the min and max threads // Jetty sets the default max thread number to 250, if we don't set it. // QueuedThreadPool threadPool = new QueuedThreadPool(); server.setThreadPool(threadPool); server.setSendServerVersion(false); server.setSendDateHeader(false); server.setStopAtShutdown(true); // set up context Context context = new Context(server, "/", Context.SESSIONS); context.addServlet(sh, "/*"); // start server server.start(); }
Example #16
Source File: GenerateToken.java From socialauth with MIT License | 5 votes |
private void startServer() throws Exception { server = new Server(port); for (Connector c : server.getConnectors()) { c.setHost(host); } server.addHandler(new CallbackHandler()); try { server.start(); } catch (Exception e) { throw new IOException(e); } }
Example #17
Source File: MiniKMS.java From hadoop with Apache License 2.0 | 5 votes |
private static Server createJettyServer(String keyStore, String password, int inPort) { try { boolean ssl = keyStore != null; InetAddress localhost = InetAddress.getByName("localhost"); String host = "localhost"; ServerSocket ss = new ServerSocket((inPort < 0) ? 0 : inPort, 50, localhost); int port = ss.getLocalPort(); ss.close(); Server server = new Server(0); if (!ssl) { server.getConnectors()[0].setHost(host); server.getConnectors()[0].setPort(port); } else { SslSocketConnector c = new SslSocketConnectorSecure(); c.setHost(host); c.setPort(port); c.setNeedClientAuth(false); c.setKeystore(keyStore); c.setKeystoreType("jks"); c.setKeyPassword(password); server.setConnectors(new Connector[]{c}); } return server; } catch (Exception ex) { throw new RuntimeException("Could not start embedded servlet container, " + ex.getMessage(), ex); } }
Example #18
Source File: Jetty6PluginServer.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
/** * @see Jetty6PluginServer#setConnectors(Object[]) */ public void setConnectors(Object[] connectors) { if (connectors == null || connectors.length == 0) { return; } for (int i = 0; i < connectors.length; i++) { Connector connector = (Connector) connectors[i]; LOGGER.debug("Setting Connector: " + connector.getClass().getName() + " on port " + connector.getPort()); this.server.addConnector(connector); } }
Example #19
Source File: HttpServer2.java From big-c with Apache License 2.0 | 5 votes |
/** * Get the address that corresponds to a particular connector. * * @return the corresponding address for the connector, or null if there's no * such connector or the connector is not bounded. */ public InetSocketAddress getConnectorAddress(int index) { Preconditions.checkArgument(index >= 0); if (index > webServer.getConnectors().length) return null; Connector c = webServer.getConnectors()[index]; if (c.getLocalPort() == -1) { // The connector is not bounded return null; } return new InetSocketAddress(c.getHost(), c.getLocalPort()); }
Example #20
Source File: HttpServer.java From incubator-tajo with Apache License 2.0 | 5 votes |
static Connector createDefaultChannelConnector() { SelectChannelConnector ret = new SelectChannelConnector(); ret.setLowResourceMaxIdleTime(10000); ret.setAcceptQueueSize(128); ret.setResolveNames(false); ret.setUseDirectBuffers(false); return ret; }
Example #21
Source File: HttpServer2.java From big-c with Apache License 2.0 | 5 votes |
/** * Open the main listener for the server * @throws Exception */ void openListeners() throws Exception { for (Connector listener : listeners) { if (listener.getLocalPort() != -1) { // This listener is either started externally or has been bound continue; } int port = listener.getPort(); while (true) { // jetty has a bug where you can't reopen a listener that previously // failed to open w/o issuing a close first, even if the port is changed try { listener.close(); listener.open(); LOG.info("Jetty bound to port " + listener.getLocalPort()); break; } catch (BindException ex) { if (port == 0 || !findPort) { BindException be = new BindException("Port in use: " + listener.getHost() + ":" + listener.getPort()); be.initCause(ex); throw be; } } // try the next port number listener.setPort(++port); Thread.sleep(100); } } }
Example #22
Source File: HttpServer.java From hadoop-gpu with Apache License 2.0 | 5 votes |
/** * Create a required listener for the Jetty instance listening on the port * provided. This wrapper and all subclasses must create at least one * listener. */ protected Connector createBaseListener(Configuration conf) throws IOException { SelectChannelConnector ret = new SelectChannelConnector(); ret.setLowResourceMaxIdleTime(10000); ret.setAcceptQueueSize(128); ret.setResolveNames(false); ret.setUseDirectBuffers(false); return ret; }
Example #23
Source File: TestHttpServer.java From big-c with Apache License 2.0 | 5 votes |
private HttpServer2 checkBindAddress(String host, int port, boolean findPort) throws Exception { HttpServer2 server = createServer(host, port); try { // not bound, ephemeral should return requested port (0 for ephemeral) List<?> listeners = (List<?>) Whitebox.getInternalState(server, "listeners"); Connector listener = (Connector) listeners.get(0); assertEquals(port, listener.getPort()); // verify hostname is what was given server.openListeners(); assertEquals(host, server.getConnectorAddress(0).getHostName()); int boundPort = server.getConnectorAddress(0).getPort(); if (port == 0) { assertTrue(boundPort != 0); // ephemeral should now return bound port } else if (findPort) { assertTrue(boundPort > port); // allow a little wiggle room to prevent random test failures if // some consecutive ports are already in use assertTrue(boundPort - port < 8); } } catch (Exception e) { server.stop(); throw e; } return server; }
Example #24
Source File: MiniKMS.java From big-c with Apache License 2.0 | 5 votes |
private static Server createJettyServer(String keyStore, String password, int inPort) { try { boolean ssl = keyStore != null; InetAddress localhost = InetAddress.getByName("localhost"); String host = "localhost"; ServerSocket ss = new ServerSocket((inPort < 0) ? 0 : inPort, 50, localhost); int port = ss.getLocalPort(); ss.close(); Server server = new Server(0); if (!ssl) { server.getConnectors()[0].setHost(host); server.getConnectors()[0].setPort(port); } else { SslSocketConnector c = new SslSocketConnectorSecure(); c.setHost(host); c.setPort(port); c.setNeedClientAuth(false); c.setKeystore(keyStore); c.setKeystoreType("jks"); c.setKeyPassword(password); server.setConnectors(new Connector[]{c}); } return server; } catch (Exception ex) { throw new RuntimeException("Could not start embedded servlet container, " + ex.getMessage(), ex); } }
Example #25
Source File: StaticHttpServer.java From tajo with Apache License 2.0 | 5 votes |
public static StaticHttpServer getInstance(Object containerObject, String name, String bindAddress, int port, boolean findPort, Connector connector, TajoConf conf, String[] pathSpecs) throws IOException { String addr = bindAddress; if(instance == null) { if(bindAddress == null || bindAddress.compareTo("") == 0) { if (containerObject instanceof TajoMaster) { addr = conf.getSocketAddrVar( ConfVars.TAJO_MASTER_INFO_ADDRESS).getHostName(); } else if (containerObject instanceof TajoWorker) { addr = conf.getSocketAddrVar( ConfVars.WORKER_INFO_ADDRESS).getHostName(); } } synchronized (lockObjectForStaticHttpServer) { if (instance == null) { instance = new StaticHttpServer(containerObject, name, addr, port, findPort, connector, conf, pathSpecs); instance.setAttribute("tajo.info.server.object", containerObject); instance.setAttribute("tajo.info.server.addr", addr); instance.setAttribute("tajo.info.server.conf", conf); instance.setAttribute("tajo.info.server.starttime", System.currentTimeMillis()); } } } return instance; }
Example #26
Source File: Jetty6PluginServer.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
/** * @see Jetty6PluginServer#setConnectors(Object[]) */ public void setConnectors(Object[] connectors) { if (connectors == null || connectors.length == 0) { return; } for (int i = 0; i < connectors.length; i++) { Connector connector = (Connector) connectors[i]; LOGGER.debug("Setting Connector: " + connector.getClass().getName() + " on port " + connector.getPort()); this.server.addConnector(connector); } }
Example #27
Source File: HttpServer.java From tajo with Apache License 2.0 | 5 votes |
static Connector createDefaultChannelConnector() { SelectChannelConnector ret = new SelectChannelConnector(); ret.setLowResourceMaxIdleTime(10000); ret.setAcceptQueueSize(128); ret.setResolveNames(false); ret.setUseDirectBuffers(false); return ret; }
Example #28
Source File: Jetty6PluginServer.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
/** * @see Jetty6PluginServer#setConnectors(Object[]) */ public void setConnectors(Object[] connectors) { if (connectors == null || connectors.length == 0) { return; } for (int i = 0; i < connectors.length; i++) { Connector connector = (Connector) connectors[i]; LOGGER.debug("Setting Connector: " + connector.getClass().getName() + " on port " + connector.getPort()); this.server.addConnector(connector); } }
Example #29
Source File: HttpConnectorProviderTest.java From incubator-myriad with Apache License 2.0 | 5 votes |
@Test public void testConnector() throws Exception { HttpConnectorProvider provider = new HttpConnectorProvider(cfg); Connector connector = provider.get(); assertEquals(8192, connector.getPort()); assertEquals("0.0.0.0", connector.getHost()); assertEquals("Myriad", connector.getName()); }
Example #30
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; }