io.undertow.client.ClientExchange Java Examples
The following examples show how to use
io.undertow.client.ClientExchange.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpClientConnection.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void sendRequest(final ClientRequest request, final ClientCallback<ClientExchange> clientCallback) { if(http2Delegate != null) { http2Delegate.sendRequest(request, clientCallback); return; } if (anyAreSet(state, UPGRADE_REQUESTED | UPGRADED | CLOSE_REQ | CLOSED)) { clientCallback.failed(UndertowClientMessages.MESSAGES.invalidConnectionState()); return; } final HttpClientExchange httpClientExchange = new HttpClientExchange(clientCallback, request, this); boolean ssl = this.connection instanceof SslConnection; if(!ssl && !http2Tried && options.get(UndertowOptions.ENABLE_HTTP2, false) && !request.getRequestHeaders().contains(Headers.UPGRADE)) { //this is the first request, as we want to try a HTTP2 upgrade request.getRequestHeaders().put(new HttpString("HTTP2-Settings"), Http2ClearClientProvider.createSettingsFrame(options, bufferPool)); request.getRequestHeaders().put(Headers.UPGRADE, Http2Channel.CLEARTEXT_UPGRADE_STRING); request.getRequestHeaders().put(Headers.CONNECTION, "Upgrade, HTTP2-Settings"); http2Tried = true; } if (currentRequest == null) { initiateRequest(httpClientExchange); } else { pendingQueue.add(httpClientExchange); } }
Example #2
Source File: HttpClientConnection.java From lams with GNU General Public License v2.0 | 6 votes |
private void prepareResponseChannel(ClientResponse response, ClientExchange exchange) { String encoding = response.getResponseHeaders().getLast(Headers.TRANSFER_ENCODING); boolean chunked = encoding != null && Headers.CHUNKED.equals(new HttpString(encoding)); String length = response.getResponseHeaders().getFirst(Headers.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, connection)); } else if (length != null) { try { long contentLength = Long.parseLong(length); connection.getSourceChannel().setConduit(new FixedLengthStreamSourceConduit(connection.getSourceChannel().getConduit(), contentLength, responseFinishedListener)); } catch (NumberFormatException e) { handleError(e); throw e; } } else if (response.getProtocol().equals(Protocols.HTTP_1_1) && !Connectors.isEntityBodyAllowed(response.getResponseCode())) { connection.getSourceChannel().setConduit(new FixedLengthStreamSourceConduit(connection.getSourceChannel().getConduit(), 0, responseFinishedListener)); } else { connection.getSourceChannel().setConduit(new FinishableStreamSourceConduit(connection.getSourceChannel().getConduit(), responseFinishedListener)); state |= CLOSE_REQ; } }
Example #3
Source File: AjpClientConnection.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void sendRequest(final ClientRequest request, final ClientCallback<ClientExchange> clientCallback) { if (anyAreSet(state, UPGRADE_REQUESTED | UPGRADED | CLOSE_REQ | CLOSED)) { clientCallback.failed(UndertowClientMessages.MESSAGES.invalidConnectionState()); return; } final AjpClientExchange AjpClientExchange = new AjpClientExchange(clientCallback, request, this); if (currentRequest == null) { initiateRequest(AjpClientExchange); } else { pendingQueue.add(AjpClientExchange); } }
Example #4
Source File: AjpClientExchange.java From lams with GNU General Public License v2.0 | 5 votes |
AjpClientExchange(ClientCallback<ClientExchange> readyCallback, ClientRequest request, AjpClientConnection clientConnection) { this.readyCallback = readyCallback; this.request = request; this.clientConnection = clientConnection; boolean reqContinue = false; if (request.getRequestHeaders().contains(Headers.EXPECT)) { for (String header : request.getRequestHeaders().get(Headers.EXPECT)) { if (header.equals("100-continue")) { reqContinue = true; } } } this.requiresContinue = reqContinue; }
Example #5
Source File: AjpClientExchange.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void setResponseListener(ClientCallback<ClientExchange> listener) { this.responseCallback = listener; if (listener != null) { if (failedReason != null) { listener.failed(failedReason); } else if (response != null) { listener.completed(this); } } }
Example #6
Source File: Http2ClientExchange.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void setResponseListener(ClientCallback<ClientExchange> responseListener) { this.responseListener = responseListener; if(failedReason != null) { responseListener.failed(failedReason); } }
Example #7
Source File: Http2ClientConnection.java From lams with GNU General Public License v2.0 | 5 votes |
public Http2ClientConnection(Http2Channel http2Channel, ClientCallback<ClientExchange> upgradeReadyCallback, ClientRequest clientRequest, String defaultHost, ClientStatistics clientStatistics, boolean secure) { this.http2Channel = http2Channel; this.defaultHost = defaultHost; this.clientStatistics = clientStatistics; this.secure = secure; http2Channel.getReceiveSetter().set(new Http2ReceiveListener()); http2Channel.resumeReceives(); http2Channel.addCloseTask(closeTask); this.initialUpgradeRequest = false; Http2ClientExchange exchange = new Http2ClientExchange(this, null, clientRequest); exchange.setResponseListener(upgradeReadyCallback); currentExchanges.put(1, exchange); }
Example #8
Source File: HttpClientExchange.java From lams with GNU General Public License v2.0 | 5 votes |
HttpClientExchange(ClientCallback<ClientExchange> readyCallback, ClientRequest request, HttpClientConnection clientConnection) { this.readyCallback = readyCallback; this.request = request; this.clientConnection = clientConnection; boolean reqContinue = false; if (request.getRequestHeaders().contains(Headers.EXPECT)) { for (String header : request.getRequestHeaders().get(Headers.EXPECT)) { if (header.equals("100-continue")) { reqContinue = true; } } } this.requiresContinue = reqContinue; }
Example #9
Source File: HttpClientExchange.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void setResponseListener(ClientCallback<ClientExchange> listener) { this.responseCallback = listener; if (listener != null) { if (failedReason != null) { listener.failed(failedReason); } else if (response != null) { listener.completed(this); } } }
Example #10
Source File: TokenAuthenticator.java From hawkular-metrics with Apache License 2.0 | 5 votes |
private ResponseBodyListener(HttpServerExchange serverExchange, PooledConnection connection, ClientExchange clientExchange) { super(clientExchange.getConnection().getBufferPool()); this.serverExchange = serverExchange; this.connection = connection; this.clientExchange = clientExchange; }
Example #11
Source File: AjpClientExchange.java From lams with GNU General Public License v2.0 | 4 votes |
void invokeReadReadyCallback(final ClientExchange result) { if(readyCallback != null) { readyCallback.completed(result); readyCallback = null; } }
Example #12
Source File: HttpClientExchange.java From lams with GNU General Public License v2.0 | 4 votes |
ClientCallback<ClientExchange> getResponseCallback() { return responseCallback; }
Example #13
Source File: TokenAuthenticator.java From hawkular-metrics with Apache License 2.0 | 4 votes |
@Override public void completed(ClientExchange clientExchange) { clientExchange.setResponseListener(new ResponseListener(serverExchange, connection)); writeBody(clientExchange); }
Example #14
Source File: TokenAuthenticator.java From hawkular-metrics with Apache License 2.0 | 4 votes |
@Override public void completed(ClientExchange clientExchange) { StringReadChannelListener readChannelListener; readChannelListener = new ResponseBodyListener(serverExchange, connection, clientExchange); readChannelListener.setup(clientExchange.getResponseChannel()); }
Example #15
Source File: TokenAuthenticator.java From hawkular-metrics with Apache License 2.0 | 4 votes |
private void sendRequest(ClientRequest request, ClientCallback<ClientExchange> clientCallback) { clientConnection.sendRequest(request, clientCallback); }