@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(); }
@Override protected void startUp() throws Exception { RestLiConfig config = new RestLiConfig(); Set<String> resourceClassNames = Sets.newHashSet(); for (Class<? extends BaseResource> resClass : this.resources) { resourceClassNames.add(resClass.getName()); } config.addResourceClassNames(resourceClassNames); config.setServerNodeUri(this.serverUri); config.setDocumentationRequestHandler(new DefaultDocumentationRequestHandler()); config.addFilter(new RestLiValidationFilter()); ResourceFactory factory = new GuiceInjectResourceFactory(this.injector); 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(this.port, dispatcher)); this.log.info("Starting the {} embedded server at port {}.", this.name, this.port); this.httpServer.get().start(); }
@Override protected void configure() { try { RestLiConfig restLiConfig = new RestLiConfig(); restLiConfig.setResourcePackageNames("org.apache.gobblin.restli.throttling"); bind(RestLiConfig.class).toInstance(restLiConfig); bind(SharedResourcesBroker.class).annotatedWith(Names.named(LimiterServerResource.BROKER_INJECT_NAME)).toInstance(topLevelBroker); MetricContext metricContext = topLevelBroker.getSharedResource(new MetricContextFactory<ThrottlingServerScopes>(), new MetricContextKey()); Timer timer = metricContext.timer(LimiterServerResource.REQUEST_TIMER_NAME); bind(MetricContext.class).annotatedWith(Names.named(LimiterServerResource.METRIC_CONTEXT_INJECT_NAME)).toInstance(metricContext); bind(Timer.class).annotatedWith(Names.named(LimiterServerResource.REQUEST_TIMER_INJECT_NAME)).toInstance(timer); bind(new TypeLiteral<Optional<LeaderFinder<URIMetadata>>>() { }).annotatedWith(Names.named(LimiterServerResource.LEADER_FINDER_INJECT_NAME)).toInstance(leaderFinder); List<RestFilter> restFilters = new ArrayList<>(); restFilters.add(new ServerCompressionFilter(EncodingType.SNAPPY.getHttpName())); List<StreamFilter> streamFilters = new ArrayList<>(); streamFilters.add(new SimpleLoggingFilter()); FilterChain filterChain = FilterChains.create(restFilters, streamFilters); bind(FilterChain.class).toInstance(filterChain); } catch (NotConfiguredException nce) { throw new RuntimeException(nce); } } }, new ServletModule() {
boolean useDebugHandler) RestLiConfig config = new RestLiConfig(); config.addResourcePackageNames(RESOURCE_PACKAGE_NAMES); config.setServerNodeUri(URI.create("http://localhost:" + port)); if (useDocumentHandler) config.setDocumentationRequestHandler(new DefaultDocumentationRequestHandler()); config.addDebugRequestHandlers(new ParseqTraceDebugRequestHandler()); config.setFilters(filters); config.setUseStreamCodec(Boolean.parseBoolean(System.getProperty("test.useStreamCodecServer", "false")));
/** * Creates {@link RestLiConfig} to be used by a {@link RestLiServer} * * @param port the port the server will run on * @return */ private static RestLiConfig createConfig(int port) { RestLiConfig restLiConfig = new RestLiConfig(); restLiConfig.setServerNodeUri(URI.create(LOCALHOST + port)); restLiConfig.setDocumentationRequestHandler(new DefaultDocumentationRequestHandler()); return restLiConfig; }
throws IOException final RestLiConfig config = new RestLiConfig(); if (resourcePackages != null) config.addResourcePackageNames(resourcePackages); config.addResourceClassNames(resourceClasses); config.addResourceClassNames(classFileNames.keySet());
RestLiConfig config = new RestLiConfig(); config.setResourcePackageNamesSet(getResourcePackageSet(servletConfig));
/** * @param commaDelimitedResourcePackageNames comma-delimited package names list */ public void setResourcePackageNames(final String commaDelimitedResourcePackageNames) { if (commaDelimitedResourcePackageNames != null && ! "".equals(commaDelimitedResourcePackageNames.trim())) { _resourcePackageNames.clear(); addResourcePackageNames(commaDelimitedResourcePackageNames.split(",")); } }
throws IOException final RestLiConfig config = new RestLiConfig(); if (resourcePackages != null) config.addResourcePackageNames(resourcePackages); config.addResourceClassNames(resourceClasses); config.addResourceClassNames(classFileNames.keySet()); sourceFileNames = classFileNames.values();
/** * Creates a {@link HttpServer} that contains a {@link RestLiServer} to be used for testing a set of Rest.li * resources. * * The {@link HttpServer} uses an empty {@link FilterChain} and uses "/" as the context path. * * If the server is run in async mode (by calling this function with the last parameter {@code true}), the * timeout used is {@link #ASYNC_TIMEOUT}. * * Both the async and sync servers will use {@link #NUM_THREADS} threads. * * The server is started by calling {@link com.linkedin.r2.transport.http.server.HttpServer#start()} * The server is stopped by calling {@link com.linkedin.r2.transport.http.server.HttpServer#stop()} * * @param port the port the server will run on on localhost * @param resourcePackageNames the names of the packages that contain the Rest.li resources that you wish to serve * @param beans beans you want to inject into your Rest.li resource. * @param enableAsync true if the server should be async, false otherwise * @return a {@link HttpServer} created with the above parameters */ public static HttpServer create(int port, String[] resourcePackageNames, Map<String, Object> beans, boolean enableAsync) { RestLiConfig config = createConfig(port); config.addResourcePackageNames(resourcePackageNames); return create(port, config, beans, enableAsync); }
@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(); }
@Override protected void startUp() throws Exception { RestLiConfig config = new RestLiConfig(); Set<String> resourceClassNames = Sets.newHashSet(); for (Class<? extends BaseResource> resClass : this.resources) { resourceClassNames.add(resClass.getName()); } config.addResourceClassNames(resourceClassNames); config.setServerNodeUri(this.serverUri); config.setDocumentationRequestHandler(new DefaultDocumentationRequestHandler()); config.addFilter(new RestLiValidationFilter()); ResourceFactory factory = new GuiceInjectResourceFactory(this.injector); 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(this.port, dispatcher)); this.log.info("Starting the {} embedded server at port {}.", this.name, this.port); this.httpServer.get().start(); }
@Override protected void configure() { try { RestLiConfig restLiConfig = new RestLiConfig(); restLiConfig.setResourcePackageNames("org.apache.gobblin.restli.throttling"); bind(RestLiConfig.class).toInstance(restLiConfig); bind(SharedResourcesBroker.class).annotatedWith(Names.named(LimiterServerResource.BROKER_INJECT_NAME)).toInstance(topLevelBroker); MetricContext metricContext = topLevelBroker.getSharedResource(new MetricContextFactory<ThrottlingServerScopes>(), new MetricContextKey()); Timer timer = metricContext.timer(LimiterServerResource.REQUEST_TIMER_NAME); bind(MetricContext.class).annotatedWith(Names.named(LimiterServerResource.METRIC_CONTEXT_INJECT_NAME)).toInstance(metricContext); bind(Timer.class).annotatedWith(Names.named(LimiterServerResource.REQUEST_TIMER_INJECT_NAME)).toInstance(timer); bind(new TypeLiteral<Optional<LeaderFinder<URIMetadata>>>() { }).annotatedWith(Names.named(LimiterServerResource.LEADER_FINDER_INJECT_NAME)).toInstance(leaderFinder); List<RestFilter> restFilters = new ArrayList<>(); restFilters.add(new ServerCompressionFilter(EncodingType.SNAPPY.getHttpName())); List<StreamFilter> streamFilters = new ArrayList<>(); streamFilters.add(new SimpleLoggingFilter()); FilterChain filterChain = FilterChains.create(restFilters, streamFilters); bind(FilterChain.class).toInstance(filterChain); } catch (NotConfiguredException nce) { throw new RuntimeException(nce); } } }, new ServletModule() {
@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(); }
@Override protected void configure() { try { RestLiConfig restLiConfig = new RestLiConfig(); restLiConfig.setResourcePackageNames("gobblin.restli.throttling"); bind(RestLiConfig.class).toInstance(restLiConfig); bind(SharedResourcesBroker.class).annotatedWith(Names.named(LimiterServerResource.BROKER_INJECT_NAME)).toInstance(topLevelBroker); MetricContext metricContext = topLevelBroker.getSharedResource(new MetricContextFactory<ThrottlingServerScopes>(), new MetricContextKey()); Timer timer = metricContext.timer(LimiterServerResource.REQUEST_TIMER_NAME); bind(MetricContext.class).annotatedWith(Names.named(LimiterServerResource.METRIC_CONTEXT_INJECT_NAME)).toInstance(metricContext); bind(Timer.class).annotatedWith(Names.named(LimiterServerResource.REQUEST_TIMER_INJECT_NAME)).toInstance(timer); bind(new TypeLiteral<Optional<LeaderFinder<URIMetadata>>>() { }).annotatedWith(Names.named(LimiterServerResource.LEADER_FINDER_INJECT_NAME)).toInstance(leaderFinder); List<RestFilter> restFilters = new ArrayList<>(); restFilters.add(new ServerCompressionFilter(EncodingType.SNAPPY.getHttpName())); List<StreamFilter> streamFilters = new ArrayList<>(); streamFilters.add(new SimpleLoggingFilter()); FilterChain filterChain = FilterChains.create(restFilters, streamFilters); bind(FilterChain.class).toInstance(filterChain); } catch (NotConfiguredException nce) { throw new RuntimeException(nce); } } }, new ServletModule() {
_packages = packages; final RestLiConfig config = new RestLiConfig(); config.setDocumentationRequestHandler(new DefaultDocumentationRequestHandler()); config.setServerNodeUri(URI.create("/")); config.addResourcePackageNames(_packages);