private static void reverseProxy() throws Exception{ Server server = new Server(); SocketConnector connector = new SocketConnector(); connector.setHost("127.0.0.1"); connector.setPort(8888); server.setConnectors(new Connector[]{connector}); // Setup proxy handler to handle CONNECT methods ConnectHandler proxy = new ConnectHandler(); server.setHandler(proxy); // Setup proxy servlet ServletContextHandler context = new ServletContextHandler(proxy, "/", ServletContextHandler.SESSIONS); ServletHolder proxyServlet = new ServletHolder(ProxyServlet.Transparent.class); proxyServlet.setInitParameter("ProxyTo", "https://localhost:54321/"); proxyServlet.setInitParameter("Prefix", "/"); context.addServlet(proxyServlet, "/*"); server.start(); }
/** * To test that the CF client is able to go through a proxy, we point the CC client to a broken url that can only be resolved by going * through an inJVM proxy which rewrites the URI. This method starts this inJvm proxy. * * @throws Exception */ private static void startInJvmProxy() throws Exception { inJvmProxyPort = getNextAvailablePort(8080); inJvmProxyServer = new Server(new InetSocketAddress("127.0.0.1", inJvmProxyPort)); // forcing use of loopback // that will be used both for Httpclient proxy and SocketDestHelper QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setMinThreads(1); inJvmProxyServer.setThreadPool(threadPool); HandlerCollection handlers = new HandlerCollection(); inJvmProxyServer.setHandler(handlers); ServletHandler servletHandler = new ServletHandler(); handlers.addHandler(servletHandler); nbInJvmProxyRcvReqs = new AtomicInteger(); ChainedProxyServlet chainedProxyServlet = new ChainedProxyServlet(httpProxyConfiguration, nbInJvmProxyRcvReqs); servletHandler.addServletWithMapping(new ServletHolder(chainedProxyServlet), "/*"); // Setup proxy handler to handle CONNECT methods ConnectHandler proxyHandler; proxyHandler = new ChainedProxyConnectHandler(httpProxyConfiguration, nbInJvmProxyRcvReqs); handlers.addHandler(proxyHandler); inJvmProxyServer.start(); }
/** * To test that the CF client is able to go through a proxy, we point the CC client to a broken url * that can only be resolved by going through an inJVM proxy which rewrites the URI. * This method starts this inJvm proxy. * @throws Exception */ private static void startInJvmProxy() throws Exception { inJvmProxyPort = getNextAvailablePort(8080); inJvmProxyServer = new Server(new InetSocketAddress("127.0.0.1", inJvmProxyPort)); //forcing use of loopback that will be used both for Httpclient proxy and SocketDestHelper QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setMinThreads(1); inJvmProxyServer.setThreadPool(threadPool); HandlerCollection handlers = new HandlerCollection(); inJvmProxyServer.setHandler(handlers); ServletHandler servletHandler = new ServletHandler(); handlers.addHandler(servletHandler); nbInJvmProxyRcvReqs = new AtomicInteger(); // ChainedProxyServlet chainedProxyServlet = new ChainedProxyServlet(httpProxyConfiguration, nbInJvmProxyRcvReqs); // servletHandler.addServletWithMapping(new ServletHolder(chainedProxyServlet), "/*"); // Setup proxy handler to handle CONNECT methods ConnectHandler proxyHandler; // proxyHandler = new ChainedProxyConnectHandler(httpProxyConfiguration, nbInJvmProxyRcvReqs); // handlers.addHandler(proxyHandler); inJvmProxyServer.start(); }