Search in sources :

Example 1 with Http2Socket

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());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Http2Config(com.webpieces.http2engine.api.client.Http2Config) Http2Socket(org.webpieces.http2client.api.Http2Socket) InjectionConfig(com.webpieces.http2engine.api.client.InjectionConfig) Http2Client(org.webpieces.http2client.api.Http2Client) Before(org.junit.Before)

Example 2 with Http2Socket

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;
}
Also used : HpackParser(com.webpieces.hpack.api.HpackParser) ChannelManager(org.webpieces.nio.api.ChannelManager) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) SSLEngine(javax.net.ssl.SSLEngine) InjectionConfig(com.webpieces.http2engine.api.client.InjectionConfig) BufferCreationPool(org.webpieces.data.api.BufferCreationPool) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) BufferPool(org.webpieces.data.api.BufferPool) Executor(java.util.concurrent.Executor) Http2Socket(org.webpieces.http2client.api.Http2Socket) Http2Client(org.webpieces.http2client.api.Http2Client)

Example 3 with Http2Socket

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);
}
Also used : BufferPool(org.webpieces.data.api.BufferPool) CompletableFuture(java.util.concurrent.CompletableFuture) Http2ClientFactory(org.webpieces.http2client.api.Http2ClientFactory) ChannelManager(org.webpieces.nio.api.ChannelManager) ArrayList(java.util.ArrayList) SSLEngine(javax.net.ssl.SSLEngine) PushPromiseListener(com.webpieces.http2engine.api.PushPromiseListener) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) Http2Push(com.webpieces.hpack.api.dto.Http2Push) Http2Request(com.webpieces.hpack.api.dto.Http2Request) HpackParser(com.webpieces.hpack.api.HpackParser) Http2Socket(org.webpieces.http2client.api.Http2Socket) HpackParserFactory(com.webpieces.hpack.api.HpackParserFactory) ResponseHandler(com.webpieces.http2engine.api.ResponseHandler) Logger(org.webpieces.util.logging.Logger) InjectionConfig(com.webpieces.http2engine.api.client.InjectionConfig) Executor(java.util.concurrent.Executor) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) CancelReason(com.webpieces.http2parser.api.dto.CancelReason) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) InetSocketAddress(java.net.InetSocketAddress) Executors(java.util.concurrent.Executors) Http2HeaderName(com.webpieces.http2parser.api.dto.lib.Http2HeaderName) PushStreamHandle(com.webpieces.http2engine.api.PushStreamHandle) Http2Client(org.webpieces.http2client.api.Http2Client) List(java.util.List) BufferCreationPool(org.webpieces.data.api.BufferCreationPool) StreamWriter(com.webpieces.http2engine.api.StreamWriter) LoggerFactory(org.webpieces.util.logging.LoggerFactory) Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Request(com.webpieces.hpack.api.dto.Http2Request) InetSocketAddress(java.net.InetSocketAddress) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) Http2Socket(org.webpieces.http2client.api.Http2Socket)

Example 4 with Http2Socket

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);
}
Also used : Logger(org.webpieces.util.logging.Logger) CancelReason(com.webpieces.http2parser.api.dto.CancelReason) CompletableFuture(java.util.concurrent.CompletableFuture) InetSocketAddress(java.net.InetSocketAddress) PushPromiseListener(com.webpieces.http2engine.api.PushPromiseListener) PushStreamHandle(com.webpieces.http2engine.api.PushStreamHandle) StreamWriter(com.webpieces.http2engine.api.StreamWriter) Http2Push(com.webpieces.hpack.api.dto.Http2Push) Http2Request(com.webpieces.hpack.api.dto.Http2Request) LoggerFactory(org.webpieces.util.logging.LoggerFactory) Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Socket(org.webpieces.http2client.api.Http2Socket) ResponseHandler(com.webpieces.http2engine.api.ResponseHandler) Http2Request(com.webpieces.hpack.api.dto.Http2Request) InetSocketAddress(java.net.InetSocketAddress) Http2Socket(org.webpieces.http2client.api.Http2Socket)

Example 5 with Http2Socket

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);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SSLEngine(javax.net.ssl.SSLEngine) ForTestSslClientEngineFactory(org.webpieces.http2client.integ.ForTestSslClientEngineFactory) InjectionConfig(com.webpieces.http2engine.api.client.InjectionConfig) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) Http2Config(com.webpieces.http2engine.api.client.Http2Config) Http2Socket(org.webpieces.http2client.api.Http2Socket) Preface(org.webpieces.http2client.mock.Preface) Http2Client(org.webpieces.http2client.api.Http2Client) Before(org.junit.Before)

Aggregations

Http2Socket (org.webpieces.http2client.api.Http2Socket)8 InetSocketAddress (java.net.InetSocketAddress)7 InjectionConfig (com.webpieces.http2engine.api.client.InjectionConfig)6 Http2Client (org.webpieces.http2client.api.Http2Client)6 Http2Config (com.webpieces.http2engine.api.client.Http2Config)4 Before (org.junit.Before)4 Http2Push (com.webpieces.hpack.api.dto.Http2Push)3 Http2Request (com.webpieces.hpack.api.dto.Http2Request)3 Http2Response (com.webpieces.hpack.api.dto.Http2Response)3 PushPromiseListener (com.webpieces.http2engine.api.PushPromiseListener)3 PushStreamHandle (com.webpieces.http2engine.api.PushStreamHandle)3 ResponseHandler (com.webpieces.http2engine.api.ResponseHandler)3 StreamWriter (com.webpieces.http2engine.api.StreamWriter)3 CancelReason (com.webpieces.http2parser.api.dto.CancelReason)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Executor (java.util.concurrent.Executor)3 SSLEngine (javax.net.ssl.SSLEngine)3 Logger (org.webpieces.util.logging.Logger)3 LoggerFactory (org.webpieces.util.logging.LoggerFactory)3 NamedThreadFactory (org.webpieces.util.threading.NamedThreadFactory)3