Search in sources :

Example 6 with ConduitStreamSinkChannel

use of org.xnio.conduits.ConduitStreamSinkChannel in project indy by Commonjava.

the class ProxyAcceptHandler method handleEvent.

@Override
public void handleEvent(AcceptingChannel<StreamConnection> channel) {
    final Logger logger = LoggerFactory.getLogger(getClass());
    StreamConnection accepted;
    try {
        accepted = channel.accept();
    } catch (IOException e) {
        logger.error("Failed to addMetadata httprox connection: " + e.getMessage(), e);
        return;
    }
    if (accepted == null) {
        return;
    }
    logger.debug("accepted {}", accepted.getPeerAddress());
    final ConduitStreamSourceChannel source = accepted.getSourceChannel();
    final ConduitStreamSinkChannel sink = accepted.getSinkChannel();
    final ProxyRepositoryCreator creator = createRepoCreator();
    final ProxyResponseWriter writer = new ProxyResponseWriter(config, storeManager, contentController, proxyAuthenticator, cacheProvider, creator);
    logger.debug("Setting writer: {}", writer);
    sink.getWriteSetter().set(writer);
    final ProxyRequestReader reader = new ProxyRequestReader(writer, sink);
    logger.debug("Setting reader: {}", reader);
    source.getReadSetter().set(reader);
    source.resumeReads();
}
Also used : IOException(java.io.IOException) Logger(org.slf4j.Logger) StreamConnection(org.xnio.StreamConnection) ConduitStreamSourceChannel(org.xnio.conduits.ConduitStreamSourceChannel) ConduitStreamSinkChannel(org.xnio.conduits.ConduitStreamSinkChannel)

Example 7 with ConduitStreamSinkChannel

use of org.xnio.conduits.ConduitStreamSinkChannel in project undertow by undertow-io.

the class HttpServerExchange method getResponseChannel.

/**
     * Get the response channel. The channel must be closed and fully flushed before the next response can be started.
     * In order to close the channel you must first call {@link org.xnio.channels.StreamSinkChannel#shutdownWrites()},
     * and then call {@link org.xnio.channels.StreamSinkChannel#flush()} until it returns true. Alternatively you can
     * call {@link #endExchange()}, which will close the channel as part of its cleanup.
     * <p>
     * Closing a fixed-length response before the corresponding number of bytes has been written will cause the connection
     * to be reset and subsequent requests to fail; thus it is important to ensure that the proper content length is
     * delivered when one is specified.  The response channel may not be writable until after the response headers have
     * been sent.
     * <p>
     * If this method is not called then an empty or default response body will be used, depending on the response code set.
     * <p>
     * The returned channel will begin to write out headers when the first write request is initiated, or when
     * {@link org.xnio.channels.StreamSinkChannel#shutdownWrites()} is called on the channel with no content being written.
     * Once the channel is acquired, however, the response code and headers may not be modified.
     * <p>
     *
     * @return the response channel, or {@code null} if another party already acquired the channel
     */
public StreamSinkChannel getResponseChannel() {
    if (responseChannel != null) {
        return null;
    }
    final ConduitWrapper<StreamSinkConduit>[] wrappers = responseWrappers;
    this.responseWrappers = null;
    final ConduitStreamSinkChannel sinkChannel = connection.getSinkChannel();
    if (sinkChannel == null) {
        return null;
    }
    if (wrappers != null) {
        final WrapperStreamSinkConduitFactory factory = new WrapperStreamSinkConduitFactory(wrappers, responseWrapperCount, this, sinkChannel.getConduit());
        sinkChannel.setConduit(factory.create());
    } else {
        sinkChannel.setConduit(connection.getSinkConduit(this, sinkChannel.getConduit()));
    }
    this.responseChannel = new WriteDispatchChannel(sinkChannel);
    this.startResponse();
    return responseChannel;
}
Also used : ConduitStreamSinkChannel(org.xnio.conduits.ConduitStreamSinkChannel)

Aggregations

ConduitStreamSinkChannel (org.xnio.conduits.ConduitStreamSinkChannel)7 IOException (java.io.IOException)5 StreamConnection (org.xnio.StreamConnection)3 BytesSentStreamSinkConduit (io.undertow.conduits.BytesSentStreamSinkConduit)2 ByteBuffer (java.nio.ByteBuffer)2 ConduitStreamSourceChannel (org.xnio.conduits.ConduitStreamSourceChannel)2 StreamSinkConduit (org.xnio.conduits.StreamSinkConduit)2 ClientRequest (io.undertow.client.ClientRequest)1 ByteActivityCallback (io.undertow.conduits.ByteActivityCallback)1 BytesReceivedStreamSourceConduit (io.undertow.conduits.BytesReceivedStreamSourceConduit)1 ChunkedStreamSinkConduit (io.undertow.conduits.ChunkedStreamSinkConduit)1 ReadDataStreamSourceConduit (io.undertow.conduits.ReadDataStreamSourceConduit)1 PooledByteBuffer (io.undertow.connector.PooledByteBuffer)1 Http2Channel (io.undertow.protocols.http2.Http2Channel)1 Resource (io.undertow.server.handlers.resource.Resource)1 HttpString (io.undertow.util.HttpString)1 OutputStream (java.io.OutputStream)1 FileChannel (java.nio.channels.FileChannel)1 Path (java.nio.file.Path)1 Executor (java.util.concurrent.Executor)1