Search in sources :

Example 1 with EchoHandler

use of org.asynchttpclient.test.EchoHandler in project async-http-client by AsyncHttpClient.

the class BasicHttpProxyToHttpsTest method setUpGlobal.

@BeforeClass(alwaysRun = true)
public void setUpGlobal() throws Exception {
    // HTTP server
    httpServer = new Server();
    ServerConnector connector1 = addHttpsConnector(httpServer);
    httpServer.setHandler(new EchoHandler());
    httpServer.start();
    httpPort = connector1.getLocalPort();
    // proxy
    proxy = new Server();
    ServerConnector connector2 = addHttpConnector(proxy);
    ConnectHandler connectHandler = new ConnectHandler() {

        @Override
        protected boolean handleAuthentication(HttpServletRequest request, HttpServletResponse response, String address) {
            String authorization = request.getHeader(PROXY_AUTHORIZATION.toString());
            if (authorization == null) {
                response.setStatus(HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED);
                response.setHeader(PROXY_AUTHENTICATE.toString(), "Basic realm=\"Fake Realm\"");
                return false;
            } else if (authorization.equals("Basic am9obmRvZTpwYXNz")) {
                return true;
            }
            response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
            return false;
        }
    };
    proxy.setHandler(connectHandler);
    proxy.start();
    proxyPort = connector2.getLocalPort();
    LOGGER.info("Local HTTP Server (" + httpPort + "), Proxy (" + proxyPort + ") started successfully");
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpServletRequest(javax.servlet.http.HttpServletRequest) ConnectHandler(org.eclipse.jetty.proxy.ConnectHandler) Server(org.eclipse.jetty.server.Server) HttpServletResponse(javax.servlet.http.HttpServletResponse) EchoHandler(org.asynchttpclient.test.EchoHandler) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with EchoHandler

use of org.asynchttpclient.test.EchoHandler in project async-http-client by AsyncHttpClient.

the class AbstractAsyncHttpClientFactoryTest method setUpBeforeTest.

@BeforeClass(alwaysRun = true)
public void setUpBeforeTest() throws Exception {
    server = new Server();
    ServerConnector connector = addHttpConnector(server);
    server.setHandler(new EchoHandler());
    server.start();
    port = connector.getLocalPort();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) EchoHandler(org.asynchttpclient.test.EchoHandler) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with EchoHandler

use of org.asynchttpclient.test.EchoHandler in project async-http-client by AsyncHttpClient.

the class HttpsProxyTest method setUpGlobal.

@BeforeClass(alwaysRun = true)
public void setUpGlobal() throws Exception {
    server = new Server();
    ServerConnector connector = addHttpConnector(server);
    server.setHandler(configureHandler());
    server.start();
    port1 = connector.getLocalPort();
    server2 = new Server();
    ServerConnector connector2 = addHttpsConnector(server2);
    server2.setHandler(new EchoHandler());
    server2.start();
    port2 = connector2.getLocalPort();
    logger.info("Local HTTP server started successfully");
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) EchoHandler(org.asynchttpclient.test.EchoHandler) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with EchoHandler

use of org.asynchttpclient.test.EchoHandler in project async-http-client by AsyncHttpClient.

the class HttpsProxyTest method setUpGlobal.

@BeforeClass(alwaysRun = true)
public void setUpGlobal() throws Exception {
    server = new Server();
    ServerConnector connector1 = addHttpConnector(server);
    server.setHandler(configureHandler());
    server.start();
    port1 = connector1.getLocalPort();
    server2 = new Server();
    ServerConnector connector2 = addHttpsConnector(server2);
    server2.setHandler(new EchoHandler());
    server2.start();
    port2 = connector2.getLocalPort();
    logger.info("Local HTTP server started successfully");
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) EchoHandler(org.asynchttpclient.test.EchoHandler) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with EchoHandler

use of org.asynchttpclient.test.EchoHandler in project async-http-client by AsyncHttpClient.

the class BasicHttpProxyToHttpTest method setUpGlobal.

@BeforeClass
public void setUpGlobal() throws Exception {
    httpServer = new Server();
    ServerConnector connector1 = addHttpConnector(httpServer);
    httpServer.setHandler(new EchoHandler());
    httpServer.start();
    httpPort = connector1.getLocalPort();
    proxy = new Server();
    ServerConnector connector2 = addHttpConnector(proxy);
    ServletHandler servletHandler = new ServletHandler();
    ServletHolder servletHolder = servletHandler.addServletWithMapping(BasicAuthProxyServlet.class, "/*");
    servletHolder.setInitParameter("maxThreads", "20");
    proxy.setHandler(servletHandler);
    proxy.start();
    proxyPort = connector2.getLocalPort();
    LOGGER.info("Local HTTP Server (" + httpPort + "), Proxy (" + proxyPort + ") started successfully");
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) EchoHandler(org.asynchttpclient.test.EchoHandler) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

EchoHandler (org.asynchttpclient.test.EchoHandler)5 Server (org.eclipse.jetty.server.Server)5 ServerConnector (org.eclipse.jetty.server.ServerConnector)5 BeforeClass (org.testng.annotations.BeforeClass)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ConnectHandler (org.eclipse.jetty.proxy.ConnectHandler)1 ServletHandler (org.eclipse.jetty.servlet.ServletHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1