当前位置: 首页>>代码示例>>Java>>正文


Java ClientResponse类代码示例

本文整理汇总了Java中io.undertow.client.ClientResponse的典型用法代码示例。如果您正苦于以下问题:Java ClientResponse类的具体用法?Java ClientResponse怎么用?Java ClientResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ClientResponse类属于io.undertow.client包,在下文中一共展示了ClientResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepareResponseChannel

import io.undertow.client.ClientResponse; //导入依赖的package包/类
private void prepareResponseChannel(ClientResponse response, ClientExchange exchange) {
    String encoding = response.getResponseHeaders().getLast(TRANSFER_ENCODING);
    boolean chunked = encoding != null && Headers.CHUNKED.equals(new HttpString(encoding));
    String length = response.getResponseHeaders().getFirst(CONTENT_LENGTH);
    if (exchange.getRequest().getMethod().equals(Methods.HEAD)) {
        connection.getSourceChannel().setConduit(new FixedLengthStreamSourceConduit(connection.getSourceChannel().getConduit(), 0, responseFinishedListener));
    } else if (chunked) {
        connection.getSourceChannel().setConduit(new ChunkedStreamSourceConduit(connection.getSourceChannel().getConduit(), pushBackStreamSourceConduit, bufferPool, responseFinishedListener, exchange));
    } else if (length != null) {
        try {
            long contentLength = Long.parseLong(length);
            connection.getSourceChannel().setConduit(new FixedLengthStreamSourceConduit(connection.getSourceChannel().getConduit(), contentLength, responseFinishedListener));
        } catch (NumberFormatException e) {
            handleError(new IOException(e));
            throw e;
        }
    } else if (response.getProtocol().equals(Protocols.HTTP_1_1)) {
        connection.getSourceChannel().setConduit(new FixedLengthStreamSourceConduit(connection.getSourceChannel().getConduit(), 0, responseFinishedListener));
    } else {
        state |= CLOSE_REQ;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:HttpClientConnection.java

示例2: testHttp2Post

import io.undertow.client.ClientResponse; //导入依赖的package包/类
/**
 * This is an example for post request. Please note that you need to set header TRANSFER_ENCODING
 * and pass the request body into the callback function.
 *
 * @throws Exception
 */
public void testHttp2Post() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    final ClientConnection connection = client.connect(new URI("https://localhost:8443"), Http2Client.WORKER, Http2Client.SSL, Http2Client.POOL, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
    final AtomicReference<ClientResponse> reference = new AtomicReference<>();
    try {
        final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/post");
        if(securityEnabled) {
            // call OAuth 2.0 provider service to get a JWT access token here and
            // put it into the request header. Optionally, you can put a traceabilityId
            // into the header.

        }
        request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
        connection.sendRequest(request, client.createClientCallback(reference, latch, "post"));
        latch.await(100, TimeUnit.MILLISECONDS);
    } finally {
        IoUtils.safeClose(connection);
    }
    System.out.println("testHttp2Post: statusCode = " + reference.get().getResponseCode() + " body = " + reference.get().getAttachment(Http2Client.RESPONSE_BODY));
}
 
开发者ID:networknt,项目名称:light-example-4j,代码行数:27,代码来源:Http2ClientExample.java

示例3: testMultipleHttp2Get

import io.undertow.client.ClientResponse; //导入依赖的package包/类
public void testMultipleHttp2Get(int round) throws Exception {
    final Http2Client client = Http2Client.getInstance();
    final List<AtomicReference<ClientResponse>> references = new CopyOnWriteArrayList<>();
    final CountDownLatch latch = new CountDownLatch(round);
    final ClientConnection connection = client.connect(new URI("https://localhost:8443"), Http2Client.WORKER, Http2Client.SSL, Http2Client.POOL, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
    try {
        connection.getIoThread().execute(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < round; i++) {
                    AtomicReference<ClientResponse> reference = new AtomicReference<>();
                    references.add(i, reference);
                    final ClientRequest request = new ClientRequest().setMethod(Methods.GET).setPath("/get");
                    request.getRequestHeaders().put(Headers.HOST, "localhost");
                    connection.sendRequest(request, client.createClientCallback(reference, latch));
                }
            }
        });
        latch.await(10, TimeUnit.SECONDS);
        /*
        for (final AtomicReference<ClientResponse> reference : references) {
            System.out.println(reference.get().getAttachment(Http2Client.RESPONSE_BODY));
            System.out.println(reference.get().getProtocol().toString());
        }
        */
    } finally {
        IoUtils.safeClose(connection);
    }
}
 
开发者ID:networknt,项目名称:http2client-benchmark,代码行数:30,代码来源:Http2ClientExample.java

示例4: testMultipleHttp2Post

import io.undertow.client.ClientResponse; //导入依赖的package包/类
public void testMultipleHttp2Post(int round) throws Exception {
    final Http2Client client = Http2Client.getInstance();
    final List<AtomicReference<ClientResponse>> references = new CopyOnWriteArrayList<>();
    final CountDownLatch latch = new CountDownLatch(round);
    final ClientConnection connection = client.connect(new URI("https://localhost:8443"), Http2Client.WORKER, Http2Client.SSL, Http2Client.POOL, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
    try {
        connection.getIoThread().execute(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < round; i++) {
                    AtomicReference<ClientResponse> reference = new AtomicReference<>();
                    references.add(i, reference);
                    final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/post");
                    request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
                    request.getRequestHeaders().put(Headers.HOST, "localhost");
                    connection.sendRequest(request, client.createClientCallback(reference, latch, "post"));
                }
            }
        });
        latch.await(10, TimeUnit.SECONDS);
        /*
        for (final AtomicReference<ClientResponse> reference : references) {
            System.out.println(reference.get().getAttachment(Http2Client.RESPONSE_BODY));
            System.out.println(reference.get().getProtocol().toString());
        }
        */
    } finally {
        IoUtils.safeClose(connection);
    }
}
 
开发者ID:networknt,项目名称:http2client-benchmark,代码行数:31,代码来源:Http2ClientExample.java

示例5: handleEvent

import io.undertow.client.ClientResponse; //导入依赖的package包/类
public void handleEvent(AjpClientChannel channel) {
    try {
        AbstractAjpClientStreamSourceChannel result = channel.receive();
        if(result == null) {
            return;
        }

        if(result instanceof AjpClientResponseStreamSourceChannel) {
            AjpClientResponseStreamSourceChannel response = (AjpClientResponseStreamSourceChannel) result;
            response.setFinishListener(responseFinishedListener);
            ClientResponse cr = new ClientResponse(response.getStatusCode(), response.getReasonPhrase(), currentRequest.getRequest().getProtocol(), response.getHeaders());
            if (response.getStatusCode() == 100) {
                currentRequest.setContinueResponse(cr);
            } else {
                currentRequest.setResponseChannel(response);
                currentRequest.setResponse(cr);
            }
        } else {
            //TODO: ping, pong ETC
            Channels.drain(result, Long.MAX_VALUE);
        }

    } catch (Exception e) {
        UndertowLogger.CLIENT_LOGGER.exceptionProcessingRequest(e);
        safeClose(connection);
        currentRequest.setFailed(e instanceof IOException ? (IOException) e : new IOException(e));
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:AjpClientConnection.java

示例6: responseReady

import io.undertow.client.ClientResponse; //导入依赖的package包/类
void responseReady(SpdySynReplyStreamSourceChannel result) {
    this.response = result;
    HeaderMap headers = result.getHeaders();
    final String status = result.getHeaders().getFirst(SpdyClientConnection.STATUS);
    int statusCode = 500;
    if (status != null && status.length() > 3) {
        statusCode = Integer.parseInt(status.substring(0, 3));
    }
    headers.remove(SpdyClientConnection.VERSION);
    headers.remove(SpdyClientConnection.STATUS);
    clientResponse = new ClientResponse(statusCode, status != null ? status.substring(3) : "", clientRequest.getProtocol(), headers);
    if (responseListener != null) {
        responseListener.completed(this);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:SpdyClientExchange.java

示例7: testHttp2Get

import io.undertow.client.ClientResponse; //导入依赖的package包/类
/**
 * This is a simple example that create a new HTTP 2.0 connection for get request
 * and close the connection after the call is done. As you can see that it is using
 * a hard coded uri which points to an statically deployed service on fixed ip and port
 *
 * @throws Exception
 */
public void testHttp2Get() throws Exception {
    // Create one CountDownLatch that will be reset in the callback function
    final CountDownLatch latch = new CountDownLatch(1);
    // Create an HTTP 2.0 connection to the server
    final ClientConnection connection = client.connect(new URI("https://localhost:8443"), Http2Client.WORKER, Http2Client.SSL, Http2Client.POOL, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
    // Create an AtomicReference object to receive ClientResponse from callback function
    final AtomicReference<ClientResponse> reference = new AtomicReference<>();
    try {
        final ClientRequest request = new ClientRequest().setMethod(Methods.GET).setPath("/get");
        // this is to ask client module to pass through correlationId and traceabilityId as well as
        // getting access token from oauth2 server automatically and attatch authorization headers.
        if(securityEnabled) {
            // call OAuth 2.0 provider service to get a JWT access token here and
            // put it into the request header. Optionally, you can put a traceabilityId
            // into the header.
            TokenResponse tokenResponse = getAccessToken();
            // you should check if the token is expired here
            expiration = tokenResponse.getExpiresIn();
            String token = tokenResponse.getAccessToken();
            // traceabilityId should be a uuid or db sequence
            client.addAuthTokenTrace(request, token, "traceabilityId");

        }
        // send request to server with a callback function provided by Http2Client
        connection.sendRequest(request, client.createClientCallback(reference, latch));
        // wait for 100 millisecond to timeout the request.
        latch.await(100, TimeUnit.MILLISECONDS);
    } finally {
        // here the connection is closed after one request. It should be used for in frequent
        // request as creating a new connection is costly with TLS handshake and ALPN.
        IoUtils.safeClose(connection);
    }
    int statusCode = reference.get().getResponseCode();
    String body = reference.get().getAttachment(Http2Client.RESPONSE_BODY);
    System.out.println("testHttp2Get: statusCode = " + statusCode + " body = " + body);
}
 
开发者ID:networknt,项目名称:light-example-4j,代码行数:44,代码来源:Http2ClientExample.java

示例8: testHttp2GetReuse

import io.undertow.client.ClientResponse; //导入依赖的package包/类
/**
 * This is a simple example that create a new HTTP 2.0 connection for get request
 * and close the connection after the call is done. As you can see that it is using
 * a hard coded uri which points to an statically deployed service on fixed ip and port
 *
 * @throws Exception
 */
public void testHttp2GetReuse() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<ClientResponse> reference = new AtomicReference<>();
    final ClientRequest request = new ClientRequest().setMethod(Methods.GET).setPath("/get");
    if(securityEnabled) {
    }
    // send request to server with a callback function provided by Http2Client
    reusedConnection.sendRequest(request, client.createClientCallback(reference, latch));
    // wait for 100 millisecond to timeout the request.
    latch.await(100, TimeUnit.MILLISECONDS);
    System.out.println("testHttp2GetReuse: statusCode = " + reference.get().getResponseCode() + " body = " + reference.get().getAttachment(Http2Client.RESPONSE_BODY));
}
 
开发者ID:networknt,项目名称:light-example-4j,代码行数:20,代码来源:Http2ClientExample.java

示例9: testHttp2PostResue

import io.undertow.client.ClientResponse; //导入依赖的package包/类
/**
 * This is an example for post request. Please note that you need to set header TRANSFER_ENCODING
 * and pass the request body into the callback function.
 *
 * @throws Exception
 */
public void testHttp2PostResue() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<ClientResponse> reference = new AtomicReference<>();
    final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/post");
    if(securityEnabled) {
    }
    request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
    reusedConnection.sendRequest(request, client.createClientCallback(reference, latch, "post"));
    latch.await(100, TimeUnit.MILLISECONDS);
    System.out.println("testHttp2PostReuse: statusCode = " + reference.get().getResponseCode() + " body = " + reference.get().getAttachment(Http2Client.RESPONSE_BODY));
}
 
开发者ID:networknt,项目名称:light-example-4j,代码行数:18,代码来源:Http2ClientExample.java

示例10: getAccessToken

import io.undertow.client.ClientResponse; //导入依赖的package包/类
/**
 * In this example, I am going to use a customized grant type to get access token. This grant type assumes
 * that the client authenticated the user and send the user info to OAuth 2.0 provider to get an access token.
 * Note that the client must be a strusted client.
 * @return
 */
private TokenResponse getAccessToken() throws Exception {
    TokenResponse tokenResponse = null;
    Map<String, String> params = new HashMap<>();
    params.put("grant_type", "client_authenticated_user");
    params.put("userId", "admin");
    params.put("userType", "Employee");
    params.put("transit", "12345"); // This is the custom claim that need to be shown in JWT token.
    String s = Http2Client.getFormDataString(params);
    final AtomicReference<ClientResponse> reference = new AtomicReference<>();
    final CountDownLatch latch = new CountDownLatch(1);
    final ClientConnection connection;
    try {
        // all the connection information should be from client.yml
        connection = client.connect(new URI("https://localhost:6882"), Http2Client.WORKER, Http2Client.SSL, Http2Client.POOL, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
        final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/oauth2/token");
        request.getRequestHeaders().put(Headers.HOST, "localhost");
        request.getRequestHeaders().put(Headers.AUTHORIZATION, "Basic " + encodeCredentials("f7d42348-c647-4efb-a52d-4c5787421e72", "f6h1FTI8Q3-7UScPZDzfXA"));
        request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/x-www-form-urlencoded");
        request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
        connection.sendRequest(request, client.createClientCallback(reference, latch, s));
        latch.await(1, TimeUnit.SECONDS);
        String body = reference.get().getAttachment(Http2Client.RESPONSE_BODY);
        tokenResponse = Config.getInstance().getMapper().readValue(body, TokenResponse.class);
    } catch (Exception e) {
        throw new ClientException(e);
    }

    return tokenResponse;
}
 
开发者ID:networknt,项目名称:light-example-4j,代码行数:36,代码来源:Http2ClientExample.java

示例11: verifyHandshake

import io.undertow.client.ClientResponse; //导入依赖的package包/类
private static void verifyHandshake(ClientResponse response, String secretKey) throws IOException {
    HeaderMap headers = response.getResponseHeaders();
    String acceptValue = headers.getFirst(HandshakeUtil.SEC_HORNETQ_REMOTING_ACCEPT);
    if (acceptValue == null) {
        throw new IOException(HandshakeUtil.SEC_HORNETQ_REMOTING_ACCEPT + " header not found");
    }
    String expectedResponse = HandshakeUtil.createExpectedResponse(secretKey);
    if(!acceptValue.equals(expectedResponse)) {
        throw new IOException(HandshakeUtil.SEC_HORNETQ_REMOTING_ACCEPT + " value of " + acceptValue + " did not match expected " + expectedResponse);
    }
}
 
开发者ID:jmesnil,项目名称:hornetq-undertow-client,代码行数:12,代码来源:Client.java

示例12: setContinueResponse

import io.undertow.client.ClientResponse; //导入依赖的package包/类
void setContinueResponse(ClientResponse response) {
    this.continueResponse = response;
    if (continueNotification != null) {
        this.continueNotification.handleContinue(this);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:7,代码来源:AjpClientExchange.java

示例13: setResponse

import io.undertow.client.ClientResponse; //导入依赖的package包/类
void setResponse(ClientResponse response) {
    this.response = response;
    if (responseCallback != null) {
        this.responseCallback.completed(this);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:7,代码来源:AjpClientExchange.java

示例14: getResponse

import io.undertow.client.ClientResponse; //导入依赖的package包/类
@Override
public ClientResponse getResponse() {
    return response;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:AjpClientExchange.java

示例15: getContinueResponse

import io.undertow.client.ClientResponse; //导入依赖的package包/类
@Override
public ClientResponse getContinueResponse() {
    return continueResponse;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:AjpClientExchange.java


注:本文中的io.undertow.client.ClientResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。