Package org.asynchttpclient

Examples of org.asynchttpclient.Request


                .setFollowRedirect(true)//
                .build();

        AsyncHttpClient c = getAsyncHttpClient(config);
        try {
            Request r = new RequestBuilder("GET").setUrl(servletEndpointRedirectUrl).build();

            ListenableFuture<Response> response = c.executeRequest(r);
            Response res = null;
            res = response.get();
            assertNotNull(res.getResponseBody());
View Full Code Here


                ctx.getRequest().getHeaders().remove("x-redirect");
                return ctx;
            }
        }).build());
        try {
            Request request = new RequestBuilder("POST").setUrl(getTargetUrl()).addFormParam("q", "a b").addHeader("x-redirect", +status + "@" + "http://localhost:" + port1 + "/foo/bar/baz").addHeader("x-negative", "true").build();
            Future<Integer> responseFuture = p.executeRequest(request, new AsyncCompletionHandler<Integer>() {

                @Override
                public Integer onCompleted(Response response) throws Exception {
                    return response.getStatusCode();
View Full Code Here

                ctx.getRequest().getHeaders().remove("x-redirect");
                return ctx;
            }
        }).build());
        try {
            Request request = new RequestBuilder("POST").setUrl(getTargetUrl()).addFormParam("q", "a b").addHeader("x-redirect", +status + "@" + "http://localhost:" + port1 + "/foo/bar/baz").build();
            Future<Integer> responseFuture = p.executeRequest(request, new AsyncCompletionHandler<Integer>() {

                @Override
                public Integer onCompleted(Response response) throws Exception {
                    return response.getStatusCode();
View Full Code Here

    @Test(groups = { "standalone", "default_provider" })
    public void testHEAD302() throws IOException, BrokenBarrierException, InterruptedException, ExecutionException, TimeoutException {
        AsyncHttpClient client = getAsyncHttpClient(null);
        try {
            final CountDownLatch l = new CountDownLatch(1);
            Request request = new RequestBuilder("HEAD").setUrl("http://127.0.0.1:" + port1 + "/Test").build();

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

    public void testMultipleOtherHeaders() throws IOException, ExecutionException, TimeoutException, InterruptedException {
        final String[] xffHeaders = new String[] { null, null };

        AsyncHttpClient ahc = getAsyncHttpClient(null);
        try {
            Request req = new RequestBuilder("GET").setUrl("http://localhost:" + port1 + "/MultiOther").build();
            final CountDownLatch latch = new CountDownLatch(1);
            ahc.executeRequest(req, new AsyncHandler<Void>() {
                public void onThrowable(Throwable t) {
                    t.printStackTrace(System.out);
                }
View Full Code Here

    public void testMultipleEntityHeaders() throws IOException, ExecutionException, TimeoutException, InterruptedException {
        final String[] clHeaders = new String[] { null, null };

        AsyncHttpClient ahc = getAsyncHttpClient(null);
        try {
            Request req = new RequestBuilder("GET").setUrl("http://localhost:" + port1 + "/MultiEnt").build();
            final CountDownLatch latch = new CountDownLatch(1);
            ahc.executeRequest(req, new AsyncHandler<Void>() {
                public void onThrowable(Throwable t) {
                    t.printStackTrace(System.out);
                }
View Full Code Here

            RequestBuilder builder = new RequestBuilder("POST");
            builder.setUrl(getTargetUrl());
            // made buff in stream big enough to mark.
            builder.setBody(new InputStreamBodyGenerator(new BufferedInputStream(new FileInputStream(LARGE_IMAGE_FILE), 400000)));

            Request r = builder.build();

            Response response = c.executeRequest(r).get();
            if (500 == response.getStatusCode()) {
                StringBuilder sb = new StringBuilder();
                sb.append("==============\n");
View Full Code Here

            final Uri requestUri = tunnelRequestEvent.getUri();

            RequestBuilder builder = new RequestBuilder();
            builder.setMethod(Method.CONNECT.getMethodString());
            builder.setUrl("http://" + getAuthority(requestUri));
            Request request = builder.build();

            AsyncHandler handler = new AsyncCompletionHandler() {
                @Override
                public Object onCompleted(Response response) throws Exception {
                    if (response.getStatusCode() != 200) {
View Full Code Here

        if (checkProxyAuthFailure(ctx, httpTxContext)) {
            return true;
        }

        final Request request = httpTxContext.getRequest();
        final Uri uri = request.getUri();
        boolean secure = Utils.isSecure(uri);
        boolean isWebSocket = isWSRequest(httpTxContext.getRequestUri());

        // If the request is secure, check to see if an error occurred during
        // the handshake. We have to do this here, as the error would occur
        // out of the scope of a HttpTxContext so there would be
        // no good way to communicate the problem to the caller.
        if (secure && checkHandshakeError(ctx, httpTxContext)) {
            return true;
        }

       
        if (isUpgradeRequest(httpTxContext.getHandler()) && isWebSocket) {
            httpTxContext.setWSRequest(true);
            convertToUpgradeRequest(httpTxContext);
        }

        HttpRequestPacket requestPacket = requestCache.poll();
        if (requestPacket == null) {
            requestPacket = new HttpRequestPacketImpl();
        }
       
        final Method method = Method.valueOf(request.getMethod());
       
        requestPacket.setMethod(method);
        requestPacket.setProtocol(Protocol.HTTP_1_1);

        // Special handling for CONNECT.
        if (method == Method.CONNECT) {
            final int port = uri.getPort();
            requestPacket.setRequestURI(uri.getHost() + ':' + (port == -1 ? 443 : port));
        } else if ((secure || isWebSocket) && config.isUseRelativeURIsWithConnectProxies()) {
            requestPacket.setRequestURI(getNonEmptyPath(uri));
        } else {
            requestPacket.setRequestURI(uri.toUrl());
        }

        final BodyHandler bodyHandler = isPayloadAllowed(method) ?
                bodyHandlerFactory.getBodyHandler(request) :
                null;
       
        if (bodyHandler != null) {
            final long contentLength = request.getContentLength();
            if (contentLength >= 0) {
                requestPacket.setContentLengthLong(contentLength);
                requestPacket.setChunked(false);
            } else {
                requestPacket.setChunked(true);
View Full Code Here

            return true;
        }

        responsePacket.setSkipRemainder(true); // ignore the remainder of the response

        final Request req = httpTransactionContext.getRequest();
        realm = new Realm.RealmBuilder().clone(realm).setScheme(realm.getAuthScheme()).setUri(req.getUri())
                .setMethodName(req.getMethod()).setUsePreemptiveAuth(true).parseWWWAuthenticateHeader(auth).build();
        String lowerCaseAuth = auth.toLowerCase(Locale.ENGLISH);
        if (lowerCaseAuth.startsWith("basic")) {
            req.getHeaders().remove(Header.Authorization.toString());
            req.getHeaders().add(Header.Authorization.toString(), AuthenticatorUtils.computeBasicAuthentication(realm));
        } else if (lowerCaseAuth.startsWith("digest")) {
            req.getHeaders().remove(Header.Authorization.toString());
            req.getHeaders().add(Header.Authorization.toString(), AuthenticatorUtils.computeDigestAuthentication(realm));
        } else {
            throw new IllegalStateException("Unsupported authorization method: " + auth);
        }

        try {
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.