use of io.undertow.conduits.ReadTimeoutStreamSourceConduit in project undertow by undertow-io.
the class AjpOpenListener method handleEvent.
@Override
public void handleEvent(final StreamConnection channel) {
if (UndertowLogger.REQUEST_LOGGER.isTraceEnabled()) {
UndertowLogger.REQUEST_LOGGER.tracef("Opened connection with %s", channel.getPeerAddress());
}
// set read and write timeouts
try {
Integer readTimeout = channel.getOption(Options.READ_TIMEOUT);
Integer idle = undertowOptions.get(UndertowOptions.IDLE_TIMEOUT);
if (idle != null) {
IdleTimeoutConduit conduit = new IdleTimeoutConduit(channel);
channel.getSourceChannel().setConduit(conduit);
channel.getSinkChannel().setConduit(conduit);
}
if (readTimeout != null && readTimeout > 0) {
channel.getSourceChannel().setConduit(new ReadTimeoutStreamSourceConduit(channel.getSourceChannel().getConduit(), channel, this));
}
Integer writeTimeout = channel.getOption(Options.WRITE_TIMEOUT);
if (writeTimeout != null && writeTimeout > 0) {
channel.getSinkChannel().setConduit(new WriteTimeoutStreamSinkConduit(channel.getSinkChannel().getConduit(), channel, this));
}
} catch (IOException e) {
IoUtils.safeClose(channel);
UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
}
if (statisticsEnabled) {
channel.getSinkChannel().setConduit(new BytesSentStreamSinkConduit(channel.getSinkChannel().getConduit(), connectorStatistics.sentAccumulator()));
channel.getSourceChannel().setConduit(new BytesReceivedStreamSourceConduit(channel.getSourceChannel().getConduit(), connectorStatistics.receivedAccumulator()));
connectorStatistics.incrementConnectionCount();
}
AjpServerConnection connection = new AjpServerConnection(channel, bufferPool, rootHandler, undertowOptions, bufferSize);
AjpReadListener readListener = new AjpReadListener(connection, scheme, parser, statisticsEnabled ? connectorStatistics : null);
if (statisticsEnabled) {
connection.addCloseListener(closeListener);
}
connection.setAjpReadListener(readListener);
connections.add(connection);
connection.addCloseListener(new ServerConnection.CloseListener() {
@Override
public void closed(ServerConnection c) {
connections.remove(connection);
}
});
readListener.startRequest();
channel.getSourceChannel().setReadListener(readListener);
readListener.handleEvent(channel.getSourceChannel());
}
use of io.undertow.conduits.ReadTimeoutStreamSourceConduit in project undertow by undertow-io.
the class HttpOpenListener method handleEvent.
@Override
public void handleEvent(final StreamConnection channel, PooledByteBuffer buffer) {
if (UndertowLogger.REQUEST_LOGGER.isTraceEnabled()) {
UndertowLogger.REQUEST_LOGGER.tracef("Opened connection with %s", channel.getPeerAddress());
}
// set read and write timeouts
try {
Integer readTimeout = channel.getOption(Options.READ_TIMEOUT);
Integer idle = undertowOptions.get(UndertowOptions.IDLE_TIMEOUT);
if (idle != null) {
IdleTimeoutConduit conduit = new IdleTimeoutConduit(channel);
channel.getSourceChannel().setConduit(conduit);
channel.getSinkChannel().setConduit(conduit);
}
if (readTimeout != null && readTimeout > 0) {
channel.getSourceChannel().setConduit(new ReadTimeoutStreamSourceConduit(channel.getSourceChannel().getConduit(), channel, this));
}
Integer writeTimeout = channel.getOption(Options.WRITE_TIMEOUT);
if (writeTimeout != null && writeTimeout > 0) {
channel.getSinkChannel().setConduit(new WriteTimeoutStreamSinkConduit(channel.getSinkChannel().getConduit(), channel, this));
}
} catch (IOException e) {
IoUtils.safeClose(channel);
UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
} catch (Throwable t) {
IoUtils.safeClose(channel);
UndertowLogger.REQUEST_IO_LOGGER.handleUnexpectedFailure(t);
}
if (statisticsEnabled) {
channel.getSinkChannel().setConduit(new BytesSentStreamSinkConduit(channel.getSinkChannel().getConduit(), connectorStatistics.sentAccumulator()));
channel.getSourceChannel().setConduit(new BytesReceivedStreamSourceConduit(channel.getSourceChannel().getConduit(), connectorStatistics.receivedAccumulator()));
}
HttpServerConnection connection = new HttpServerConnection(channel, bufferPool, rootHandler, undertowOptions, bufferSize, statisticsEnabled ? connectorStatistics : null);
HttpReadListener readListener = new HttpReadListener(connection, parser, statisticsEnabled ? connectorStatistics : null);
if (buffer != null) {
if (buffer.getBuffer().hasRemaining()) {
connection.setExtraBytes(buffer);
} else {
buffer.close();
}
}
if (connectorStatistics != null && statisticsEnabled) {
connectorStatistics.incrementConnectionCount();
}
connections.add(connection);
connection.addCloseListener(new ServerConnection.CloseListener() {
@Override
public void closed(ServerConnection c) {
connections.remove(connection);
}
});
connection.setReadListener(readListener);
readListener.newRequest();
channel.getSourceChannel().setReadListener(readListener);
readListener.handleEvent(channel.getSourceChannel());
}
use of io.undertow.conduits.ReadTimeoutStreamSourceConduit in project undertow by undertow-io.
the class HttpClientConnection method sendRequest.
@Override
public void sendRequest(final ClientRequest request, final ClientCallback<ClientExchange> clientCallback) {
try {
Integer readTimeout = connection.getOption(Options.READ_TIMEOUT);
if (readTimeout != null && readTimeout > 0) {
connection.getSourceChannel().setConduit(new ReadTimeoutStreamSourceConduit(connection.getSourceChannel().getConduit(), connection, new HttpOpenListener(bufferPool)));
}
Integer writeTimeout = connection.getOption(Options.WRITE_TIMEOUT);
if (writeTimeout != null && writeTimeout > 0) {
connection.getSinkChannel().setConduit(new WriteTimeoutStreamSinkConduit(connection.getSinkChannel().getConduit(), connection, new HttpOpenListener(bufferPool)));
}
} catch (IOException e) {
IoUtils.safeClose(connection);
UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
}
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);
}
}
Aggregations