use of com.linkedin.restli.server.RestLiServer 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);
}
use of com.linkedin.restli.server.RestLiServer 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();
}
Aggregations