Java Code Examples for org.mortbay.jetty.nio.SelectChannelConnector.setHost()

The following are Jave code examples for showing how to use setHost() of the org.mortbay.jetty.nio.SelectChannelConnector class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: EatDubbo   File: JettyHttpServer.java   Source Code and License Vote up 5 votes
public JettyHttpServer(URL url, final HttpHandler handler){
    super(url, handler);
    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);
    
    server.addHandler(servletHandler);
    
    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: "
                                        + e.getMessage(), e);
    }
}
 
Example 2
Project: GeoCrawler   File: TestProtocolHttp.java   Source Code and License Vote up 5 votes
/**
 * Starts the Jetty server at a specified port and redirection parameter.
 * 
 * @param portno
 *          Port number.
 * @param redirection
 *          whether redirection
 */
private void startServer(int portno, boolean redirection) throws Exception {
  port = portno;
  setUp(redirection);
  SelectChannelConnector connector = new SelectChannelConnector();
  connector.setHost("127.0.0.1");
  connector.setPort(port);

  server.addConnector(connector);
  server.start();
}
 
Example 3
Project: dubbo-comments   File: JettyHttpServer.java   Source Code and License Vote up 5 votes
public JettyHttpServer(URL url, final HttpHandler handler){
    super(url, handler);
    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);
    
    server.addHandler(servletHandler);
    
    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: "
                                        + e.getMessage(), e);
    }
}
 
Example 4
Project: dubbo   File: JettyHttpServer.java   Source Code and License Vote up 5 votes
public JettyHttpServer(URL url, final HttpHandler handler){
    super(url, handler);
    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);
    
    server.addHandler(servletHandler);
    
    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: "
                                        + e.getMessage(), e);
    }
}
 
Example 5
Project: openbravo-pos   File: JettyHttpServer.java   Source Code and License Vote up 5 votes
@Override
 public void bind(InetSocketAddress addr, int backlog) throws IOException
 {
     this._addr = addr;
     
 	// check if there is already a connector listening
     Connector[] connectors = _server.getConnectors();
     if (connectors != null)
     {
      for (int i = 0; i < connectors.length; i++)
      {
	if (connectors[i].getPort() == addr.getPort())
	{
		if (Log.isDebugEnabled()) Log.debug("server already bound to port " + addr.getPort() + ", no need to rebind");
		return;
	}
}
     }
     
     if (_executor != null && _server.getThreadPool() == null)
     {
     	if (Log.isDebugEnabled()) Log.debug("using given Executor for server thread pool");
     	_server.setThreadPool(new ThreadPoolExecutorAdapter(_executor));
     }

     SelectChannelConnector connector = new SelectChannelConnector();
     connector.setAcceptors(1);
     connector.setPort(addr.getPort());
     connector.setHost(addr.getHostName());
     _server.addConnector(connector);
     
     _connectors.put(addr.getHostName() + addr.getPort(), connector);
 }
 
Example 6
Project: SecureKeeper   File: JettyAdminServer.java   Source Code and License Vote up 5 votes
public JettyAdminServer(String address, int port, String commandUrl) {
    this.port = port;
    this.commandUrl = commandUrl;
    this.address = address;

    server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setHost(address);
    connector.setPort(port);
    server.addConnector(connector);
    Context context = new Context(server, "/");
    server.setHandler(context);
    context.addServlet(new ServletHolder(new CommandServlet()), commandUrl
            + "/*");
}
 
Example 7
Project: SecureKeeper   File: JettyAdminServer.java   Source Code and License Vote up 5 votes
public JettyAdminServer(String address, int port, String commandUrl) {
    this.port = port;
    this.commandUrl = commandUrl;
    this.address = address;

    server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setHost(address);
    connector.setPort(port);
    server.addConnector(connector);
    Context context = new Context(server, "/");
    server.setHandler(context);
    context.addServlet(new ServletHolder(new CommandServlet()), commandUrl
            + "/*");
}
 
Example 8
Project: dubbo-learning   File: JettyHttpServer.java   Source Code and License Vote up 5 votes
public JettyHttpServer(URL url, final HttpHandler handler){
    super(url, handler);
    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);
    
    server.addHandler(servletHandler);
    
    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: "
                                        + e.getMessage(), e);
    }
}
 
Example 9
Project: DubboCode   File: JettyHttpServer.java   Source Code and License Vote up 5 votes
public JettyHttpServer(URL url, final HttpHandler handler){
    super(url, handler);
    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);
    
    server.addHandler(servletHandler);
    
    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: "
                                        + e.getMessage(), e);
    }
}
 
Example 10
Project: hadoop-EAR   File: ProxyHttpServer.java   Source Code and License Vote up 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 11
Project: hadoop-EAR   File: ProxyHttpServer.java   Source Code and License Vote up 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 12
Project: dubbo2study   File: JettyHttpServer.java   Source Code and License Vote up 5 votes
public JettyHttpServer(URL url, final HttpHandler handler){
    super(url, handler);
    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);
    
    server.addHandler(servletHandler);
    
    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: "
                                        + e.getMessage(), e);
    }
}
 
Example 13
Project: dubbo-comments   File: JettyHttpServer.java   Source Code and License Vote up 5 votes
public JettyHttpServer(URL url, final HttpHandler handler){
    super(url, handler);
    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);
    
    server.addHandler(servletHandler);
    
    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: "
                                        + e.getMessage(), e);
    }
}
 
Example 14
Project: dubbo-ex   File: JettyHttpServer.java   Source Code and License Vote up 5 votes
public JettyHttpServer(URL url, final HttpHandler handler){
    super(url, handler);
    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);
    
    server.addHandler(servletHandler);
    
    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: "
                                        + e.getMessage(), e);
    }
}
 
Example 15
Project: incubator-myriad   File: HttpConnectorProvider.java   Source Code and License Vote up 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 16
Project: exDubbo   File: JettyHttpServer.java   Source Code and License Vote up 5 votes
public JettyHttpServer(URL url, final HttpHandler handler){
    super(url, handler);
    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);
    
    server.addHandler(servletHandler);
    
    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: "
                                        + e.getMessage(), e);
    }
}
 
Example 17
Project: yawp   File: DevServer.java   Source Code and License Vote up 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 18
Project: hadoop-on-lustre   File: ProxyHttpServer.java   Source Code and License Vote up 5 votes
/** {@inheritDoc} */
public 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 19
Project: dubbo2.js   File: JettyHttpServer.java   Source Code and License Vote up 5 votes
public JettyHttpServer(URL url, final HttpHandler handler) {
    super(url, handler);
    DispatcherServlet.addHttpHandler(url.getParameter(Constants.BIND_PORT_KEY, 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();

    String bindIp = url.getParameter(Constants.BIND_IP_KEY, url.getHost());
    if (!url.isAnyHost() && NetUtils.isValidLocalHost(bindIp)) {
        connector.setHost(bindIp);
    }
    connector.setPort(url.getParameter(Constants.BIND_PORT_KEY, url.getPort()));

    server = new Server();
    server.setThreadPool(threadPool);
    server.addConnector(connector);

    ServletHandler servletHandler = new ServletHandler();
    ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*");
    servletHolder.setInitOrder(2);

    server.addHandler(servletHandler);

    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + url.getParameter(Constants.BIND_IP_KEY) + ":" + url.getParameter(Constants.BIND_PORT_KEY) + ", cause: "
                + e.getMessage(), e);
    }
}
 
Example 20
Project: fiware-cygnus   File: JettyServer.java   Source Code and License Vote up 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 21
Project: cumulus   File: ProxyHttpServer.java   Source Code and License Vote up 5 votes
/** {@inheritDoc} */
public 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 22
Project: RDFS   File: ProxyHttpServer.java   Source Code and License Vote up 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 23
Project: hadoop-0.20   File: ProxyHttpServer.java   Source Code and License Vote up 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 24
Project: OpenbravoPOS   File: JettyHttpServer.java   Source Code and License Vote up 5 votes
@Override
 public void bind(InetSocketAddress addr, int backlog) throws IOException
 {
     this._addr = addr;
     
 	// check if there is already a connector listening
     Connector[] connectors = _server.getConnectors();
     if (connectors != null)
     {
      for (int i = 0; i < connectors.length; i++)
      {
	if (connectors[i].getPort() == addr.getPort())
	{
		if (Log.isDebugEnabled()) Log.debug("server already bound to port " + addr.getPort() + ", no need to rebind");
		return;
	}
}
     }
     
     if (_executor != null && _server.getThreadPool() == null)
     {
     	if (Log.isDebugEnabled()) Log.debug("using given Executor for server thread pool");
     	_server.setThreadPool(new ThreadPoolExecutorAdapter(_executor));
     }

     SelectChannelConnector connector = new SelectChannelConnector();
     connector.setAcceptors(1);
     connector.setPort(addr.getPort());
     connector.setHost(addr.getHostName());
     _server.addConnector(connector);
     
     _connectors.put(addr.getHostName() + addr.getPort(), connector);
 }
 
Example 25
Project: hortonworks-extension   File: ProxyHttpServer.java   Source Code and License Vote up 5 votes
/** {@inheritDoc} */
public 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 26
Project: hortonworks-extension   File: ProxyHttpServer.java   Source Code and License Vote up 5 votes
/** {@inheritDoc} */
public 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 27
Project: hortonworks-extension   File: ProxyHttpServer.java   Source Code and License Vote up 5 votes
/** {@inheritDoc} */
public 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 28
Project: hadoop-gpu   File: ProxyHttpServer.java   Source Code and License Vote up 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 29
Project: dubbo2   File: JettyHttpServer.java   Source Code and License Vote up 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 30
Project: dubbox-hystrix   File: JettyHttpServer.java   Source Code and License Vote up 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 31
Project: dubbocloud   File: JettyHttpServer.java   Source Code and License Vote up 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 32
Project: dubbos   File: JettyHttpServer.java   Source Code and License Vote up 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 33
Project: dubbox   File: JettyHttpServer.java   Source Code and License Vote up 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 34
Project: subsonic   File: SubsonicDeployer.java   Source Code and License Vote up 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 35
Project: jahhan   File: JettyHttpServer.java   Source Code and License Vote up 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);
        BaseContext.CTX.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 36
Project: LetUsGo-Server   File: JettyHttpServer.java   Source Code and License Vote up 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 37
Project: dangdangdotcom   File: JettyHttpServer.java   Source Code and License Vote up 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 38
Project: hadoop-on-lustre   File: SecureDataNodeStarter.java   Source Code and License Vote up 4 votes
@Override
public void init(DaemonContext context) throws Exception {
  System.err.println("Initializing secure datanode resources");
  // We should only start up a secure datanode in a Kerberos-secured cluster
  Configuration conf = new Configuration(); // Skip UGI method to not log in
  if(!conf.get(HADOOP_SECURITY_AUTHENTICATION).equals("kerberos"))
    throw new RuntimeException("Cannot start secure datanode in unsecure cluster");
  
  // Stash command-line arguments for regular datanode
  args = context.getArguments();
  
  // Obtain secure port for data streaming to datanode
  InetSocketAddress socAddr = DataNode.getStreamingAddr(conf);
  int socketWriteTimeout = conf.getInt("dfs.datanode.socket.write.timeout",
      HdfsConstants.WRITE_TIMEOUT);
  
  ServerSocket ss = (socketWriteTimeout > 0) ? 
      ServerSocketChannel.open().socket() : new ServerSocket();
  ss.bind(socAddr, 0);
  
  // Check that we got the port we need
  if(ss.getLocalPort() != socAddr.getPort())
    throw new RuntimeException("Unable to bind on specified streaming port in secure " +
    		"context. Needed " + socAddr.getPort() + ", got " + ss.getLocalPort());

  // Obtain secure listener for web server
  SelectChannelConnector listener = 
                 (SelectChannelConnector)HttpServer.createDefaultChannelConnector();
  InetSocketAddress infoSocAddr = DataNode.getInfoAddr(conf);
  listener.setHost(infoSocAddr.getHostName());
  listener.setPort(infoSocAddr.getPort());
  // Open listener here in order to bind to port as root
  listener.open(); 
  if(listener.getPort() != infoSocAddr.getPort())
    throw new RuntimeException("Unable to bind on specified info port in secure " +
        "context. Needed " + socAddr.getPort() + ", got " + ss.getLocalPort());
 
  if(ss.getLocalPort() >= 1023 || listener.getPort() >= 1023)
    throw new RuntimeException("Cannot start secure datanode on non-privileged "
       +" ports. (streaming port = " + ss + " ) (http listener port = " + 
       listener.getConnection() + "). Exiting.");
 
  System.err.println("Successfully obtained privileged resources (streaming port = "
      + ss + " ) (http listener port = " + listener.getConnection() +")");
  
  resources = new SecureResources(ss, listener);
}
 
Example 39
Project: cumulus   File: SecureDataNodeStarter.java   Source Code and License Vote up 4 votes
@Override
public void init(DaemonContext context) throws Exception {
  System.err.println("Initializing secure datanode resources");
  // We should only start up a secure datanode in a Kerberos-secured cluster
  Configuration conf = new Configuration(); // Skip UGI method to not log in
  if(!conf.get(HADOOP_SECURITY_AUTHENTICATION).equals("kerberos"))
    throw new RuntimeException("Cannot start secure datanode in unsecure cluster");
  
  // Stash command-line arguments for regular datanode
  args = context.getArguments();
  
  // Obtain secure port for data streaming to datanode
  InetSocketAddress socAddr = DataNode.getStreamingAddr(conf);
  int socketWriteTimeout = conf.getInt("dfs.datanode.socket.write.timeout",
      HdfsConstants.WRITE_TIMEOUT);
  
  ServerSocket ss = (socketWriteTimeout > 0) ? 
      ServerSocketChannel.open().socket() : new ServerSocket();
  ss.bind(socAddr, 0);
  
  // Check that we got the port we need
  if(ss.getLocalPort() != socAddr.getPort())
    throw new RuntimeException("Unable to bind on specified streaming port in secure " +
    		"context. Needed " + socAddr.getPort() + ", got " + ss.getLocalPort());

  // Obtain secure listener for web server
  SelectChannelConnector listener = 
                 (SelectChannelConnector)HttpServer.createDefaultChannelConnector();
  InetSocketAddress infoSocAddr = DataNode.getInfoAddr(conf);
  listener.setHost(infoSocAddr.getHostName());
  listener.setPort(infoSocAddr.getPort());
  // Open listener here in order to bind to port as root
  listener.open(); 
  if(listener.getPort() != infoSocAddr.getPort())
    throw new RuntimeException("Unable to bind on specified info port in secure " +
        "context. Needed " + socAddr.getPort() + ", got " + ss.getLocalPort());
  System.err.println("Successfully obtained privileged resources (streaming port = "
      + ss + " ) (http listener port = " + listener.getConnection() +")");
  
  if(ss.getLocalPort() >= 1023 || listener.getPort() >= 1023)
    throw new RuntimeException("Cannot start secure datanode with unprivileged ports");
  
  resources = new SecureResources(ss, listener);
}
 
Example 40
Project: appkeep   File: AppkeepServer.java   Source Code and License Vote up 4 votes
public AppkeepServer(final ServerConfiguration config, final ProxyFactory proxyFactory) {
		try {
			config.validate();
			
			jetty = new Server();
			SelectChannelConnector connector = new SelectChannelConnector();
			connector.setPort(config.publishPort());
			connector.setHost(config.bindAddress());
			jetty.addConnector(connector);
			
			lobs = new LocalDiskLobStore(new File(config.storageDir(), "lob-data"));
			data = new Data(new File(config.storageDir(), "bdb-data"), new Long(10 * 1024 * 100 /*10mb*/));
			
			{// ADMINISTRATOR BOOTSTRAPPING MECHANISM
				for(AdministratorConfig admin : config.administrators()){
					UserAccount user = data.userAccounts.get(admin.authenticationId(), null, LockMode.READ_COMMITTED);
					if(user==null){
						log.warn("Bootstrapping admin account for " + admin.authenticationId());
						user = new UserAccount(admin.authenticationId());
						user.setAdministrator(true);
					}
					if(!user.isAdministrator()){
						log.warn("Promoting account " + admin.authenticationId() + " to administrator");
						user.setAdministrator(true);
					}
					
					data.userAccounts.put(user.id(), user, null);
					if(admin.idProofRecipie() instanceof PasswordProofRecipie){
						PasswordProofRecipie pr = (PasswordProofRecipie) admin.idProofRecipie();
						data.passwords.put(admin.authenticationId().toString(), pr.password().getPassword(), null);
					}
				}
			}
			{// IDENTITY TOOLS
				idTool = new IdTool(
						new SimpleIdIdToolPlugin(new PasswordCheckerImpl(config, data)), 
						new VeracityIdToolPlugin(proxyFactory)
				);
				idProover = idTool.getFactory(
						config.idProofRecipie().id(), 
						config.idProofRecipie().password()
					);
				
			}
			{// REPLICATION POLLER
				poller = new Poller(config.id(), config.peers(), proxyFactory, idProover, lobs, data);
			}
			{// MAIN RPC SERVICE
				AppkeepServiceImpl mapService = new AppkeepServiceImpl(data, lobs, poller, config, proxyFactory, idProover, idTool);
				String path = "/rpc";
				SwitchingContentHandler handler = new SwitchingContentHandler(path);
//				handler.addHandler(new JAXWSContentHandler(path, mapService));
				handler.addHandler(new HessianContentHandler(AppkeepService.class, mapService));
				jetty.addHandler(handler);
			}
			
			{// BDBADMIN SERVICE
				BdbService service = new BdbService(buildBdbadminTree(data), new BdbAdminAuthorizer(data), proxyFactory);
				jetty.addHandler(new BdbAdminJettyAdapter("/bdbadmin", service));
			}
			
			jetty.addHandler(new HttpPublisher(data, lobs, new KeepTool(data, lobs, config.peers(), proxyFactory, config.id(), idProover)));
			
			jetty.start();
			
			log.info("SERVER READY FOR ACTION");
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
 
Example 41
Project: hortonworks-extension   File: SecureDataNodeStarter.java   Source Code and License Vote up 4 votes
@Override
public void init(DaemonContext context) throws Exception {
  System.err.println("Initializing secure datanode resources");
  // We should only start up a secure datanode in a Kerberos-secured cluster
  Configuration conf = new Configuration(); // Skip UGI method to not log in
  if(!conf.get(HADOOP_SECURITY_AUTHENTICATION).equals("kerberos"))
    throw new RuntimeException("Cannot start secure datanode in unsecure cluster");
  
  // Stash command-line arguments for regular datanode
  args = context.getArguments();
  
  // Obtain secure port for data streaming to datanode
  InetSocketAddress socAddr = DataNode.getStreamingAddr(conf);
  int socketWriteTimeout = conf.getInt("dfs.datanode.socket.write.timeout",
      HdfsConstants.WRITE_TIMEOUT);
  
  ServerSocket ss = (socketWriteTimeout > 0) ? 
      ServerSocketChannel.open().socket() : new ServerSocket();
  ss.bind(socAddr, 0);
  
  // Check that we got the port we need
  if(ss.getLocalPort() != socAddr.getPort())
    throw new RuntimeException("Unable to bind on specified streaming port in secure " +
    		"context. Needed " + socAddr.getPort() + ", got " + ss.getLocalPort());

  // Obtain secure listener for web server
  SelectChannelConnector listener = 
                 (SelectChannelConnector)HttpServer.createDefaultChannelConnector();
  InetSocketAddress infoSocAddr = DataNode.getInfoAddr(conf);
  listener.setHost(infoSocAddr.getHostName());
  listener.setPort(infoSocAddr.getPort());
  // Open listener here in order to bind to port as root
  listener.open(); 
  if(listener.getPort() != infoSocAddr.getPort())
    throw new RuntimeException("Unable to bind on specified info port in secure " +
        "context. Needed " + socAddr.getPort() + ", got " + ss.getLocalPort());
 
  if(ss.getLocalPort() >= 1023 || listener.getPort() >= 1023)
    throw new RuntimeException("Cannot start secure datanode on non-privileged "
       +" ports. (streaming port = " + ss + " ) (http listener port = " + 
       listener.getConnection() + "). Exiting.");
 
  System.err.println("Successfully obtained privileged resources (streaming port = "
      + ss + " ) (http listener port = " + listener.getConnection() +")");
  
  resources = new SecureResources(ss, listener);
}
 
Example 42
Project: hortonworks-extension   File: SecureDataNodeStarter.java   Source Code and License Vote up 4 votes
@Override
public void init(DaemonContext context) throws Exception {
  System.err.println("Initializing secure datanode resources");
  // We should only start up a secure datanode in a Kerberos-secured cluster
  Configuration conf = new Configuration(); // Skip UGI method to not log in
  if(!conf.get(HADOOP_SECURITY_AUTHENTICATION).equals("kerberos"))
    throw new RuntimeException("Cannot start secure datanode in unsecure cluster");
  
  // Stash command-line arguments for regular datanode
  args = context.getArguments();
  
  // Obtain secure port for data streaming to datanode
  InetSocketAddress socAddr = DataNode.getStreamingAddr(conf);
  int socketWriteTimeout = conf.getInt("dfs.datanode.socket.write.timeout",
      HdfsConstants.WRITE_TIMEOUT);
  
  ServerSocket ss = (socketWriteTimeout > 0) ? 
      ServerSocketChannel.open().socket() : new ServerSocket();
  ss.bind(socAddr, 0);
  
  // Check that we got the port we need
  if(ss.getLocalPort() != socAddr.getPort())
    throw new RuntimeException("Unable to bind on specified streaming port in secure " +
    		"context. Needed " + socAddr.getPort() + ", got " + ss.getLocalPort());

  // Obtain secure listener for web server
  SelectChannelConnector listener = 
                 (SelectChannelConnector)HttpServer.createDefaultChannelConnector();
  InetSocketAddress infoSocAddr = DataNode.getInfoAddr(conf);
  listener.setHost(infoSocAddr.getHostName());
  listener.setPort(infoSocAddr.getPort());
  // Open listener here in order to bind to port as root
  listener.open(); 
  if(listener.getPort() != infoSocAddr.getPort())
    throw new RuntimeException("Unable to bind on specified info port in secure " +
        "context. Needed " + socAddr.getPort() + ", got " + ss.getLocalPort());
 
  if(ss.getLocalPort() >= 1023 || listener.getPort() >= 1023)
    throw new RuntimeException("Cannot start secure datanode on non-privileged "
       +" ports. (streaming port = " + ss + " ) (http listener port = " + 
       listener.getConnection() + "). Exiting.");
 
  System.err.println("Successfully obtained privileged resources (streaming port = "
      + ss + " ) (http listener port = " + listener.getConnection() +")");
  
  resources = new SecureResources(ss, listener);
}