Java Code Examples for org.mortbay.jetty.Connector#setHost()
The following examples show how to use
org.mortbay.jetty.Connector#setHost() .
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: 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 2
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 3
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 4
Source File: AbstractServerMojo.java From opoopress with Apache License 2.0 | 5 votes |
/** * * @param host localhost, 127.0.0.1 or 0.0.0.0. * @param port port * @return jetty connector */ protected Connector createConnector(String host, int port){ Connector connector = new SelectChannelConnector(); if(host != null){ connector.setHost(host); } connector.setPort( port ); connector.setMaxIdleTime(MAX_IDLE_TIME); return connector; }
Example 5
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 6
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 7
Source File: HbaseRestLocalCluster.java From hadoop-mini-clusters with Apache License 2.0 | 4 votes |
@Override public void start() throws Exception { VersionInfo.logVersion(); Configuration conf = builder.getHbaseConfiguration(); conf.set("hbase.rest.port", hbaseRestPort.toString()); conf.set("hbase.rest.readonly", (hbaseRestReadOnly == null) ? "true" : hbaseRestReadOnly.toString()); conf.set("hbase.rest.info.port", (hbaseRestInfoPort == null) ? "8085" : hbaseRestInfoPort.toString()); String hbaseRestHost = (this.hbaseRestHost == null) ? "0.0.0.0" : this.hbaseRestHost; Integer hbaseRestThreadMax = (this.hbaseRestThreadMax == null) ? 100 : this.hbaseRestThreadMax; Integer hbaseRestThreadMin = (this.hbaseRestThreadMin == null) ? 2 : this.hbaseRestThreadMin; UserProvider userProvider = UserProvider.instantiate(conf); Pair<FilterHolder, Class<? extends ServletContainer>> pair = loginServerPrincipal(userProvider, conf); FilterHolder authFilter = pair.getFirst(); Class<? extends ServletContainer> containerClass = pair.getSecond(); RESTServlet.getInstance(conf, userProvider); // set up the Jersey servlet container for Jetty ServletHolder sh = new ServletHolder(containerClass); sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", ResourceConfig.class.getCanonicalName()); sh.setInitParameter("com.sun.jersey.config.property.packages", "jetty"); ServletHolder shPojoMap = new ServletHolder(containerClass); Map<String, String> shInitMap = sh.getInitParameters(); for (Map.Entry<String, String> e : shInitMap.entrySet()) { shPojoMap.setInitParameter(e.getKey(), e.getValue()); } shPojoMap.setInitParameter(JSONConfiguration.FEATURE_POJO_MAPPING, "true"); // set up Jetty and run the embedded server server = new Server(); Connector connector = new SelectChannelConnector(); if (conf.getBoolean(RESTServer.REST_SSL_ENABLED, false)) { SslSelectChannelConnector sslConnector = new SslSelectChannelConnector(); String keystore = conf.get(RESTServer.REST_SSL_KEYSTORE_STORE); String password = HBaseConfiguration.getPassword(conf, RESTServer.REST_SSL_KEYSTORE_PASSWORD, null); String keyPassword = HBaseConfiguration.getPassword(conf, RESTServer.REST_SSL_KEYSTORE_KEYPASSWORD, password); sslConnector.setKeystore(keystore); sslConnector.setPassword(password); sslConnector.setKeyPassword(keyPassword); connector = sslConnector; } connector.setPort(hbaseRestPort); connector.setHost(hbaseRestHost); connector.setHeaderBufferSize(8192); server.addConnector(connector); QueuedThreadPool threadPool = new QueuedThreadPool(hbaseRestThreadMax); threadPool.setMinThreads(hbaseRestThreadMin); server.setThreadPool(threadPool); server.setSendServerVersion(false); server.setSendDateHeader(false); server.setStopAtShutdown(true); // set up context Context context = new Context(server, "/", Context.SESSIONS); context.addServlet(shPojoMap, "/status/cluster"); context.addServlet(sh, "/*"); if (authFilter != null) { context.addFilter(authFilter, "/*", 1); } HttpServerUtil.constrainHttpMethods(context); // Put up info server. int port = (hbaseRestInfoPort == null) ? 8085 : hbaseRestInfoPort; if (port >= 0) { conf.setLong("startcode", System.currentTimeMillis()); String a = hbaseRestHost; infoServer = new InfoServer("rest", a, port, false, conf); infoServer.setAttribute("hbase.conf", conf); infoServer.start(); } // start server server.start(); }