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();
}
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;
}
Aggregations