Search in sources :

Example 1 with Http2Client

use of org.webpieces.http2client.api.Http2Client in project webpieces by deanhiller.

the class GuiceModule method createClient.

@Provides
@Singleton
public Http2Client createClient(MeterRegistry metrics) {
    BackpressureConfig config = new BackpressureConfig();
    // clients should NOT have backpressure or it could screw the server over when the server does not support backpresssure
    config.setMaxBytes(null);
    // This is an http1_1 client masquerading as an http2 client so we can switch to http2 faster when ready!!
    Http2Client httpClient = Http2to11ClientFactory.createHttpClient("httpclient", 10, config, metrics);
    return httpClient;
}
Also used : BackpressureConfig(org.webpieces.nio.api.BackpressureConfig) Http2Client(org.webpieces.http2client.api.Http2Client) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 2 with Http2Client

use of org.webpieces.http2client.api.Http2Client in project webpieces by deanhiller.

the class IntegSingleRequest method createHttpClient.

public static Http2Socket createHttpClient(String id, boolean isHttp, InetSocketAddress addr) {
    BufferPool pool2 = new TwoPools("pl", new SimpleMeterRegistry());
    HpackParser hpackParser = HpackParserFactory.createParser(pool2, false);
    Executor executor2 = Executors.newFixedThreadPool(10, new NamedThreadFactory("clientThread"));
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory(Metrics.globalRegistry);
    ChannelManager mgr = factory.createMultiThreadedChanMgr("client", pool2, new BackpressureConfig(), 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("myClient", mgr, injConfig);
    Http2Socket socket;
    if (isHttp) {
        socket = client.createHttpSocket(new Http2CloseListener());
    } else {
        socket = client.createHttpsSocket(engine, new Http2CloseListener());
    }
    return socket;
}
Also used : HpackParser(com.webpieces.hpack.api.HpackParser) BackpressureConfig(org.webpieces.nio.api.BackpressureConfig) ChannelManager(org.webpieces.nio.api.ChannelManager) TwoPools(org.webpieces.data.api.TwoPools) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) SSLEngine(javax.net.ssl.SSLEngine) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) InjectionConfig(com.webpieces.http2engine.api.client.InjectionConfig) 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 Http2Client

use of org.webpieces.http2client.api.Http2Client in project webpieces by deanhiller.

the class CompanyTest method initialize.

public void initialize() {
    log.info("Setting up test");
    // Necessary to avoid errors that could be confusing to developers...(fail early instead with what is wrong)
    Asserts.assertWasCompiledWithParamNames("test");
    try {
        startServer();
    } catch (IOException ex) {
        throw SneakyThrow.sneak(ex);
    }
    if (serverHttpAddr == null || serverHttpsAddr == null)
        throw new IllegalStateException("startServer method forgot to set the serverHttpAddr and serverHttpsAddr");
    simulateContext();
    Http2Client http2Client = getClient();
    Injector injector = Guice.createInjector(new ClientTestModule(http2Client));
    restClientCreator = injector.getInstance(RESTClientCreator.class);
    initialized = true;
}
Also used : RESTClientCreator(org.webpieces.microsvc.client.api.RESTClientCreator) Injector(com.google.inject.Injector) IOException(java.io.IOException) Http2Client(org.webpieces.http2client.api.Http2Client)

Example 4 with Http2Client

use of org.webpieces.http2client.api.Http2Client in project webpieces by deanhiller.

the class TestC3InitialHttpConnections method setUp.

@Before
public void setUp() throws InterruptedException, ExecutionException, TimeoutException {
    mockChannel.setIncomingFrameDefaultReturnValue(XFuture.completedFuture(null));
    Http2Config config = new Http2Config();
    // start with 1 max concurrent
    config.setInitialRemoteMaxConcurrent(1);
    config.setLocalSettings(localSettings);
    SimpleMeterRegistry metrics = new SimpleMeterRegistry();
    InjectionConfig injConfig = new InjectionConfig(mockTime, config, metrics);
    Http2Client client = Http2ClientFactory.createHttpClient("test2Client", mockChanMgr, injConfig);
    mockChanMgr.addTCPChannelToReturn(mockChannel);
    socket = client.createHttpSocket(new SocketListener());
    XFuture<Void> connect = socket.connect(new InetSocketAddress(555));
    connect.get(2, TimeUnit.SECONDS);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Http2Config(com.webpieces.http2engine.api.client.Http2Config) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) InjectionConfig(com.webpieces.http2engine.api.client.InjectionConfig) Http2Client(org.webpieces.http2client.api.Http2Client) Before(org.junit.Before)

Example 5 with Http2Client

use of org.webpieces.http2client.api.Http2Client in project webpieces by deanhiller.

the class IntegSingleRequest method createHttpClient.

public static Http2Socket createHttpClient(String id, boolean isHttp, InetSocketAddress addr) {
    BufferPool pool2 = new TwoPools("pl", new SimpleMeterRegistry());
    HpackParser hpackParser = HpackParserFactory.createParser(pool2, false);
    Executor executor2 = Executors.newFixedThreadPool(10, new NamedThreadFactory("clientThread"));
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory(Metrics.globalRegistry);
    ChannelManager mgr = factory.createMultiThreadedChanMgr("client", pool2, new BackpressureConfig(), 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(id, mgr, injConfig);
    Http2Socket socket;
    if (isHttp) {
        socket = client.createHttpSocket(new SocketListener());
    } else {
        socket = client.createHttpsSocket(engine, new SocketListener());
    }
    return socket;
}
Also used : HpackParser(com.webpieces.hpack.api.HpackParser) BackpressureConfig(org.webpieces.nio.api.BackpressureConfig) ChannelManager(org.webpieces.nio.api.ChannelManager) TwoPools(org.webpieces.data.api.TwoPools) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) SSLEngine(javax.net.ssl.SSLEngine) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) InjectionConfig(com.webpieces.http2engine.api.client.InjectionConfig) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) BufferPool(org.webpieces.data.api.BufferPool) Executor(java.util.concurrent.Executor) SocketListener(org.webpieces.http2client.SocketListener) Http2Socket(org.webpieces.http2client.api.Http2Socket) Http2Client(org.webpieces.http2client.api.Http2Client)

Aggregations

Http2Client (org.webpieces.http2client.api.Http2Client)11 InjectionConfig (com.webpieces.http2engine.api.client.InjectionConfig)7 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)7 Http2Config (com.webpieces.http2engine.api.client.Http2Config)5 InetSocketAddress (java.net.InetSocketAddress)5 Before (org.junit.Before)5 SSLEngine (javax.net.ssl.SSLEngine)3 TwoPools (org.webpieces.data.api.TwoPools)3 Http2Socket (org.webpieces.http2client.api.Http2Socket)3 BackpressureConfig (org.webpieces.nio.api.BackpressureConfig)3 ChannelManager (org.webpieces.nio.api.ChannelManager)3 ChannelManagerFactory (org.webpieces.nio.api.ChannelManagerFactory)3 HpackParser (com.webpieces.hpack.api.HpackParser)2 Executor (java.util.concurrent.Executor)2 BufferPool (org.webpieces.data.api.BufferPool)2 NamedThreadFactory (org.webpieces.util.threading.NamedThreadFactory)2 Injector (com.google.inject.Injector)1 Provides (com.google.inject.Provides)1 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)1 IOException (java.io.IOException)1