Search in sources :

Example 16 with HttpServer

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

the class RestLiExampleBasicServer method main.

public static void main(String[] args) throws Exception {
    final HttpServer server = createServer();
    startServer(server);
    System.out.println("Basic example server running on port " + SERVER_PORT + ". Press any key to stop server.");
    System.in.read();
    stopServer(server);
}
Also used : HttpServer(com.linkedin.r2.transport.http.server.HttpServer)

Example 17 with HttpServer

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

the class RestLiExampleBasicServer method createServer.

public static HttpServer createServer() {
    // create Rest.li resource class information and initialize documentation generator
    // only the resource classes in the specified package names are visible for public
    final RestLiConfig config = new RestLiConfig();
    config.addResourcePackageNames("com.linkedin.restli.example.impl");
    config.setServerNodeUri(URI.create(getServerUrl()));
    config.setDocumentationRequestHandler(new DefaultDocumentationRequestHandler());
    // Create an instance of the Example Filter and add it to the config.
    RestLiExampleFilter filter = new RestLiExampleFilter();
    config.addFilter(filter);
    // demonstrate dynamic dependency injection
    final PhotoDatabase photoDb = new PhotoDatabaseImpl(10);
    final SimpleBeanProvider beanProvider = new SimpleBeanProvider();
    beanProvider.add("photoDb", photoDb);
    beanProvider.add("albumDb", new AlbumDatabaseImpl(10));
    beanProvider.add("albumEntryDb", new AlbumEntryDatabaseImpl(photoDb, 3));
    // using InjectMockResourceFactory to keep examples spring-free
    final ResourceFactory factory = new InjectMockResourceFactory(beanProvider);
    final RestLiServer restliServer = new RestLiServer(config, factory);
    final TransportDispatcher dispatcher = new DelegatingTransportDispatcher(restliServer, restliServer);
    return new HttpServerFactory(FilterChains.empty()).createServer(SERVER_PORT, dispatcher);
}
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) ResourceFactory(com.linkedin.restli.server.resources.ResourceFactory) InjectMockResourceFactory(com.linkedin.restli.server.mock.InjectMockResourceFactory) DelegatingTransportDispatcher(com.linkedin.restli.server.DelegatingTransportDispatcher) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher) PhotoDatabase(com.linkedin.restli.example.impl.PhotoDatabase) AlbumEntryDatabaseImpl(com.linkedin.restli.example.impl.AlbumEntryDatabaseImpl) AlbumDatabaseImpl(com.linkedin.restli.example.impl.AlbumDatabaseImpl) PhotoDatabaseImpl(com.linkedin.restli.example.impl.PhotoDatabaseImpl) InjectMockResourceFactory(com.linkedin.restli.server.mock.InjectMockResourceFactory) RestLiConfig(com.linkedin.restli.server.RestLiConfig)

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