Package io.undertow.client

Examples of io.undertow.client.ClientConnection


  protected ResponseEntity<String> executeRequest(URI url, HttpString method, HttpHeaders headers, String body) {

    final CountDownLatch latch = new CountDownLatch(1);
    final List<ClientResponse> responses = new CopyOnWriteArrayList<ClientResponse>();
    try {
      final ClientConnection connection = this.httpClient.connect(url, this.worker,
          this.bufferPool, this.optionMap).get();
      try {
        final ClientRequest request = new ClientRequest().setMethod(method).setPath(url.getPath());
        request.getRequestHeaders().add(HttpString.tryFromString(HttpHeaders.HOST), url.getHost());
        if (body !=null && !body.isEmpty()) {
          request.getRequestHeaders().add(HttpString.tryFromString(HttpHeaders.CONTENT_LENGTH), body.length());
        }
        addHttpHeaders(request, headers);
        connection.sendRequest(request, createRequestCallback(body, responses, latch));

        latch.await();
        final ClientResponse response = responses.iterator().next();
        HttpStatus status = HttpStatus.valueOf(response.getResponseCode());
        HttpHeaders responseHeaders = toHttpHeaders(response.getResponseHeaders());
View Full Code Here


                @Override
                public void run() {
                    ProxyConnection connectionAttachment = exchange.getAttachment(CONNECTION);
                    if(connectionAttachment != null) {
                        //we rely on the close listener to end the exchange
                        ClientConnection clientConnection = connectionAttachment.getConnection();
                        IoUtils.safeClose(clientConnection);
                    } else {
                        exchange.setResponseCode(503);
                        exchange.endExchange();
                    }
View Full Code Here

                @Override
                public void run() {
                    ProxyConnection connectionAttachment = exchange.getAttachment(CONNECTION);
                    if(connectionAttachment != null) {
                        //we rely on the close listener to end the exchange
                        ClientConnection clientConnection = connectionAttachment.getConnection();
                        IoUtils.safeClose(clientConnection);
                    } else {
                        exchange.setResponseCode(503);
                        exchange.endExchange();
                    }
View Full Code Here

    void returnConnection(final ClientConnection connection) {
        HostThreadData hostData = getData();
        if (closed) {
            //the host has been closed
            IoUtils.safeClose(connection);
            ClientConnection con = hostData.availbleConnections.poll();
            while (con != null) {
                IoUtils.safeClose(con);
                con = hostData.availbleConnections.poll();
            }
            redistributeQueued(hostData);
View Full Code Here

        return data;
    }

    public void connect(HttpServerExchange exchange, ProxyCallback<ProxyConnection> callback, final long timeout, final TimeUnit timeUnit) {
        HostThreadData data = getData();
        ClientConnection conn = data.availbleConnections.poll();
        while (conn != null && !conn.isOpen()) {
            conn = data.availbleConnections.poll();
        }
        if (conn != null) {
            connectionReady(conn, callback, exchange);
        } else if (data.connections < loadBalancingProxyClient.getConnectionsPerThread()) {
View Full Code Here

                            connection.putAttachment(exclusiveConnectionKey, newHolder);
                            connection.addCloseListener(new ServerConnection.CloseListener() {

                                @Override
                                public void closed(ServerConnection connection) {
                                    ClientConnection clientConnection = newHolder.connection.getConnection();
                                    if (clientConnection.isOpen()) {
                                        safeClose(clientConnection);
                                    }
                                }
                            });
                        }
View Full Code Here

            final XnioExecutor.Key key = exchange.getIoThread().executeAfter(new Runnable() {
                @Override
                public void run() {
                    UndertowLogger.REQUEST_LOGGER.proxyRequestTimedOut(exchange.getRequestURI());
                    IoUtils.safeClose(exchange.getConnection());
                    ClientConnection clientConnection = exchange.getAttachment(ProxyClient.CONNECTION);
                    IoUtils.safeClose(clientConnection);
                }
            }, maxRequestTime, TimeUnit.MILLISECONDS);
            exchange.putAttachment(TIMEOUT_KEY, key);
            exchange.addExchangeCompleteListener(new ExchangeCompletionListener() {
View Full Code Here

                            connection.putAttachment(exclusiveConnectionKey, newHolder);
                            connection.addCloseListener(new ServerConnection.CloseListener() {

                                @Override
                                public void closed(ServerConnection connection) {
                                    ClientConnection clientConnection = newHolder.connection.getConnection();
                                    if (clientConnection.isOpen()) {
                                        safeClose(clientConnection);
                                    }
                                }
                            });
                        }
View Full Code Here

        return TARGET;
    }

    @Override
    public void getConnection(ProxyTarget target, HttpServerExchange exchange, ProxyCallback<ProxyConnection> callback, long timeout, TimeUnit timeUnit) {
        ClientConnection existing = exchange.getConnection().getAttachment(clientAttachmentKey);
        if (existing != null) {
            if (existing.isOpen()) {
                //this connection already has a client, re-use it
                callback.completed(exchange, new ProxyConnection(existing, uri.getPath() == null ? "/" : uri.getPath()));
                return;
            } else {
                exchange.getConnection().removeAttachment(clientAttachmentKey);
View Full Code Here

    private void returnConnection(final ClientConnection connection) {
        HostThreadData hostData = getData();
        if (closed) {
            //the host has been closed
            IoUtils.safeClose(connection);
            ClientConnection con = hostData.availableConnections.poll();
            while (con != null) {
                IoUtils.safeClose(con);
                con = hostData.availableConnections.poll();
            }
            redistributeQueued(hostData);
View Full Code Here

TOP

Related Classes of io.undertow.client.ClientConnection

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.