use of org.xnio.conduits.StreamSourceConduit in project undertow by undertow-io.
the class HttpServerExchange method getRequestChannel.
/**
* Get the inbound request. If there is no request body, calling this method
* may cause the next request to immediately be processed. The {@link StreamSourceChannel#close()} or {@link StreamSourceChannel#shutdownReads()}
* method must be called at some point after the request is processed to prevent resource leakage and to allow
* the next request to proceed. Any unread content will be discarded.
*
* @return the channel for the inbound request, or {@code null} if another party already acquired the channel
*/
public StreamSourceChannel getRequestChannel() {
if (requestChannel != null) {
if (anyAreSet(state, FLAG_REQUEST_RESET)) {
state &= ~FLAG_REQUEST_RESET;
return requestChannel;
}
return null;
}
if (anyAreSet(state, FLAG_REQUEST_TERMINATED)) {
return requestChannel = new ReadDispatchChannel(new ConduitStreamSourceChannel(Configurable.EMPTY, new EmptyStreamSourceConduit(getIoThread())));
}
final ConduitWrapper<StreamSourceConduit>[] wrappers = this.requestWrappers;
final ConduitStreamSourceChannel sourceChannel = connection.getSourceChannel();
if (wrappers != null) {
this.requestWrappers = null;
final WrapperConduitFactory<StreamSourceConduit> factory = new WrapperConduitFactory<>(wrappers, requestWrapperCount, sourceChannel.getConduit(), this);
sourceChannel.setConduit(factory.create());
}
return requestChannel = new ReadDispatchChannel(sourceChannel);
}
use of org.xnio.conduits.StreamSourceConduit in project wildfly by wildfly.
the class DistributableSessionTestCase method changeSessionIdResponseCommitted.
public void changeSessionIdResponseCommitted() {
when(this.session.getMetaData()).thenReturn(this.metaData);
when(this.metaData.isNew()).thenReturn(false);
when(this.session.isValid()).thenReturn(true);
io.undertow.server.session.Session session = new DistributableSession(this.manager, this.session, this.config, this.batch, this.closeTask);
// Ugh - all this, just to get HttpServerExchange.isResponseStarted() to return true
Configurable configurable = mock(Configurable.class);
StreamSourceConduit sourceConduit = mock(StreamSourceConduit.class);
ConduitStreamSourceChannel sourceChannel = new ConduitStreamSourceChannel(configurable, sourceConduit);
StreamSinkConduit sinkConduit = mock(StreamSinkConduit.class);
ConduitStreamSinkChannel sinkChannel = new ConduitStreamSinkChannel(configurable, sinkConduit);
StreamConnection stream = mock(StreamConnection.class);
when(stream.getSourceChannel()).thenReturn(sourceChannel);
when(stream.getSinkChannel()).thenReturn(sinkChannel);
ByteBufferPool bufferPool = mock(ByteBufferPool.class);
HttpHandler handler = mock(HttpHandler.class);
HttpServerConnection connection = new HttpServerConnection(stream, bufferPool, handler, OptionMap.create(UndertowOptions.ALWAYS_SET_DATE, false), 0, null);
HttpServerExchange exchange = new HttpServerExchange(connection);
exchange.setProtocol(Protocols.HTTP_1_1);
exchange.getResponseChannel();
SessionConfig config = mock(SessionConfig.class);
Assert.assertThrows(IllegalStateException.class, () -> session.changeSessionId(exchange, config));
}
use of org.xnio.conduits.StreamSourceConduit in project oap by oaplatform.
the class HttpServerExchangeStub method createSourceChannel.
private static ConduitStreamSourceChannel createSourceChannel() {
StreamSourceConduit sourceConduit = Mockito.mock(StreamSourceConduit.class);
ConduitStreamSourceChannel sourceChannel = new ConduitStreamSourceChannel(null, sourceConduit);
return sourceChannel;
}
use of org.xnio.conduits.StreamSourceConduit in project wildfly by wildfly.
the class DistributableSessionManagerTestCase method createSessionResponseCommitted.
@Test
public void createSessionResponseCommitted() {
// Ugh - all this, just to get HttpServerExchange.isResponseStarted() to return true
Configurable configurable = mock(Configurable.class);
StreamSourceConduit sourceConduit = mock(StreamSourceConduit.class);
ConduitStreamSourceChannel sourceChannel = new ConduitStreamSourceChannel(configurable, sourceConduit);
StreamSinkConduit sinkConduit = mock(StreamSinkConduit.class);
ConduitStreamSinkChannel sinkChannel = new ConduitStreamSinkChannel(configurable, sinkConduit);
StreamConnection stream = mock(StreamConnection.class);
when(stream.getSourceChannel()).thenReturn(sourceChannel);
when(stream.getSinkChannel()).thenReturn(sinkChannel);
ByteBufferPool bufferPool = mock(ByteBufferPool.class);
HttpHandler handler = mock(HttpHandler.class);
HttpServerConnection connection = new HttpServerConnection(stream, bufferPool, handler, OptionMap.create(UndertowOptions.ALWAYS_SET_DATE, false), 0, null);
HttpServerExchange exchange = new HttpServerExchange(connection);
exchange.setProtocol(Protocols.HTTP_1_1);
exchange.getResponseChannel();
SessionConfig config = mock(SessionConfig.class);
Assert.assertThrows(IllegalStateException.class, () -> this.adapter.createSession(exchange, config));
}
Aggregations