Search in sources :

Example 1 with HttpParser

use of org.webpieces.httpparser.api.HttpParser in project webpieces by deanhiller.

the class TestBeans method testIncomingDataAndDataSeperate.

@Test
public void testIncomingDataAndDataSeperate() {
    HttpDummyRequest req = Requests.createPostRequest("/postArray2", "user.accounts[1].name", "Account2Name", "user.accounts[1].color", "green", "user.accounts[2].addresses[0].number", "56", "user.firstName", "D&D", "user.lastName", "Hiller", "user.fullName", "Dean Hiller");
    DataWrapperGenerator dataGen = DataWrapperGeneratorFactory.createDataWrapperGenerator();
    HttpParser parser = HttpParserFactory.createParser(new BufferCreationPool());
    MarshalState state = parser.prepareToMarshal();
    ByteBuffer buffer = parser.marshalToByteBuffer(state, req.getRequest());
    DataWrapper d1 = dataGen.wrapByteBuffer(buffer);
    ByteBuffer buf2 = parser.marshalToByteBuffer(state, req.getData());
    DataWrapper data = dataGen.chainDataWrappers(d1, dataGen.wrapByteBuffer(buf2));
    // Split the body in half
    List<? extends DataWrapper> split = dataGen.split(data, data.getReadableSize() - 20);
    http11Socket.sendBytes(split.get(0));
    http11Socket.sendBytes(split.get(1));
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    UserDto user = mockSomeLib.getUser();
    Assert.assertEquals("D&D", user.getFirstName());
    Assert.assertEquals(3, user.getAccounts().size());
    Assert.assertEquals("Account2Name", user.getAccounts().get(1).getName());
    Assert.assertEquals(56, user.getAccounts().get(2).getAddresses().get(0).getNumber());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) DataWrapperGenerator(org.webpieces.data.api.DataWrapperGenerator) MarshalState(org.webpieces.httpparser.api.MarshalState) FullResponse(org.webpieces.webserver.test.FullResponse) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) UserDto(org.webpieces.webserver.basic.app.biz.UserDto) HttpParser(org.webpieces.httpparser.api.HttpParser) ByteBuffer(java.nio.ByteBuffer) BufferCreationPool(org.webpieces.data.api.BufferCreationPool) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 2 with HttpParser

use of org.webpieces.httpparser.api.HttpParser in project webpieces by deanhiller.

the class HttpFrontendFactory method createFrontEnd.

public static HttpFrontendManager createFrontEnd(ChannelManager chanMgr, ScheduledExecutorService timer, InjectionConfig injConfig, MeterRegistry metrics) {
    TwoPools pool = new TwoPools(chanMgr.getName() + ".bufpoolmain", metrics);
    HttpParser httpParser = HttpParserFactory.createParser(chanMgr.getName(), metrics, pool);
    return createFrontEnd(chanMgr, timer, injConfig, httpParser, metrics);
}
Also used : TwoPools(org.webpieces.data.api.TwoPools) HttpParser(org.webpieces.httpparser.api.HttpParser)

Example 3 with HttpParser

use of org.webpieces.httpparser.api.HttpParser in project webpieces by deanhiller.

the class HttpFrontendFactory method createFrontEnd.

/**
 * @param id Use for logging and also file recording names
 * use the SessionExecutorImpl found in webpieces
 * @param metrics
 *
 * @return
 */
public static HttpFrontendManager createFrontEnd(String id, ScheduledExecutorService timer, BufferPool pool, FrontendMgrConfig config, MeterRegistry metrics) {
    Executor executor = Executors.newFixedThreadPool(config.getThreadPoolSize(), new NamedThreadFactory(id));
    MetricsCreator.monitor(metrics, executor, id);
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory(metrics);
    ChannelManager chanMgr = factory.createMultiThreadedChanMgr(id, pool, config.getBackpressureConfig(), executor);
    AsyncServerManager svrMgr = AsyncServerMgrFactory.createAsyncServer(chanMgr, metrics);
    HttpParser httpParser = HttpParserFactory.createParser(id, metrics, pool);
    HpackParser http2Parser = HpackParserFactory.createParser(pool, true);
    InjectionConfig injConfig = new InjectionConfig(http2Parser, new TimeImpl(), config.getHttp2Config());
    Http2ServerEngineFactory svrEngineFactory = new Http2ServerEngineFactory(injConfig);
    return new FrontEndServerManagerImpl(svrMgr, timer, svrEngineFactory, httpParser);
}
Also used : HpackParser(com.webpieces.hpack.api.HpackParser) Executor(java.util.concurrent.Executor) ChannelManager(org.webpieces.nio.api.ChannelManager) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) InjectionConfig(com.webpieces.http2engine.api.client.InjectionConfig) HttpParser(org.webpieces.httpparser.api.HttpParser) AsyncServerManager(org.webpieces.asyncserver.api.AsyncServerManager) Http2ServerEngineFactory(com.webpieces.http2engine.api.server.Http2ServerEngineFactory) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) TimeImpl(org.webpieces.util.time.TimeImpl) FrontEndServerManagerImpl(org.webpieces.frontend2.impl.FrontEndServerManagerImpl)

Example 4 with HttpParser

use of org.webpieces.httpparser.api.HttpParser in project webpieces by deanhiller.

the class WebServerModule method providesAsyncServerMgr.

@Provides
@Singleton
public HttpFrontendManager providesAsyncServerMgr(ChannelManager chanMgr, ScheduledExecutorService timer, BufferPool pool, Time time, WebServerConfig config, MeterRegistry metrics) {
    HttpParser httpParser = HttpParserFactory.createParser("a", new SimpleMeterRegistry(), pool);
    HpackParser http2Parser = HpackParserFactory.createParser(pool, true);
    InjectionConfig injConfig = new InjectionConfig(http2Parser, time, config.getHttp2Config());
    return HttpFrontendFactory.createFrontEnd(chanMgr, timer, injConfig, httpParser, metrics);
}
Also used : HpackParser(com.webpieces.hpack.api.HpackParser) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) InjectionConfig(com.webpieces.http2engine.api.client.InjectionConfig) HttpParser(org.webpieces.httpparser.api.HttpParser) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 5 with HttpParser

use of org.webpieces.httpparser.api.HttpParser in project webpieces by deanhiller.

the class TestCancelStream method setup.

@Before
public void setup() {
    SimpleMeterRegistry metrics = new SimpleMeterRegistry();
    TwoPools pool = new TwoPools("client.bufferpool", metrics);
    HttpParser parser = HttpParserFactory.createParser("testParser", metrics, pool);
    httpClient = HttpClientFactory.createHttpClient("testClient", mockChanMgr, parser);
    mockChannel.setConnectFuture(XFuture.completedFuture(null));
    mockChanMgr.addTCPChannelToReturn(mockChannel);
    httpSocket = httpClient.createHttpSocket(new SocketListener());
}
Also used : TwoPools(org.webpieces.data.api.TwoPools) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) HttpParser(org.webpieces.httpparser.api.HttpParser) Before(org.junit.Before)

Aggregations

HttpParser (org.webpieces.httpparser.api.HttpParser)15 TwoPools (org.webpieces.data.api.TwoPools)6 HpackParser (com.webpieces.hpack.api.HpackParser)5 InjectionConfig (com.webpieces.http2engine.api.client.InjectionConfig)5 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)5 Executor (java.util.concurrent.Executor)5 ChannelManager (org.webpieces.nio.api.ChannelManager)5 ChannelManagerFactory (org.webpieces.nio.api.ChannelManagerFactory)5 NamedThreadFactory (org.webpieces.util.threading.NamedThreadFactory)5 Http2ServerEngineFactory (com.webpieces.http2engine.api.server.Http2ServerEngineFactory)3 BufferCreationPool (org.webpieces.data.api.BufferCreationPool)3 FrontEndServerManagerImpl (org.webpieces.frontend2.impl.FrontEndServerManagerImpl)3 Provides (com.google.inject.Provides)2 ByteBuffer (java.nio.ByteBuffer)2 Singleton (javax.inject.Singleton)2 Before (org.junit.Before)2 Test (org.junit.Test)2 AsyncServerManager (org.webpieces.asyncserver.api.AsyncServerManager)2 DataWrapper (org.webpieces.data.api.DataWrapper)2 DataWrapperGenerator (org.webpieces.data.api.DataWrapperGenerator)2