Search in sources :

Example 1 with StreamSourceConduit

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);
}
Also used : EmptyStreamSourceConduit(io.undertow.conduits.EmptyStreamSourceConduit) ConduitStreamSourceChannel(org.xnio.conduits.ConduitStreamSourceChannel) StreamSourceConduit(org.xnio.conduits.StreamSourceConduit) EmptyStreamSourceConduit(io.undertow.conduits.EmptyStreamSourceConduit)

Example 2 with StreamSourceConduit

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));
}
Also used : ByteBufferPool(io.undertow.connector.ByteBufferPool) HttpHandler(io.undertow.server.HttpHandler) HttpServerConnection(io.undertow.server.protocol.http.HttpServerConnection) SessionConfig(io.undertow.server.session.SessionConfig) Configurable(org.xnio.channels.Configurable) StreamConnection(org.xnio.StreamConnection) StreamSourceConduit(org.xnio.conduits.StreamSourceConduit) HttpServerExchange(io.undertow.server.HttpServerExchange) StreamSinkConduit(org.xnio.conduits.StreamSinkConduit) ConduitStreamSourceChannel(org.xnio.conduits.ConduitStreamSourceChannel) ConduitStreamSinkChannel(org.xnio.conduits.ConduitStreamSinkChannel)

Example 3 with StreamSourceConduit

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;
}
Also used : ConduitStreamSourceChannel(org.xnio.conduits.ConduitStreamSourceChannel) StreamSourceConduit(org.xnio.conduits.StreamSourceConduit)

Example 4 with StreamSourceConduit

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));
}
Also used : ByteBufferPool(io.undertow.connector.ByteBufferPool) HttpServerExchange(io.undertow.server.HttpServerExchange) HttpHandler(io.undertow.server.HttpHandler) HttpServerConnection(io.undertow.server.protocol.http.HttpServerConnection) StreamSinkConduit(org.xnio.conduits.StreamSinkConduit) SessionConfig(io.undertow.server.session.SessionConfig) Configurable(org.xnio.channels.Configurable) ConduitStreamSourceChannel(org.xnio.conduits.ConduitStreamSourceChannel) StreamConnection(org.xnio.StreamConnection) StreamSourceConduit(org.xnio.conduits.StreamSourceConduit) ConduitStreamSinkChannel(org.xnio.conduits.ConduitStreamSinkChannel) Test(org.junit.Test)

Aggregations

ConduitStreamSourceChannel (org.xnio.conduits.ConduitStreamSourceChannel)4 StreamSourceConduit (org.xnio.conduits.StreamSourceConduit)4 ByteBufferPool (io.undertow.connector.ByteBufferPool)2 HttpHandler (io.undertow.server.HttpHandler)2 HttpServerExchange (io.undertow.server.HttpServerExchange)2 HttpServerConnection (io.undertow.server.protocol.http.HttpServerConnection)2 SessionConfig (io.undertow.server.session.SessionConfig)2 StreamConnection (org.xnio.StreamConnection)2 Configurable (org.xnio.channels.Configurable)2 ConduitStreamSinkChannel (org.xnio.conduits.ConduitStreamSinkChannel)2 StreamSinkConduit (org.xnio.conduits.StreamSinkConduit)2 EmptyStreamSourceConduit (io.undertow.conduits.EmptyStreamSourceConduit)1 Test (org.junit.Test)1