Package org.asynchttpclient

Examples of org.asynchttpclient.Request


    @Test(groups = { "standalone", "default_provider", "async" }, enabled = false)
    public void asyncStatusHEADContentLenghtTest() throws Exception {
        AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeout(120 * 1000).build());
        try {
            final CountDownLatch l = new CountDownLatch(1);
            Request request = new RequestBuilder("HEAD").setUrl(getTargetUrl()).build();

            client.executeRequest(request, new AsyncCompletionHandlerAdapter() {
                @Override
                public Response onCompleted(Response response) throws Exception {
                    fail();
View Full Code Here


            Map<String, List<String>> m = new HashMap<String, List<String>>();
            for (int i = 0; i < 5; i++) {
                m.put("param_" + i, Arrays.asList("value_" + i));
            }
            Request request = new RequestBuilder("POST").setUrl(getTargetUrl()).setHeaders(h).setFormParams(m).setVirtualHost("localhost:" + port1).build();

            Response response = client.executeRequest(request, new AsyncCompletionHandlerAdapter()).get();

            assertEquals(response.getStatusCode(), 200);
            if (response.getHeader("X-Host").startsWith("localhost")) {
View Full Code Here

                    }
                    return response;
                }
            };

            Request req = new RequestBuilder("GET").setUrl(getTargetUrl() + "?foo=bar").build();

            client.executeRequest(req, handler).get();

            if (!l.await(TIMEOUT, TimeUnit.SECONDS)) {
                fail("Timed out");
View Full Code Here

        final String proxyAuth = responsePacket.getHeader(Header.ProxyAuthenticate);
        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);

                return executeRequest(httpTransactionContext, req, c, newContext);
            } else if (isNTLMSecondHandShake(proxyAuth)) {
                final Connection c = ctx.getConnection();
                final HttpTxContext newContext = httpTransactionContext.copy();
View Full Code Here

    }

    @Override
    public void handle(Channel channel, NettyResponseFuture<?> future, Object e) throws Exception {
        WebSocketUpgradeHandler handler = WebSocketUpgradeHandler.class.cast(future.getAsyncHandler());
        Request request = future.getRequest();

        if (e instanceof HttpResponse) {
            HttpResponse response = (HttpResponse) e;
            // we buffer the response until we get the LastHttpContent
            future.setPendingResponse(response);
View Full Code Here

            HttpPacket httpPacket = (HttpPacket) msg;
            final HttpRequestPacket request = (HttpRequestPacket) httpPacket.getHttpHeader();
            if (!request.isCommitted()) {
                HttpTxContext context = HttpTxContext.get(ctx);
                assert (context != null);
                Request req = context.getRequest();
                if (!secure) {
                    request.setRequestURI(req.getUrl());
                }
                addProxyHeaders(getRealm(req), request);
            }
        }
       
View Full Code Here

*/
public class ResumableIOExceptionFilter implements IOExceptionFilter {
    public <T> FilterContext<T> filter(FilterContext<T> ctx) throws FilterException {
        if (ctx.getIOException() != null && ctx.getAsyncHandler() instanceof ResumableAsyncHandler) {

            Request request = ResumableAsyncHandler.class.cast(ctx.getAsyncHandler()).adjustRequestRange(ctx.getRequest());

            return new FilterContext.FilterContextBuilder<T>(ctx).request(request).replayRequest(true).build();
        }
        return ctx;
    }
View Full Code Here

                        // FIXME don't understand: this offers the connection to the pool, or even closes it, while the
                        // request has not been sent, right?
                        callback.call();
                    }

                    Request redirectRequest = requestBuilder.setUrl(newUrl).build();
                    // FIXME why not reuse the channel is same host?
                    requestSender.sendNextRequest(redirectRequest, future);
                    return true;
                }
            }
View Full Code Here

    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public void replayRequest(final NettyResponseFuture<?> future, FilterContext fc, Channel channel) throws IOException {

        Request newRequest = fc.getRequest();
        future.setAsyncHandler(fc.getAsyncHandler());
        future.setState(NettyResponseFuture.STATE.NEW);
        future.touch();

        LOGGER.debug("\n\nReplaying Request {}\n for Future {}\n", newRequest, future);
View Full Code Here

                            .parseWWWAuthenticateHeader(wwwAuthHeaders.get(0))//
                            .build();
                }

                Realm nr = newRealm;
                final Request nextRequest = new RequestBuilder(future.getRequest()).setHeaders(request.getHeaders()).setRealm(nr).build();

                logger.debug("Sending authentication to {}", request.getUri());
                Callback callback = new Callback(future) {
                    public void call() throws IOException {
                        channelManager.drainChannel(channel, future);
View Full Code Here

TOP

Related Classes of org.asynchttpclient.Request

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.