@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 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(); }
@Test(dataProvider = "headersData") public void testResponseCompressionRules(String acceptEncoding, int compressionThreshold, EncodingType expectedContentEncoding) throws CompressionException, URISyntaxException { ServerCompressionFilter serverCompressionFilter = new ServerCompressionFilter(ACCEPT_COMPRESSIONS); RequestContext context = new RequestContext(); context.putLocalAttr(HttpConstants.ACCEPT_ENCODING, acceptEncoding); context.putLocalAttr(HttpConstants.HEADER_RESPONSE_COMPRESSION_THRESHOLD, compressionThreshold); int originalLength = 100; byte[] entity = new byte[originalLength]; Arrays.fill(entity, (byte) 'A'); int compressedLength = (expectedContentEncoding == null) ? originalLength : expectedContentEncoding.getCompressor().deflate(new ByteArrayInputStream(entity)).length; String expectedContentEncodingName = (expectedContentEncoding == null) ? null : expectedContentEncoding.getHttpName(); RestResponse restResponse = new RestResponseBuilder().setEntity(entity).build(); serverCompressionFilter.onRestResponse(restResponse, context, Collections.<String, String>emptyMap(), new HeaderCaptureFilter(HttpConstants.CONTENT_ENCODING, expectedContentEncodingName, compressedLength)); } }
@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 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() {
@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 { // 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(); }
public static HttpServer createServer(final Engine engine, int port, String supportedCompression, boolean useAsyncServletApi, int asyncTimeOut) { final FilterChain fc = FilterChains.empty().addLastRest(new ServerCompressionFilter(supportedCompression, new CompressionConfig(0))) .addLastRest(new SimpleLoggingFilter()); return createServer(engine, port, useAsyncServletApi, asyncTimeOut, null, fc, true); }