Examples of HttpTxContext


Examples of org.asynchttpclient.providers.grizzly.HttpTxContext

    private boolean sendAsGrizzlyRequest(
            final RequestInfoHolder requestInfoHolder,
            final FilterChainContext ctx) throws IOException {

        HttpTxContext httpTxContext = requestInfoHolder.getHttpTxContext();
        if (httpTxContext == null) {
            httpTxContext = HttpTxContext.create(requestInfoHolder);
        }

        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);
            }
        }

        if (httpTxContext.isWSRequest()) {
            try {
                final URI wsURI = httpTxContext.getWsRequestURI().toJavaNetURI();
                httpTxContext.setProtocolHandler(Version.RFC6455.createHandler(true));
                httpTxContext.setHandshake(httpTxContext.getProtocolHandler().createHandShake(wsURI));
                requestPacket = (HttpRequestPacket) httpTxContext.getHandshake().composeHeaders().getHttpHeader();
            } catch (URISyntaxException e) {
                throw new IllegalArgumentException("Invalid WS URI: " + httpTxContext.getWsRequestURI());
            }
        }

        requestPacket.setSecure(secure);
        addQueryString(request, requestPacket);
        addHostHeader(request, uri, requestPacket);
        addGeneralHeaders(request, requestPacket);
        addCookies(request, requestPacket);
        addAuthorizationHeader(request, requestPacket);

        initTransferCompletionHandler(request, httpTxContext.getHandler());

        final HttpRequestPacket requestPacketLocal = requestPacket;
        FilterChainContext sendingCtx = ctx;

        if (secure) {
View Full Code Here

Examples of org.asynchttpclient.providers.grizzly.HttpTxContext

            throws IOException {

        boolean isWriteComplete = true;

        if (bodyHandler != null) {
            final HttpTxContext context = HttpTxContext.get(ctx);
            context.setBodyHandler(bodyHandler);
            if (logger.isDebugEnabled()) {
                logger.debug("REQUEST: {}", requestPacket);
            }
            isWriteComplete = bodyHandler.doHandle(ctx, request, requestPacket);
        } else {
View Full Code Here

Examples of org.asynchttpclient.providers.grizzly.HttpTxContext

    @SuppressWarnings({ "unchecked" })
    public boolean doHandle(final FilterChainContext ctx, final Request request, final HttpRequestPacket requestPacket) throws IOException {

        final File f = request.getFile();
        requestPacket.setContentLengthLong(f.length());
        final HttpTxContext context = HttpTxContext.get(ctx);
        if (!SEND_FILE_SUPPORT || requestPacket.isSecure()) {
            final FileInputStream fis = new FileInputStream(request.getFile());
            final MemoryManager mm = ctx.getMemoryManager();
            AtomicInteger written = new AtomicInteger();
            boolean last = false;
View Full Code Here

Examples of org.asynchttpclient.providers.grizzly.HttpTxContext

            throw new IllegalStateException("Unsupported authorization method: " + auth);
        }

        try {
            final Connection c = getConnectionForNextRequest(ctx, req, responsePacket, httpTransactionContext);
            final HttpTxContext newContext = httpTransactionContext.copy();
            httpTransactionContext.setFuture(null);
            HttpTxContext.set(ctx, newContext);
            newContext.setInvocationStatus(STOP);
            httpTransactionContext.getProvider().execute(c, req, httpTransactionContext.getHandler(), httpTransactionContext.getFuture(),
                    newContext);
            return false;
        } catch (Exception e) {
            httpTransactionContext.abort(e);
View Full Code Here

Examples of org.asynchttpclient.providers.grizzly.HttpTxContext

        }

        final ConnectionManager m = httpTransactionContext.getProvider().getConnectionManager();
        try {
            final Connection c = m.obtainConnection(requestToSend, httpTransactionContext.getFuture());
            final HttpTxContext newContext = httpTransactionContext.copy();
            httpTransactionContext.setFuture(null);
            newContext.setInvocationStatus(CONTINUE);
            newContext.setRequest(requestToSend);
            newContext.setRequestUri(requestToSend.getUri());
            HttpTxContext.set(ctx, newContext);
            httpTransactionContext.getProvider().execute(c, requestToSend, newContext.getHandler(), newContext.getFuture(), newContext);
            return false;
        } catch (Exception e) {
            httpTransactionContext.abort(e);
        }
View Full Code Here

Examples of org.asynchttpclient.providers.grizzly.HttpTxContext

            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();

                httpTransactionContext.setFuture(null);
                HttpTxContext.set(ctx, newContext);

                newContext.setInvocationStatus(tempInvocationStatus);

                return executeRequest(httpTransactionContext, req, c, newContext);

            } else {
                final Connection c = getConnectionForNextRequest(ctx, req, responsePacket, httpTransactionContext);
                final HttpTxContext newContext = httpTransactionContext.copy();
                httpTransactionContext.setFuture(null);
                HttpTxContext.set(ctx, newContext);

                newContext.setInvocationStatus(tempInvocationStatus);

                //NTLM needs the same connection to be used for exchange of tokens
                return executeRequest(httpTransactionContext, req, c, newContext);
            }
        } catch (Exception e) {
View Full Code Here

Examples of org.asynchttpclient.providers.grizzly.HttpTxContext

        final Object msg = ctx.getMessage();
        if (HttpPacket.isHttp(msg)) {
            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
TOP
Copyright © 2018 www.massapi.com. 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.