List of usage examples for io.netty.handler.proxy HttpProxyHandler HttpProxyHandler
public HttpProxyHandler(SocketAddress proxyAddress)
From source file:com.github.sinsinpub.pero.manual.proxyhandler.ProxyHandlerTest.java
License:Apache License
@Parameters(name = "{index}: {0}") public static List<Object[]> testItems() { List<TestItem> items = Arrays.asList( // HTTP ------------------------------------------------------- new SuccessTestItem("Anonymous HTTP proxy: successful connection", DESTINATION, new HttpProxyHandler(anonHttpProxy.address())), new FailureTestItem("Anonymous HTTP proxy: rejected connection", BAD_DESTINATION, "status: 403", new HttpProxyHandler(anonHttpProxy.address())), new FailureTestItem("HTTP proxy: rejected anonymous connection", DESTINATION, "status: 401", new HttpProxyHandler(httpProxy.address())), new SuccessTestItem("HTTP proxy: successful connection", DESTINATION, new HttpProxyHandler(httpProxy.address(), USERNAME, PASSWORD)), new FailureTestItem("HTTP proxy: rejected connection", BAD_DESTINATION, "status: 403", new HttpProxyHandler(httpProxy.address(), USERNAME, PASSWORD)), new FailureTestItem("HTTP proxy: authentication failure", DESTINATION, "status: 401", new HttpProxyHandler(httpProxy.address(), BAD_USERNAME, BAD_PASSWORD)), new TimeoutTestItem("HTTP proxy: timeout", new HttpProxyHandler(deadHttpProxy.address())), // HTTPS ------------------------------------------------------ new SuccessTestItem("Anonymous HTTPS proxy: successful connection", DESTINATION, clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT), new HttpProxyHandler(anonHttpsProxy.address())), new FailureTestItem("Anonymous HTTPS proxy: rejected connection", BAD_DESTINATION, "status: 403", clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT), new HttpProxyHandler(anonHttpsProxy.address())), new FailureTestItem("HTTPS proxy: rejected anonymous connection", DESTINATION, "status: 401", clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT), new HttpProxyHandler(httpsProxy.address())), new SuccessTestItem("HTTPS proxy: successful connection", DESTINATION, clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT), new HttpProxyHandler(httpsProxy.address(), USERNAME, PASSWORD)), new FailureTestItem("HTTPS proxy: rejected connection", BAD_DESTINATION, "status: 403", clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT), new HttpProxyHandler(httpsProxy.address(), USERNAME, PASSWORD)), new FailureTestItem("HTTPS proxy: authentication failure", DESTINATION, "status: 401", clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT), new HttpProxyHandler(httpsProxy.address(), BAD_USERNAME, BAD_PASSWORD)), new TimeoutTestItem("HTTPS proxy: timeout", clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT), new HttpProxyHandler(deadHttpsProxy.address())), // SOCKS5 ----------------------------------------------------- new SuccessTestItem("Anonymous SOCKS5: successful connection", DESTINATION, new Socks5ProxyHandler(anonSocks5Proxy.address())), new FailureTestItem("Anonymous SOCKS5: rejected connection", BAD_DESTINATION, "status: FORBIDDEN", new Socks5ProxyHandler(anonSocks5Proxy.address())), new FailureTestItem("SOCKS5: rejected anonymous connection", DESTINATION, "unexpected authMethod: PASSWORD", new Socks5ProxyHandler(socks5Proxy.address())), new SuccessTestItem("SOCKS5: successful connection", DESTINATION, new Socks5ProxyHandler(socks5Proxy.address(), USERNAME, PASSWORD)), new FailureTestItem("SOCKS5: rejected connection", BAD_DESTINATION, "status: FORBIDDEN", new Socks5ProxyHandler(socks5Proxy.address(), USERNAME, PASSWORD)), new FailureTestItem("SOCKS5: authentication failure", DESTINATION, "authStatus: FAILURE", new Socks5ProxyHandler(socks5Proxy.address(), BAD_USERNAME, BAD_PASSWORD)), new TimeoutTestItem("SOCKS5: timeout", new Socks5ProxyHandler(deadSocks5Proxy.address())), // HTTP + HTTPS + SOCKS5 new SuccessTestItem("Single-chain: successful connection", DESTINATION, new Socks5ProxyHandler(interSocks5Proxy.address()), // SOCKS5 clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT), new HttpProxyHandler(interHttpsProxy.address()), // HTTPS new HttpProxyHandler(interHttpProxy.address()), // HTTP new HttpProxyHandler(anonHttpProxy.address())), // (HTTP + HTTPS + SOCKS5) * 2 new SuccessTestItem("Double-chain: successful connection", DESTINATION, new Socks5ProxyHandler(interSocks5Proxy.address()), // SOCKS5 clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT), new HttpProxyHandler(interHttpsProxy.address()), // HTTPS new HttpProxyHandler(interHttpProxy.address()), // HTTP new Socks5ProxyHandler(interSocks5Proxy.address()), // SOCKS5 clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT), new HttpProxyHandler(interHttpsProxy.address()), // HTTPS new HttpProxyHandler(interHttpProxy.address()), // HTTP new HttpProxyHandler(anonHttpProxy.address())) );/*from ww w . ja v a2s .co m*/ // Convert the test items to the list of constructor parameters. List<Object[]> params = new ArrayList<Object[]>(items.size()); for (Object i : items) { params.add(new Object[] { i }); } // Randomize the execution order to increase the possibility of exposing failure // dependencies. Collections.shuffle(params); return params; }
From source file:org.glowroot.common2.repo.util.HttpClient.java
License:Apache License
private @Nullable HttpProxyHandler newHttpProxyHandlerIfNeeded(HttpProxyConfig httpProxyConfig, @Nullable String passwordOverride) throws Exception { String proxyHost = httpProxyConfig.host(); if (proxyHost.isEmpty()) { return null; }//from w w w .j a v a 2 s . c om int proxyPort = MoreObjects.firstNonNull(httpProxyConfig.port(), 80); SocketAddress proxyAddress = new InetSocketAddress(proxyHost, proxyPort); String username = httpProxyConfig.username(); if (username.isEmpty()) { return new HttpProxyHandler(proxyAddress); } else { String password = getPassword(httpProxyConfig, passwordOverride); return new HttpProxyHandler(proxyAddress, username, password); } }