org.webpieces.webserver.test.http11.DelayedProxy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http-webserver-test Show documentation
Show all versions of http-webserver-test Show documentation
The full webpieces server AS A library
package org.webpieces.webserver.test.http11;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.concurrent.CompletableFuture;
import org.webpieces.httpclient11.impl.ChannelProxy;
import org.webpieces.nio.api.handlers.ConnectionListener;
import org.webpieces.nio.api.handlers.DataListener;
import org.webpieces.webserver.test.MockTcpChannel;
public class DelayedProxy implements ChannelProxy {
private ConnectionListener listener;
private MockTcpChannel channel;
private DataListener toServerDataListener;
public DelayedProxy(ConnectionListener listener, MockTcpChannel channel) {
this.listener = listener;
this.channel = channel;
}
@Override
public CompletableFuture connect(InetSocketAddress addr, DataListener dataListener) {
channel.setDataListener(dataListener);
return listener.connected(channel, true).thenApply( d -> {
toServerDataListener = d;
return null;
});
}
@Override
public CompletableFuture write(ByteBuffer buffer) {
return toServerDataListener.incomingData(channel, buffer);
}
@Override
public CompletableFuture close() {
toServerDataListener.farEndClosed(channel);
return CompletableFuture.completedFuture(null);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy