Search in sources :

Example 11 with HttpServer

use of com.linkedin.r2.transport.http.server.HttpServer in project rest.li by linkedin.

the class HttpServerFactory method createServer.

public HttpServer createServer(int port, String contextPath, int threadPoolSize, TransportDispatcher transportDispatcher, HttpJettyServer.ServletType servletType, int asyncTimeOut, boolean restOverStream) {
    final TransportDispatcher filterDispatcher = new FilterChainDispatcher(transportDispatcher, _filters);
    final HttpDispatcher dispatcher = HttpDispatcherFactory.create((filterDispatcher));
    return new HttpJettyServer(port, contextPath, threadPoolSize, dispatcher, servletType, asyncTimeOut, restOverStream);
}
Also used : FilterChainDispatcher(com.linkedin.r2.filter.transport.FilterChainDispatcher) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher)

Example 12 with HttpServer

use of com.linkedin.r2.transport.http.server.HttpServer in project rest.li by linkedin.

the class TestMockHttpServerFactory method testCreateUsingPackageNames.

@Test
public void testCreateUsingPackageNames() throws IOException, RemoteInvocationException {
    Map<String, Object> beans = getBeans();
    boolean[] enableAsyncOptions = { true, false };
    for (boolean enableAsync : enableAsyncOptions) {
        HttpServer server = MockHttpServerFactory.create(PORT, new String[] { "com.linkedin.restli.example.impl" }, beans, enableAsync);
        runTest(server);
    }
}
Also used : HttpServer(com.linkedin.r2.transport.http.server.HttpServer) Test(org.testng.annotations.Test)

Example 13 with HttpServer

use of com.linkedin.r2.transport.http.server.HttpServer in project rest.li by linkedin.

the class HttpNettyServerFactory method createServer.

public HttpServer createServer(int port, int threadPoolSize, TransportDispatcher transportDispatcher) {
    final TransportDispatcher filterDispatcher = new FilterChainDispatcher(transportDispatcher, _filters);
    final HttpDispatcher dispatcher = HttpDispatcherFactory.create((filterDispatcher));
    return new HttpNettyServer(port, threadPoolSize, dispatcher);
}
Also used : FilterChainDispatcher(com.linkedin.r2.filter.transport.FilterChainDispatcher) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher)

Example 14 with HttpServer

use of com.linkedin.r2.transport.http.server.HttpServer in project rest.li by linkedin.

the class RestLiIntTestServer method main.

public static void main(String[] args) throws IOException {
    final int numCores = Runtime.getRuntime().availableProcessors();
    final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(numCores + 1);
    final Engine engine = new EngineBuilder().setTaskExecutor(scheduler).setTimerScheduler(scheduler).build();
    HttpServer server = createServer(engine, DEFAULT_PORT, supportedCompression);
    server.start();
    System.out.println("HttpServer running on port " + DEFAULT_PORT + ". Press any key to stop server");
    System.in.read();
    server.stop();
    engine.shutdown();
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) HttpServer(com.linkedin.r2.transport.http.server.HttpServer) EngineBuilder(com.linkedin.parseq.EngineBuilder) Engine(com.linkedin.parseq.Engine)

Example 15 with HttpServer

use of com.linkedin.r2.transport.http.server.HttpServer in project rest.li by linkedin.

the class RestLiIntTestServer method createServer.

public static HttpServer createServer(Engine engine, int port, boolean useAsyncServletApi, int asyncTimeOut, List<? extends Filter> filters, FilterChain filterChain, boolean restOverStream, boolean useDocumentHandler, boolean useDebugHandler, RestLiConfig config) {
    config.addResourcePackageNames(RESOURCE_PACKAGE_NAMES);
    config.setServerNodeUri(URI.create("http://localhost:" + port));
    if (useDocumentHandler && config.getDocumentationRequestHandler() == null) {
        config.setDocumentationRequestHandler(new DefaultDocumentationRequestHandler());
    }
    if (useDebugHandler) {
        config.addDebugRequestHandlers(new ParseqTraceDebugRequestHandler());
    }
    config.setFilters(filters);
    config.setUseStreamCodec(Boolean.parseBoolean(System.getProperty("test.useStreamCodecServer", "false")));
    GroupMembershipMgr membershipMgr = new HashGroupMembershipMgr();
    GroupMgr groupMgr = new HashMapGroupMgr(membershipMgr);
    GroupsRestApplication app = new GroupsRestApplication(groupMgr, membershipMgr);
    SimpleBeanProvider beanProvider = new SimpleBeanProvider();
    beanProvider.add("GroupsRestApplication", app);
    // using InjectMockResourceFactory to keep examples spring-free
    ResourceFactory factory = new InjectMockResourceFactory(beanProvider);
    RestLiServer restLiServer = new RestLiServer(config, factory, engine);
    TransportDispatcher dispatcher = new DelegatingTransportDispatcher(restLiServer, restLiServer);
    return new HttpServerFactory(filterChain).createServer(port, HttpServerFactory.DEFAULT_CONTEXT_PATH, HttpServerFactory.DEFAULT_THREAD_POOL_SIZE, dispatcher, useAsyncServletApi ? HttpJettyServer.ServletType.ASYNC_EVENT : HttpJettyServer.ServletType.RAP, asyncTimeOut, restOverStream);
}
Also used : HttpServerFactory(com.linkedin.r2.transport.http.server.HttpServerFactory) RestLiServer(com.linkedin.restli.server.RestLiServer) SimpleBeanProvider(com.linkedin.restli.server.mock.SimpleBeanProvider) DelegatingTransportDispatcher(com.linkedin.restli.server.DelegatingTransportDispatcher) DefaultDocumentationRequestHandler(com.linkedin.restli.docgen.DefaultDocumentationRequestHandler) InjectMockResourceFactory(com.linkedin.restli.server.mock.InjectMockResourceFactory) ResourceFactory(com.linkedin.restli.server.resources.ResourceFactory) DelegatingTransportDispatcher(com.linkedin.restli.server.DelegatingTransportDispatcher) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher) ParseqTraceDebugRequestHandler(com.linkedin.restli.server.ParseqTraceDebugRequestHandler) HashGroupMembershipMgr(com.linkedin.restli.examples.groups.server.impl.HashGroupMembershipMgr) GroupMembershipMgr(com.linkedin.restli.examples.groups.server.api.GroupMembershipMgr) HashMapGroupMgr(com.linkedin.restli.examples.groups.server.impl.HashMapGroupMgr) GroupMgr(com.linkedin.restli.examples.groups.server.api.GroupMgr) InjectMockResourceFactory(com.linkedin.restli.server.mock.InjectMockResourceFactory) HashGroupMembershipMgr(com.linkedin.restli.examples.groups.server.impl.HashGroupMembershipMgr) HashMapGroupMgr(com.linkedin.restli.examples.groups.server.impl.HashMapGroupMgr) GroupsRestApplication(com.linkedin.restli.examples.groups.server.rest.impl.GroupsRestApplication)

Aggregations

TransportDispatcher (com.linkedin.r2.transport.common.bridge.server.TransportDispatcher)11 FilterChainDispatcher (com.linkedin.r2.filter.transport.FilterChainDispatcher)7 HttpServer (com.linkedin.r2.transport.http.server.HttpServer)6 HttpServerFactory (com.linkedin.r2.transport.http.server.HttpServerFactory)4 DelegatingTransportDispatcher (com.linkedin.restli.server.DelegatingTransportDispatcher)4 RestLiServer (com.linkedin.restli.server.RestLiServer)4 InjectMockResourceFactory (com.linkedin.restli.server.mock.InjectMockResourceFactory)4 ResourceFactory (com.linkedin.restli.server.resources.ResourceFactory)4 DefaultDocumentationRequestHandler (com.linkedin.restli.docgen.DefaultDocumentationRequestHandler)3 SimpleBeanProvider (com.linkedin.restli.server.mock.SimpleBeanProvider)3 Engine (com.linkedin.parseq.Engine)2 EngineBuilder (com.linkedin.parseq.EngineBuilder)2 GroupMembershipMgr (com.linkedin.restli.examples.groups.server.api.GroupMembershipMgr)2 GroupMgr (com.linkedin.restli.examples.groups.server.api.GroupMgr)2 HashGroupMembershipMgr (com.linkedin.restli.examples.groups.server.impl.HashGroupMembershipMgr)2 HashMapGroupMgr (com.linkedin.restli.examples.groups.server.impl.HashMapGroupMgr)2 GroupsRestApplication (com.linkedin.restli.examples.groups.server.rest.impl.GroupsRestApplication)2 ParseqTraceDebugRequestHandler (com.linkedin.restli.server.ParseqTraceDebugRequestHandler)2 RestLiConfig (com.linkedin.restli.server.RestLiConfig)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2