Package org.eclipse.jetty.server.nio

Examples of org.eclipse.jetty.server.nio.SelectChannelConnector


  public static void main(String[] args) throws Exception {
    new FileServer().start();
  }

  public void start() throws Exception {
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(8080);
    server.addConnector(connector);
    ContextHandler updateContext = createUpdateContext();
    ContextHandler rootContext = createRootContext();
    ContextHandlerCollection handlers = new ContextHandlerCollection();
    handlers.setHandlers(new Handler[]{updateContext, rootContext});
View Full Code Here


        return version;
    }

    private boolean initializeHttp()
    {
        Connector connector = this.config.isUseHttpNio() ? new SelectChannelConnector() : new SocketConnector();
        configureConnector(connector, this.config.getHttpPort());
        return startConnector(connector);
    }
View Full Code Here

   */
  public static String setUp(final Handler handler) throws Exception {
    server = new Server();
    if (handler != null)
      server.setHandler(handler);
    Connector connector = new SelectChannelConnector();
    connector.setPort(0);
    server.setConnectors(new Connector[] { connector });
    server.start();

    proxy = new Server();
    Connector proxyConnector = new SelectChannelConnector();
    proxyConnector.setPort(0);
    proxy.setConnectors(new Connector[] { proxyConnector });

    ServletHandler proxyHandler = new ServletHandler();

    RequestHandler proxyCountingHandler = new RequestHandler() {

      @Override
      public void handle(Request request, HttpServletResponse response) {
        proxyHitCount.incrementAndGet();
        String auth = request.getHeader("Proxy-Authorization");
        auth = auth.substring(auth.indexOf(' ') + 1);
        try {
          auth = B64Code.decode(auth, CHARSET_UTF8);
        } catch (UnsupportedEncodingException e) {
          throw new RuntimeException(e);
        }
        int colon = auth.indexOf(':');
        proxyUser.set(auth.substring(0, colon));
        proxyPassword.set(auth.substring(colon + 1));
        request.setHandled(false);
      }
    };

    HandlerList handlerList = new HandlerList();
    handlerList.addHandler(proxyCountingHandler);
    handlerList.addHandler(proxyHandler);
    proxy.setHandler(handlerList);

    ServletHolder proxyHolder = proxyHandler.addServletWithMapping("org.eclipse.jetty.servlets.ProxyServlet", "/");
    proxyHolder.setAsyncSupported(true);

    proxy.start();

    proxyPort = proxyConnector.getLocalPort();

    return "http://localhost:" + connector.getLocalPort();
  }
View Full Code Here

public class Launcher {
    public static void main(String[] args) throws Exception {
        Server server = new Server();

        SelectChannelConnector connector = new SelectChannelConnector();
        connector.setPort(8080);
        server.addConnector(connector);

        WebAppContext context = new WebAppContext("webapp", "/");

        if (System.getProperty("os.name").toLowerCase().contains("windows")) {
View Full Code Here


     private static Connector buildConnector() {
        Connector connector;
        if (usingNIO) {
            connector = new SelectChannelConnector();
        } else {
            connector = new SocketConnector();
        }
        connector.setPort(jettyPort);
        connector.setMaxIdleTime(maxIdleTime);
View Full Code Here

        }
        return answer;
    }

    protected Connector createSocketConnector() throws Exception {
        SelectChannelConnector answer = new SelectChannelConnector();
        if (getSocketConnectorProperties() != null) {
            // must copy the map otherwise it will be deleted
            Map<String, Object> properties = new HashMap<String, Object>(getSocketConnectorProperties());
            IntrospectionSupport.setProperties(answer, properties);
            if (properties.size() > 0) {
                throw new IllegalArgumentException("There are " + properties.size()
                    + " parameters that couldn't be set on the SocketConnector."
                    + " Check the uri if the parameters are spelt correctly and that they are properties of the SelectChannelConnector."
                    + " Unknown parameters=[" + properties + "]");
            }
        }

        if (requestBufferSize != null) {
            answer.setRequestBufferSize(requestBufferSize);
        }
        if (requestHeaderSize != null) {
            answer.setRequestHeaderSize(requestHeaderSize);
        }
        if (responseBufferSize != null) {
            answer.setResponseBufferSize(responseBufferSize);
        }
        if (responseHeaderSize != null) {
            answer.setResponseBufferSize(responseHeaderSize);
        }
        return answer;
    }
View Full Code Here

    protected Server server;

    @Before
    public void setUp() throws Exception {
        server = new Server();
        Connector connector = new SelectChannelConnector();
        connector.setHost("localhost");
        connector.setPort(PORT);
        server.addConnector(connector);
       
        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
        context.setContextPath("/");
        server.setHandler(context);
View Full Code Here

                        + port
                        + "\n-------------------------------------------------\n");

        final Server server = new Server();

        final Connector connector = new SelectChannelConnector();

        connector.setPort(port);
        if (serverArgs.containsKey("withssl")) {
            final SslSocketConnector sslConnector = new SslSocketConnector();
            sslConnector.setPort(8444);
            SslContextFactory sslFact = sslConnector.getSslContextFactory();
            sslFact.setTrustStore(KEYSTORE);
View Full Code Here

  }

  @Provides
  @Singleton
  Connector getConnector(final Injector injector) {
    final Connector conn = new SelectChannelConnector();
    WebServerConfig webAppConfig = injector.getInstance(WebServerConfig.class);
    conn.setPort(webAppConfig.getPort());
    conn.setHost("127.0.0.1");
    return conn;
  }
View Full Code Here

        HttpServletRequest request = VaadinServletService
                .getCurrentServletRequest();

        // Set up a server
        server = new Server();
        SelectChannelConnector connector = new SelectChannelConnector();
        // Uses random available port by default, uncomment this to make local
        // testing easier (you can just reload old tab after restarting proxy)
        // connector.setPort(8889);
        server.setConnectors(new Connector[] { connector });

        // Create root context and add the ProxyServlet.Transparent to it
        ServletContextHandler contextHandler = new ServletContextHandler();
        server.setHandler(contextHandler);
        contextHandler.setContextPath("/");
        ServletHolder servletHolder = contextHandler.addServlet(
                ProxyServlet.Transparent.class, "/*");

        // Configure servlet to forward to the root of the original server
        servletHolder.setInitParameter(
                "ProxyTo",
                "http://" + request.getLocalAddr() + ":"
                        + request.getLocalPort() + "/");
        // Configure servlet to strip beginning of paths
        servletHolder.setInitParameter("Prefix", "/proxypath/");

        // Start the server
        try {
            server.start();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        // Add links to some proxied urls to tests
        String linkBase = "http://" + request.getLocalName() + ":"
                + connector.getLocalPort() + "/proxypath/";

        linkHolder.removeAllComponents();
        linkHolder.addComponent(new Link("Open embed1 in proxy",
                new ExternalResource(linkBase + "embed1")));
        linkHolder.addComponent(new Link("Open embed1/ in proxy",
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.server.nio.SelectChannelConnector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.