Search in sources :

Example 1 with ReadTimeoutStreamSourceConduit

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());
}
Also used : IdleTimeoutConduit(io.undertow.conduits.IdleTimeoutConduit) WriteTimeoutStreamSinkConduit(io.undertow.conduits.WriteTimeoutStreamSinkConduit) ServerConnection(io.undertow.server.ServerConnection) ReadTimeoutStreamSourceConduit(io.undertow.conduits.ReadTimeoutStreamSourceConduit) IOException(java.io.IOException) BytesSentStreamSinkConduit(io.undertow.conduits.BytesSentStreamSinkConduit) BytesReceivedStreamSourceConduit(io.undertow.conduits.BytesReceivedStreamSourceConduit)

Example 2 with ReadTimeoutStreamSourceConduit

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());
}
Also used : WriteTimeoutStreamSinkConduit(io.undertow.conduits.WriteTimeoutStreamSinkConduit) ServerConnection(io.undertow.server.ServerConnection) ReadTimeoutStreamSourceConduit(io.undertow.conduits.ReadTimeoutStreamSourceConduit) IOException(java.io.IOException) BytesReceivedStreamSourceConduit(io.undertow.conduits.BytesReceivedStreamSourceConduit) IdleTimeoutConduit(io.undertow.conduits.IdleTimeoutConduit) BytesSentStreamSinkConduit(io.undertow.conduits.BytesSentStreamSinkConduit)

Example 3 with ReadTimeoutStreamSourceConduit

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);
    }
}
Also used : SslConnection(org.xnio.ssl.SslConnection) WriteTimeoutStreamSinkConduit(io.undertow.conduits.WriteTimeoutStreamSinkConduit) ReadTimeoutStreamSourceConduit(io.undertow.conduits.ReadTimeoutStreamSourceConduit) HttpOpenListener(io.undertow.server.protocol.http.HttpOpenListener) IOException(java.io.IOException) HttpString(io.undertow.util.HttpString)

Aggregations

ReadTimeoutStreamSourceConduit (io.undertow.conduits.ReadTimeoutStreamSourceConduit)3 WriteTimeoutStreamSinkConduit (io.undertow.conduits.WriteTimeoutStreamSinkConduit)3 IOException (java.io.IOException)3 BytesReceivedStreamSourceConduit (io.undertow.conduits.BytesReceivedStreamSourceConduit)2 BytesSentStreamSinkConduit (io.undertow.conduits.BytesSentStreamSinkConduit)2 IdleTimeoutConduit (io.undertow.conduits.IdleTimeoutConduit)2 ServerConnection (io.undertow.server.ServerConnection)2 HttpOpenListener (io.undertow.server.protocol.http.HttpOpenListener)1 HttpString (io.undertow.util.HttpString)1 SslConnection (org.xnio.ssl.SslConnection)1