Package org.asynchttpclient

Examples of org.asynchttpclient.ProxyServer


    @Test(groups = { "standalone", "default_provider" })
    public void testRequestLevelProxy() throws IOException, ExecutionException, TimeoutException, InterruptedException {
        AsyncHttpClient client = getAsyncHttpClient(null);
        try {
            String target = "http://127.0.0.1:1234/";
            Future<Response> f = client.prepareGet(target).setProxyServer(new ProxyServer("127.0.0.1", port1)).execute();
            Response resp = f.get(3, TimeUnit.SECONDS);
            assertNotNull(resp);
            assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
            assertEquals(resp.getHeader("target"), "/");
        } finally {
View Full Code Here


        }
    }

    @Test(groups = { "standalone", "default_provider" })
    public void testGlobalProxy() throws IOException, ExecutionException, TimeoutException, InterruptedException {
        AsyncHttpClientConfig cfg = new AsyncHttpClientConfig.Builder().setProxyServer(new ProxyServer("127.0.0.1", port1)).build();
        AsyncHttpClient client = getAsyncHttpClient(cfg);
        try {
            String target = "http://127.0.0.1:1234/";
            Future<Response> f = client.prepareGet(target).execute();
            Response resp = f.get(3, TimeUnit.SECONDS);
View Full Code Here

        }
    }

    @Test(groups = { "standalone", "default_provider" })
    public void testBothProxies() throws IOException, ExecutionException, TimeoutException, InterruptedException {
        AsyncHttpClientConfig cfg = new AsyncHttpClientConfig.Builder().setProxyServer(new ProxyServer("127.0.0.1", port1 - 1)).build();
        AsyncHttpClient client = getAsyncHttpClient(cfg);
        try {
            String target = "http://127.0.0.1:1234/";
            Future<Response> f = client.prepareGet(target).setProxyServer(new ProxyServer("127.0.0.1", port1)).execute();
            Response resp = f.get(3, TimeUnit.SECONDS);
            assertNotNull(resp);
            assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
            assertEquals(resp.getHeader("target"), "/");
        } finally {
View Full Code Here

        }
    }

    @Test(groups = { "standalone", "default_provider" })
    public void testNonProxyHosts() throws IOException, ExecutionException, TimeoutException, InterruptedException {
        AsyncHttpClientConfig cfg = new AsyncHttpClientConfig.Builder().setProxyServer(new ProxyServer("127.0.0.1", port1 - 1)).build();
        AsyncHttpClient client = getAsyncHttpClient(cfg);
        try {

            String target = "http://127.0.0.1:1234/";
            client.prepareGet(target).setProxyServer(new ProxyServer("127.0.0.1", port1).addNonProxyHost("127.0.0.1")).execute().get();
            assertFalse(true);
        } catch (Throwable e) {
            assertNotNull(e.getCause());
            assertEquals(e.getCause().getClass(), ConnectException.class);
        } finally {
View Full Code Here

    @Test(groups = { "standalone", "default_provider" })
    public void testNonProxyHostIssue202() throws IOException, ExecutionException, TimeoutException, InterruptedException {
        AsyncHttpClient client = getAsyncHttpClient(null);
        try {
            String target = "http://127.0.0.1:" + port1 + "/";
            Future<Response> f = client.prepareGet(target).setProxyServer(new ProxyServer("127.0.0.1", port1 - 1).addNonProxyHost("127.0.0.1")).execute();
            Response resp = f.get(3, TimeUnit.SECONDS);
            assertNotNull(resp);
            assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
            assertEquals(resp.getHeader("target"), "/");
        } finally {
View Full Code Here

    }

    @Test(groups = { "online", "default_provider" })
    public void testRequestProxy() throws IOException, InterruptedException, ExecutionException, TimeoutException {

        ProxyServer ps = new ProxyServer(ProxyServer.Protocol.HTTPS, "127.0.0.1", port1);

        AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()//
        .setFollowRedirect(true)//
        .setAcceptAnyCertificate(true)//
        .build();
View Full Code Here

    @Test(groups = { "online", "default_provider" })
    public void testConfigProxy() throws IOException, InterruptedException, ExecutionException, TimeoutException {
        AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()//
                .setFollowRedirect(true)//
                .setProxyServer(new ProxyServer(ProxyServer.Protocol.HTTPS, "127.0.0.1", port1))//
                .setAcceptAnyCertificate(true)//
                .build();
        AsyncHttpClient asyncHttpClient = getAsyncHttpClient(config);
        try {
            Future<Response> responseFuture = asyncHttpClient.executeRequest(new RequestBuilder("GET").setUrl(getTargetUrl2()).build(), new AsyncCompletionHandlerBase() {
View Full Code Here

        } else if (type == TunnelRequestEvent.class) {
            // Disable SSL for the time being...
            ctx.notifyDownstream(new SSLSwitchingEvent(false, ctx.getConnection()));
            ctx.suspend();
            TunnelRequestEvent tunnelRequestEvent = (TunnelRequestEvent) event;
            final ProxyServer proxyServer = tunnelRequestEvent.getProxyServer();
            final Uri requestUri = tunnelRequestEvent.getUri();

            RequestBuilder builder = new RequestBuilder();
            builder.setMethod(Method.CONNECT.getMethodString());
            builder.setUrl("http://" + getAuthority(requestUri));
View Full Code Here

        }
    }

    @Test(groups = { "standalone", "default_provider", "async" })
    public void asyncDoPostProxyTest() throws Exception {
        AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setProxyServer(new ProxyServer("127.0.0.1", port2)).build());
        try {
            FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap();
            h.add("Content-Type", "application/x-www-form-urlencoded");
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 5; i++) {
View Full Code Here

        if (proxyAuth == null) {
            throw new IllegalStateException("407 response received, but no Proxy Authenticate header was present");
        }

        final Request req = httpTransactionContext.getRequest();
        ProxyServer proxyServer = httpTransactionContext.getProvider().getClientConfig().getProxyServerSelector()
                .select(req.getUri());
        String principal = proxyServer.getPrincipal();
        String password = proxyServer.getPassword();
        Realm realm = new Realm.RealmBuilder().setPrincipal(principal).setPassword(password).setUri(req.getUri()).setOmitQuery(true)
                .setMethodName(Method.CONNECT.getMethodString()).setUsePreemptiveAuth(true).parseProxyAuthenticateHeader(proxyAuth).build();
        String proxyAuthLowerCase = proxyAuth.toLowerCase(Locale.ENGLISH);
        if (proxyAuthLowerCase.startsWith("basic")) {
            req.getHeaders().remove(Header.ProxyAuthenticate.toString());
            req.getHeaders().remove(Header.ProxyAuthorization.toString());
            req.getHeaders().add(Header.ProxyAuthorization.toString(), AuthenticatorUtils.computeBasicAuthentication(realm));
        } else if (proxyAuthLowerCase.startsWith("digest")) {
            req.getHeaders().remove(Header.ProxyAuthenticate.toString());
            req.getHeaders().remove(Header.ProxyAuthorization.toString());
            req.getHeaders().add(Header.ProxyAuthorization.toString(), AuthenticatorUtils.computeDigestAuthentication(realm));
        } else if (proxyAuthLowerCase.startsWith("ntlm")) {

            req.getHeaders().remove(Header.ProxyAuthenticate.toString());
            req.getHeaders().remove(Header.ProxyAuthorization.toString());

            String msg;
            try {
                if (isNTLMFirstHandShake(proxyAuth)) {
                    msg = GrizzlyAsyncHttpProvider.NTLM_ENGINE.generateType1Msg();
                } else {
                    String serverChallenge = proxyAuth.trim().substring("NTLM ".length());
                    msg = GrizzlyAsyncHttpProvider.NTLM_ENGINE.generateType3Msg(principal, password, proxyServer.getNtlmDomain(),
                            proxyServer.getHost(), serverChallenge);
                }

                req.getHeaders().add(Header.ProxyAuthorization.toString(), "NTLM " + msg);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        } else if (proxyAuthLowerCase.startsWith("negotiate")) {
            //this is for kerberos
            req.getHeaders().remove(Header.ProxyAuthenticate.toString());
            req.getHeaders().remove(Header.ProxyAuthorization.toString());
        } else {
            throw new IllegalStateException("Unsupported authorization method: " + proxyAuth);
        }

        InvocationStatus tempInvocationStatus = InvocationStatus.STOP;

        try {
            if (isNTLMFirstHandShake(proxyAuth)) {
                tempInvocationStatus = InvocationStatus.CONTINUE;
            }
            if (proxyAuth.toLowerCase().startsWith("negotiate")) {
                final Connection c = getConnectionForNextRequest(ctx, req, responsePacket, httpTransactionContext);
                final HttpTxContext newContext = httpTransactionContext.copy();
                httpTransactionContext.setFuture(null);
                HttpTxContext.set(ctx, newContext);

                newContext.setInvocationStatus(tempInvocationStatus);

                String challengeHeader;
                String server = proxyServer.getHost();

                challengeHeader = GSSSPNEGOWrapper.generateToken(server);

                req.getHeaders().add(Header.ProxyAuthorization.toString(), "Negotiate " + challengeHeader);
View Full Code Here

TOP

Related Classes of org.asynchttpclient.ProxyServer

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.