use of org.webpieces.http2client.api.Http2Socket in project webpieces by deanhiller.
the class TestC3InitialHttpConnections method setUp.
@Before
public void setUp() throws InterruptedException, ExecutionException {
mockChannel.setIncomingFrameDefaultReturnValue(CompletableFuture.completedFuture(mockChannel));
Http2Config config = new Http2Config();
//start with 1 max concurrent
config.setInitialRemoteMaxConcurrent(1);
config.setLocalSettings(localSettings);
InjectionConfig injConfig = new InjectionConfig(mockTime, config);
Http2Client client = Http2ClientFactory.createHttpClient(mockChanMgr, injConfig);
mockChanMgr.addTCPChannelToReturn(mockChannel);
socket = client.createHttpSocket("simple");
CompletableFuture<Http2Socket> connect = socket.connect(new InetSocketAddress(555));
Assert.assertTrue(connect.isDone());
Assert.assertEquals(socket, connect.get());
}
use of org.webpieces.http2client.api.Http2Socket in project webpieces by deanhiller.
the class IntegSingleRequest method createHttpClient.
public static Http2Socket createHttpClient(String id, boolean isHttp, InetSocketAddress addr) {
BufferPool pool2 = new BufferCreationPool();
HpackParser hpackParser = HpackParserFactory.createParser(pool2, false);
Executor executor2 = Executors.newFixedThreadPool(10, new NamedThreadFactory("clientThread"));
ChannelManagerFactory factory = ChannelManagerFactory.createFactory();
ChannelManager mgr = factory.createMultiThreadedChanMgr("client", pool2, executor2);
InjectionConfig injConfig = new InjectionConfig(hpackParser);
String host = addr.getHostName();
int port = addr.getPort();
ForTestSslClientEngineFactory ssl = new ForTestSslClientEngineFactory();
SSLEngine engine = ssl.createSslEngine(host, port);
Http2Client client = Http2ClientFactory.createHttpClient(mgr, injConfig);
Http2Socket socket;
if (isHttp) {
socket = client.createHttpSocket(id);
} else {
socket = client.createHttpsSocket(id, engine);
}
return socket;
}
use of org.webpieces.http2client.api.Http2Socket in project webpieces by deanhiller.
the class IntegSingleRequest method start.
public void start() throws InterruptedException {
log.info("starting test to download / page from google");
boolean isHttp = true;
String host = "www.google.com";
//String host = "localhost"; //jetty
//String host = "api.push.apple.com";
//String host = "gcm-http.googleapis.com";
//String host = "nghttp2.org";
int port = 443;
if (isHttp)
port = 80;
if ("localhost".equals(host)) {
port = 8443;
if (isHttp)
port = 8080;
}
List<Http2Header> req = createRequest(host, isHttp);
Http2Request request = new Http2Request(req);
request.setEndOfStream(true);
InetSocketAddress addr = new InetSocketAddress(host, port);
Http2Socket socket = createHttpClient("testRunSocket", isHttp, addr);
socket.connect(addr).thenAccept(s -> s.openStream().process(request, new ChunkedResponseListener())).exceptionally(e -> reportException(socket, e));
Thread.sleep(10000000);
}
use of org.webpieces.http2client.api.Http2Socket in project webpieces by deanhiller.
the class IntegColoradoEdu method main.
public static void main(String[] args) throws InterruptedException {
boolean isHttp = true;
String host = "www.colorado.edu";
int port = 443;
if (isHttp)
port = 80;
Http2Request req = createRequest(host);
log.info("starting socket");
ChunkedResponseListener listener = new ChunkedResponseListener();
InetSocketAddress addr = new InetSocketAddress(host, port);
Http2Socket socket = IntegSingleRequest.createHttpClient("oneTimerHttp2Socket", isHttp, addr);
socket.connect(addr).thenAccept(socet -> socket.openStream().process(req, listener)).exceptionally(e -> reportException(socket, e));
Thread.sleep(100000);
}
use of org.webpieces.http2client.api.Http2Socket in project webpieces by deanhiller.
the class TestC3InitialHttpsConnections method setUp.
@Before
public void setUp() throws InterruptedException, ExecutionException {
mockChannel.setIncomingFrameDefaultReturnValue(CompletableFuture.completedFuture(mockChannel));
Http2Config config = new Http2Config();
//start with 1 max concurrent
config.setInitialRemoteMaxConcurrent(1);
config.setLocalSettings(localSettings);
InjectionConfig injConfig = new InjectionConfig(mockTime, config);
Http2Client client = Http2ClientFactory.createHttpClient(mockChanMgr, injConfig);
mockChanMgr.addSSLChannelToReturn(mockChannel);
InetSocketAddress addr = new InetSocketAddress("somehost.com", 555);
String host = addr.getHostName();
int port = addr.getPort();
ForTestSslClientEngineFactory ssl = new ForTestSslClientEngineFactory();
SSLEngine engine = ssl.createSslEngine(host, port);
socket = client.createHttpsSocket("simple", engine);
CompletableFuture<Http2Socket> connect = socket.connect(addr);
Assert.assertTrue(connect.isDone());
Assert.assertEquals(socket, connect.get());
//verify settings on connect were sent
//verify settings on connect were sent
List<Http2Msg> frames = mockChannel.getFramesAndClear();
Preface preface = (Preface) frames.get(0);
preface.verify();
Http2Msg settings1 = frames.get(1);
Assert.assertEquals(HeaderSettings.createSettingsFrame(localSettings), settings1);
}
Aggregations