use of org.apache.hc.core5.http.nio.command.RequestExecutionCommand in project httpcomponents-core by apache.
the class ClientSessionEndpoint method execute.
public void execute(final AsyncClientExchangeHandler exchangeHandler, final HandlerFactory<AsyncPushConsumer> pushHandlerFactory, final HttpContext context) {
Asserts.check(!closed.get(), "Connection is already closed");
final Command executionCommand = new RequestExecutionCommand(exchangeHandler, pushHandlerFactory, null, context);
ioSession.enqueue(executionCommand, Command.Priority.NORMAL);
if (!ioSession.isOpen()) {
exchangeHandler.failed(new ConnectionClosedException());
}
}
use of org.apache.hc.core5.http.nio.command.RequestExecutionCommand in project httpcomponents-core by apache.
the class ClientH2StreamMultiplexer method createLocallyInitiatedStream.
@Override
H2StreamHandler createLocallyInitiatedStream(final ExecutableCommand command, final H2StreamChannel channel, final HttpProcessor httpProcessor, final BasicHttpConnectionMetrics connMetrics) throws IOException {
if (command instanceof RequestExecutionCommand) {
final RequestExecutionCommand executionCommand = (RequestExecutionCommand) command;
final AsyncClientExchangeHandler exchangeHandler = executionCommand.getExchangeHandler();
final HandlerFactory<AsyncPushConsumer> pushHandlerFactory = executionCommand.getPushHandlerFactory();
final HttpCoreContext context = HttpCoreContext.adapt(executionCommand.getContext());
context.setAttribute(HttpCoreContext.SSL_SESSION, getSSLSession());
context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, getEndpointDetails());
return new ClientH2StreamHandler(channel, httpProcessor, connMetrics, exchangeHandler, pushHandlerFactory != null ? pushHandlerFactory : this.pushHandlerFactory, context);
}
throw new H2ConnectionException(H2Error.INTERNAL_ERROR, "Unexpected executable command");
}
use of org.apache.hc.core5.http.nio.command.RequestExecutionCommand in project httpcomponents-core by apache.
the class H2MultiplexingRequester method execute.
private void execute(final AsyncClientExchangeHandler exchangeHandler, final HandlerFactory<AsyncPushConsumer> pushHandlerFactory, final CancellableDependency cancellableDependency, final Timeout timeout, final HttpContext context) {
Args.notNull(exchangeHandler, "Exchange handler");
Args.notNull(timeout, "Timeout");
Args.notNull(context, "Context");
try {
exchangeHandler.produceRequest((request, entityDetails, httpContext) -> {
final String scheme = request.getScheme();
final URIAuthority authority = request.getAuthority();
if (authority == null) {
throw new ProtocolException("Request authority not specified");
}
final HttpHost target = new HttpHost(scheme, authority);
connPool.getSession(target, timeout, new FutureCallback<IOSession>() {
@Override
public void completed(final IOSession ioSession) {
ioSession.enqueue(new RequestExecutionCommand(new AsyncClientExchangeHandler() {
@Override
public void releaseResources() {
exchangeHandler.releaseResources();
}
@Override
public void produceRequest(final RequestChannel channel, final HttpContext httpContext) throws HttpException, IOException {
channel.sendRequest(request, entityDetails, httpContext);
}
@Override
public int available() {
return exchangeHandler.available();
}
@Override
public void produce(final DataStreamChannel channel) throws IOException {
exchangeHandler.produce(channel);
}
@Override
public void consumeInformation(final HttpResponse response, final HttpContext httpContext) throws HttpException, IOException {
exchangeHandler.consumeInformation(response, httpContext);
}
@Override
public void consumeResponse(final HttpResponse response, final EntityDetails entityDetails, final HttpContext httpContext) throws HttpException, IOException {
exchangeHandler.consumeResponse(response, entityDetails, httpContext);
}
@Override
public void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
exchangeHandler.updateCapacity(capacityChannel);
}
@Override
public void consume(final ByteBuffer src) throws IOException {
exchangeHandler.consume(src);
}
@Override
public void streamEnd(final List<? extends Header> trailers) throws HttpException, IOException {
exchangeHandler.streamEnd(trailers);
}
@Override
public void cancel() {
exchangeHandler.cancel();
}
@Override
public void failed(final Exception cause) {
exchangeHandler.failed(cause);
}
}, pushHandlerFactory, cancellableDependency, context), Command.Priority.NORMAL);
if (!ioSession.isOpen()) {
exchangeHandler.failed(new ConnectionClosedException());
}
}
@Override
public void failed(final Exception ex) {
exchangeHandler.failed(ex);
}
@Override
public void cancelled() {
exchangeHandler.cancel();
}
});
}, context);
} catch (final IOException | HttpException ex) {
exchangeHandler.failed(ex);
}
}
use of org.apache.hc.core5.http.nio.command.RequestExecutionCommand in project httpcomponents-core by apache.
the class ClientHttp1StreamDuplexer method execute.
@Override
void execute(final RequestExecutionCommand executionCommand) throws HttpException, IOException {
final AsyncClientExchangeHandler exchangeHandler = executionCommand.getExchangeHandler();
final HttpCoreContext context = HttpCoreContext.adapt(executionCommand.getContext());
context.setAttribute(HttpCoreContext.SSL_SESSION, getSSLSession());
context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, getEndpointDetails());
final ClientHttp1StreamHandler handler = new ClientHttp1StreamHandler(outputChannel, httpProcessor, http1Config, connectionReuseStrategy, exchangeHandler, context);
pipeline.add(handler);
outgoing = handler;
if (handler.isOutputReady()) {
handler.produceOutput();
}
}
use of org.apache.hc.core5.http.nio.command.RequestExecutionCommand in project httpcomponents-core by apache.
the class AbstractHttp1StreamDuplexer method processCommands.
private void processCommands() throws HttpException, IOException {
for (; ; ) {
final Command command = ioSession.poll();
if (command == null) {
return;
}
if (command instanceof ShutdownCommand) {
final ShutdownCommand shutdownCommand = (ShutdownCommand) command;
requestShutdown(shutdownCommand.getType());
} else if (command instanceof RequestExecutionCommand) {
if (connState.compareTo(ConnectionState.GRACEFUL_SHUTDOWN) >= 0) {
command.cancel();
} else {
execute((RequestExecutionCommand) command);
return;
}
} else {
throw new HttpException("Unexpected command: " + command.getClass());
}
}
}
Aggregations