Search in sources :

Example 31 with TransportDispatcher

use of com.linkedin.r2.transport.common.bridge.server.TransportDispatcher in project rest.li by linkedin.

the class HttpNettyServerBuilder method build.

public HttpNettyServer build() {
    validateParameters();
    final TransportDispatcher filterDispatcher = new FilterChainDispatcher(_transportDispatcher, _filters);
    final HttpDispatcher dispatcher = HttpDispatcherFactory.create((filterDispatcher));
    return new HttpNettyServer(_port, _threadPoolSize, dispatcher, _sslContext, _sslParameters);
}
Also used : FilterChainDispatcher(com.linkedin.r2.filter.transport.FilterChainDispatcher) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher)

Example 32 with TransportDispatcher

use of com.linkedin.r2.transport.common.bridge.server.TransportDispatcher 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)

Example 33 with TransportDispatcher

use of com.linkedin.r2.transport.common.bridge.server.TransportDispatcher in project incubator-gobblin by apache.

the class JobExecutionInfoServer method startUp.

@Override
protected void startUp() throws Exception {
    // Server configuration
    RestLiConfig config = new RestLiConfig();
    config.addResourcePackageNames(JobExecutionInfoResource.class.getPackage().getName());
    config.setServerNodeUri(serverUri);
    config.setDocumentationRequestHandler(new DefaultDocumentationRequestHandler());
    // Handle dependency injection
    Injector injector = Guice.createInjector(new MetaStoreModule(properties));
    JobHistoryStore jobHistoryStore = injector.getInstance(JobHistoryStore.class);
    SimpleBeanProvider beanProvider = new SimpleBeanProvider();
    beanProvider.add("jobHistoryStore", jobHistoryStore);
    // Use InjectMockResourceFactory to keep this Spring free
    ResourceFactory factory = new InjectMockResourceFactory(beanProvider);
    // Create and start the HTTP server
    TransportDispatcher dispatcher = new DelegatingTransportDispatcher(new RestLiServer(config, factory));
    String acceptedFilters = EncodingType.SNAPPY.getHttpName() + "," + EncodingType.GZIP.getHttpName();
    FilterChain filterChain = FilterChains.createRestChain(new ServerCompressionFilter(acceptedFilters));
    this.httpServer = Optional.of(new HttpNettyServerFactory(filterChain).createServer(port, dispatcher));
    LOGGER.info("Starting the job execution information server");
    this.httpServer.get().start();
}
Also used : JobHistoryStore(org.apache.gobblin.metastore.JobHistoryStore) RestLiServer(com.linkedin.restli.server.RestLiServer) SimpleBeanProvider(com.linkedin.restli.server.mock.SimpleBeanProvider) DelegatingTransportDispatcher(com.linkedin.restli.server.DelegatingTransportDispatcher) HttpNettyServerFactory(com.linkedin.r2.transport.http.server.HttpNettyServerFactory) ServerCompressionFilter(com.linkedin.r2.filter.compression.ServerCompressionFilter) DefaultDocumentationRequestHandler(com.linkedin.restli.docgen.DefaultDocumentationRequestHandler) FilterChain(com.linkedin.r2.filter.FilterChain) 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) Injector(com.google.inject.Injector) InjectMockResourceFactory(com.linkedin.restli.server.mock.InjectMockResourceFactory) MetaStoreModule(org.apache.gobblin.metastore.MetaStoreModule) RestLiConfig(com.linkedin.restli.server.RestLiConfig)

Aggregations

TransportDispatcher (com.linkedin.r2.transport.common.bridge.server.TransportDispatcher)29 HttpServerFactory (com.linkedin.r2.transport.http.server.HttpServerFactory)14 TransportDispatcherBuilder (com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder)11 RequestContext (com.linkedin.r2.message.RequestContext)9 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)9 StreamRequestHandler (com.linkedin.r2.transport.common.StreamRequestHandler)9 FilterChainDispatcher (com.linkedin.r2.filter.transport.FilterChainDispatcher)8 RestRequest (com.linkedin.r2.message.rest.RestRequest)8 HashMap (java.util.HashMap)8 TransportClientAdapter (com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter)7 TransportCallback (com.linkedin.r2.transport.common.bridge.common.TransportCallback)7 Map (java.util.Map)7 DelegatingTransportDispatcher (com.linkedin.restli.server.DelegatingTransportDispatcher)6 RestLiServer (com.linkedin.restli.server.RestLiServer)6 ResourceFactory (com.linkedin.restli.server.resources.ResourceFactory)6 BeforeClass (org.testng.annotations.BeforeClass)6 FilterChain (com.linkedin.r2.filter.FilterChain)5 DrainReader (com.linkedin.r2.message.stream.entitystream.DrainReader)5 DefaultDocumentationRequestHandler (com.linkedin.restli.docgen.DefaultDocumentationRequestHandler)5 InjectMockResourceFactory (com.linkedin.restli.server.mock.InjectMockResourceFactory)5