org.glassfish.jersey.message.GZipEncoder Java Examples
The following examples show how to use
org.glassfish.jersey.message.GZipEncoder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GatewayBinaryResponseFilterIntTest.java From jrestless with Apache License 2.0 | 6 votes |
private JerseyTest createJerseyTest(Boolean binaryCompressionOnly) { return new JerseyTest() { @Override protected Application configure() { ResourceConfig config = new ResourceConfig(); config.register(TestResource.class); config.register(EncodingFilter.class); config.register(GZipEncoder.class); config.register(GatewayBinaryResponseFilter.class); if (binaryCompressionOnly != null) { config.property(GatewayBinaryResponseFilter.BINARY_COMPRESSION_ONLY_PROPERTY, binaryCompressionOnly); } return config; } }; }
Example #2
Source File: HttpClientCommon.java From datacollector with Apache License 2.0 | 6 votes |
private void configureCompression(ClientBuilder clientBuilder) { if (jerseyClientConfig.httpCompression != null) { switch (jerseyClientConfig.httpCompression) { case SNAPPY: clientBuilder.register(SnappyEncoder.class); break; case GZIP: clientBuilder.register(GZipEncoder.class); break; case NONE: default: break; } clientBuilder.register(EncodingFilter.class); } }
Example #3
Source File: RestResourceConfig.java From frameworkAggregate with Apache License 2.0 | 5 votes |
public RestResourceConfig() { log.info("-----------------------------loading JERSEY2 restful---------------------------"); packages("com.framework.rest.service"); register(RestAuthRequestFilter.class); register(RestResponseFilter.class); register(LoggingFilter.class); register(JacksonFeature.class); register(DeflateEncoder.class); EncodingFilter.enableFor(this, GZipEncoder.class); }
Example #4
Source File: GatewayRequestObjectHandlerIntTest.java From jrestless with Apache License 2.0 | 5 votes |
private GatewayRequestObjectHandlerImpl createAndStartHandler(ResourceConfig config, TestService testService) { config.register(GatewayFeature.class); Binder binder = new InstanceBinder.Builder().addInstance(testService, TestService.class).build(); config.register(binder); config.register(TestResource.class); config.register(EncodingFilter.class); config.register(GZipEncoder.class); config.register(SomeCheckedAppExceptionMapper.class); config.register(SomeUncheckedAppExceptionMapper.class); config.register(GlobalExceptionMapper.class); GatewayRequestObjectHandlerImpl handler = new GatewayRequestObjectHandlerImpl(); handler.init(config); handler.start(); return handler; }
Example #5
Source File: RequestHandler.java From jrestless-examples with Apache License 2.0 | 5 votes |
public RequestHandler() { // configure the application with the resource init(new ResourceConfig() .register(GatewayFeature.class) .register(MultiPartFeature.class) .register(EncodingFilter.class) .register(GZipEncoder.class) .packages("com.jrestless.aws.examples")); start(); }
Example #6
Source File: CubeApplication.java From cubedb with GNU General Public License v3.0 | 5 votes |
protected static void registerStuff(ResourceConfig rConfig) { rConfig.register(AccessOriginFilter.class); /* * rConfig.register(ErrorMapper.class); * rConfig.register(PreFilter.class); * rConfig.register(PostFilter.class); */ rConfig.register(GenericExceptionMapper.class); rConfig.register(org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainerProvider.class); EncodingFilter.enableFor(rConfig, GZipEncoder.class); rConfig.register(JsonIteratorConverter.class); }
Example #7
Source File: JerseyRestApplication.java From micro-server with Apache License 2.0 | 5 votes |
public JerseyRestApplication(List<Object> allResources,List<String> packages, List<Class<?>> resources, Map<String, Object> serverProperties) { if (allResources != null) { for (Object next : allResources) { if(isSingleton(next)) register(next); else register(next.getClass()); } } register(EncodingFilter.class); //Server encoding filter class register(GZipEncoder.class); register(new AsyncBinder()); if (serverProperties.isEmpty()) { property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true); //http://stackoverflow.com/questions/25755773/bean-validation-400-errors-are-returning-default-error-page-html-instead-of-re property(ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, "true"); } else { for (Map.Entry<String, Object> entry : serverProperties.entrySet()) { property(entry.getKey(), entry.getValue()); } } packages.stream().forEach( e -> packages(e)); resources.stream().forEach( e -> register(e)); Optional.ofNullable(this.resourceConfigManager.get(ServerThreadLocalVariables.getContext().get())).ifPresent(e->e.accept(new JaxRsProvider<>(this))); }
Example #8
Source File: AbstractRestClient.java From hugegraph-common with Apache License 2.0 | 5 votes |
public AbstractRestClient(String url, ClientConfig config) { Client client = null; Object protocol = config.getProperty("protocol"); if (protocol != null && protocol.equals("https")) { client = wrapTrustConfig(url, config); } else { client = ClientBuilder.newClient(config); } this.client = client; this.client.register(GZipEncoder.class); this.target = this.client.target(url); this.pool = (PoolingHttpClientConnectionManager) config.getProperty( ApacheClientProperties.CONNECTION_MANAGER); if (this.pool != null) { this.cleanExecutor = ExecutorUtil.newScheduledThreadPool( "conn-clean-worker-%d"); Number idleTimeProp = (Number) config.getProperty("idleTime"); final long idleTime = idleTimeProp == null ? IDLE_TIME : idleTimeProp.longValue(); final long checkPeriod = idleTime / 2L; this.cleanExecutor.scheduleWithFixedDelay(() -> { PoolStats stats = this.pool.getTotalStats(); int using = stats.getLeased() + stats.getPending(); if (using > 0) { // Do clean only when all connections are idle return; } // Release connections when all clients are inactive this.pool.closeIdleConnections(idleTime, TimeUnit.MILLISECONDS); this.pool.closeExpiredConnections(); }, checkPeriod, checkPeriod, TimeUnit.MILLISECONDS); } }
Example #9
Source File: JerseyApplication.java From XBDD with Apache License 2.0 | 5 votes |
public JerseyApplication() { // Need to register all resources manually as spring fat jar doesn't like the resource scanning register(AdminUtils.class); register(Attachment.class); register(AutomationStatistics.class); register(BuildReOrdering.class); register(Environment.class); register(Favourites.class); register(Feature.class); register(MergeBuilds.class); register(Presence.class); register(PrintPDF.class); register(Recents.class); register(Report.class); register(Search.class); register(Stats.class); register(TagView.class); register(UploadAttachment.class); register(UserResource.class); EncodingFilter.enableFor(this, GZipEncoder.class); register(MultiPartFeature.class); property(ServerProperties.TRACING, TracingConfig.ON_DEMAND.name()); }
Example #10
Source File: RestDemoJaxRsApplication.java From demo-rest-jersey-spring with MIT License | 5 votes |
/** * Register JAX-RS application components. */ public RestDemoJaxRsApplication() { packages("org.codingpedia.demo.rest"); // // register application resources // register(PodcastsResource.class); // register(PodcastLegacyResource.class); // // // register filters // register(RequestContextFilter.class); // register(LoggingResponseFilter.class); // register(CORSResponseFilter.class); // // // register exception mappers // register(GenericExceptionMapper.class); // register(AppExceptionMapper.class); // register(CustomReasonPhraseExceptionMapper.class); // register(NotFoundExceptionMapper.class); // // // register features // register(JacksonFeature.class); register(EntityFilteringFeature.class); EncodingFilter.enableFor(this, GZipEncoder.class); // property(EntityFilteringFeature.ENTITY_FILTERING_SCOPE, new Annotation[] {PodcastDetailedView.Factory.get()}); }
Example #11
Source File: OpenTsdb.java From metrics-opentsdb with Apache License 2.0 | 5 votes |
private OpenTsdb(String baseURL, Integer connectionTimeout, Integer readTimeout, boolean gzipEnabled) { ClientBuilder builder = ClientBuilder.newBuilder() .register(JacksonFeature.class); if (gzipEnabled) { builder = builder.register(GZipEncoder.class) .register(EncodingFilter.class) .property(ClientProperties.USE_ENCODING, "gzip"); } final Client client = builder.build(); client.property(ClientProperties.CONNECT_TIMEOUT, connectionTimeout); client.property(ClientProperties.READ_TIMEOUT, readTimeout); this.apiResource = client.target(baseURL); }
Example #12
Source File: JerseyRestApplicationTest.java From micro-server with Apache License 2.0 | 4 votes |
@Test public void testGZipRegistration() { JerseyRestApplication app = new JerseyRestApplication(); assertTrue(app.isRegistered(GZipEncoder.class)); assertTrue(app.isRegistered(EncodingFilter.class)); }
Example #13
Source File: Openscoring.java From openscoring with GNU Affero General Public License v3.0 | 4 votes |
public Openscoring(){ Config config = ConfigFactory.load(); setConfig(config); Binder configBinder = new AbstractBinder(){ @Override public void configure(){ bind(config).to(Config.class).named("openscoring"); } }; register(configBinder); ModelRegistry modelRegistry = createModelRegistry(config); setModelRegistry(modelRegistry); Binder modelRegistryBinder = new AbstractBinder(){ @Override public void configure(){ bind(modelRegistry).to(ModelRegistry.class).named("openscoring"); } }; register(modelRegistryBinder); LoadingModelEvaluatorBuilder loadingModelEvaluatorBuilder = createLoadingModelEvaluatorBuilder(config); setLoadingModelEvaluatorBuilder(loadingModelEvaluatorBuilder); Binder loadingModelEvaluatorBuilderBinder = new AbstractBinder(){ @Override public void configure(){ bind(loadingModelEvaluatorBuilder).to(LoadingModelEvaluatorBuilder.class); } }; register(loadingModelEvaluatorBuilderBinder); Config applicationConfig = config.getConfig("application"); register(ModelResource.class); // Convert path variables to ModelRef objects register(loadClass(ModelRefConverterProvider.class, applicationConfig)); // PMML support register(loadClass(ModelProvider.class, applicationConfig)); // JSON support register(JacksonJsonProvider.class); register(ObjectMapperProvider.class); // CSV support register(loadClass(TableProvider.class, applicationConfig)); // Convert exceptions to JSON objects register(WebApplicationExceptionMapper.class); // Permit the HTTP POST method to be changed to HTTP PUT or DELETE methods register(HttpMethodOverrideFilter.class); // File upload support register(MultiPartFeature.class); // Security support register(RolesAllowedDynamicFeature.class); // GZip and Deflate encoding support register(EncodingFilter.class); register(GZipEncoder.class); register(DeflateEncoder.class); // Application identification register(ApplicationHeaderFilter.class); List<String> componentClassNames = applicationConfig.getStringList("componentClasses"); for(String componentClassName : componentClassNames){ Class<?> clazz = loadClass(Object.class, componentClassName); register(clazz); } }
Example #14
Source File: NiFiWebApiResourceConfig.java From nifi with Apache License 2.0 | 4 votes |
public NiFiWebApiResourceConfig(@Context ServletContext servletContext) { // get the application context to register the rest endpoints final ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext); // request support register(RedirectResourceFilter.class); register(MultiPartFeature.class); // jackson register(JacksonFeature.class); register(ObjectMapperResolver.class); // rest api register(ctx.getBean("flowResource")); register(ctx.getBean("resourceResource")); register(ctx.getBean("controllerResource")); register(ctx.getBean("siteToSiteResource")); register(ctx.getBean("dataTransferResource")); register(ctx.getBean("snippetResource")); register(ctx.getBean("templateResource")); register(ctx.getBean("controllerServiceResource")); register(ctx.getBean("reportingTaskResource")); register(ctx.getBean("processGroupResource")); register(ctx.getBean("processorResource")); register(ctx.getBean("connectionResource")); register(ctx.getBean("flowfileQueueResource")); register(ctx.getBean("remoteProcessGroupResource")); register(ctx.getBean("inputPortResource")); register(ctx.getBean("outputPortResource")); register(ctx.getBean("labelResource")); register(ctx.getBean("funnelResource")); register(ctx.getBean("provenanceResource")); register(ctx.getBean("provenanceEventResource")); register(ctx.getBean("countersResource")); register(ctx.getBean("systemDiagnosticsResource")); register(ctx.getBean("accessResource")); register(ctx.getBean("accessPolicyResource")); register(ctx.getBean("tenantsResource")); register(ctx.getBean("versionsResource")); register(ctx.getBean("parameterContextResource")); // exception mappers register(AccessDeniedExceptionMapper.class); register(AuthorizationAccessExceptionMapper.class); register(InvalidAuthenticationExceptionMapper.class); register(AuthenticationCredentialsNotFoundExceptionMapper.class); register(AdministrationExceptionMapper.class); register(ClusterExceptionMapper.class); register(IllegalArgumentExceptionMapper.class); register(IllegalClusterResourceRequestExceptionMapper.class); register(IllegalClusterStateExceptionMapper.class); register(IllegalNodeDeletionExceptionMapper.class); register(IllegalNodeDisconnectionExceptionMapper.class); register(IllegalNodeReconnectionExceptionMapper.class); register(IllegalStateExceptionMapper.class); register(InvalidRevisionExceptionMapper.class); register(JsonMappingExceptionMapper.class); register(JsonParseExceptionMapper.class); register(JsonContentConversionExceptionMapper.class); register(MutableRequestExceptionMapper.class); register(NiFiCoreExceptionMapper.class); register(NoConnectedNodesExceptionMapper.class); register(NoClusterCoordinatorExceptionMapper.class); register(NoResponseFromNodesExceptionMapper.class); register(NodeDisconnectionExceptionMapper.class); register(NodeReconnectionExceptionMapper.class); register(ResourceNotFoundExceptionMapper.class); register(NotFoundExceptionMapper.class); register(UnknownNodeExceptionMapper.class); register(ValidationExceptionMapper.class); register(WebApplicationExceptionMapper.class); register(ThrowableMapper.class); // gzip EncodingFilter.enableFor(this, GZipEncoder.class); }
Example #15
Source File: AggregatedMetricsFetcher.java From datacollector with Apache License 2.0 | 4 votes |
public MetricRegistryJson fetchLatestAggregatedMetrics( PipelineConfiguration pipelineConfiguration, RuleDefinitionsJson ruleDefJson, List<Stage.ConfigIssue> issues ) { // fetch last persisted metrics for the following counters, timers, meters and histograms MetricRegistryJson metricRegistryJson = buildMetricRegistryJson(pipelineConfiguration, ruleDefJson); client = ClientBuilder.newBuilder().build(); client.register(new CsrfProtectionFilter("CSRF")); client.register(GZipEncoder.class); target = client.target(targetUrl); Entity<MetricRegistryJson> metricRegistryJsonEntity = Entity.json(metricRegistryJson); String errorResponseMessage = null; int delaySecs = 1; int attempts = 0; // Wait for a few random seconds before starting the stopwatch int waitSeconds = new Random().nextInt(60); try { Thread.sleep(waitSeconds * 1000); } catch (InterruptedException e) { // No-op } while (attempts < retryAttempts || retryAttempts == -1) { if (attempts > 0) { delaySecs = delaySecs * 2; delaySecs = Math.min(delaySecs, 60); LOG.warn("DPM fetchLatestAggregatedMetrics attempt '{}', waiting for '{}' seconds before retrying ...", attempts, delaySecs); StatsUtil.sleep(delaySecs); } attempts++; Response response = null; try { response = target .queryParam("jobId", jobId) .queryParam("pipelineId", pipelineId) .queryParam("pipelineVersion", pipelineVersion) .request() .header(SSOConstants.X_REST_CALL, SSOConstants.SDC_COMPONENT_NAME) .header(SSOConstants.X_APP_AUTH_TOKEN, authToken.replaceAll("(\\r|\\n)", "")) .header(SSOConstants.X_APP_COMPONENT_ID, appComponentId) .post(metricRegistryJsonEntity); if (response.getStatus() == HttpURLConnection.HTTP_OK) { metricRegistryJson = response.readEntity(MetricRegistryJson.class); break; } else if (response.getStatus() == HttpURLConnection.HTTP_UNAVAILABLE) { errorResponseMessage = "Error requesting latest stats from time-series app: DPM unavailable"; LOG.warn(errorResponseMessage); metricRegistryJson = null; } else if (response.getStatus() == HttpURLConnection.HTTP_FORBIDDEN) { errorResponseMessage = response.readEntity(String.class); LOG.error(Utils.format(Errors.STATS_02.getMessage(), errorResponseMessage)); metricRegistryJson = null; break; } else { errorResponseMessage = response.readEntity(String.class); LOG.warn("Error requesting latest stats from time-series app, HTTP status '{}': {}", response.getStatus(), errorResponseMessage); metricRegistryJson = null; } } catch (Exception ex) { errorResponseMessage = ex.toString(); LOG.warn("Error requesting latest stats from time-series app : {}", ex.toString()); metricRegistryJson = null; } finally { if (response != null) { response.close(); } } } if (metricRegistryJson == null) { issues.add( context.createConfigIssue( Groups.STATS.getLabel(), "targetUrl", Errors.STATS_02, errorResponseMessage ) ); } return metricRegistryJson; }
Example #16
Source File: HttpClientCommon.java From datacollector with Apache License 2.0 | 4 votes |
private void configureCompression(ClientBuilder clientBuilder) { clientBuilder.register(GZipEncoder.class); clientBuilder.register(EncodingFilter.class); }
Example #17
Source File: ElasticConnectionPool.java From dremio-oss with Apache License 2.0 | 4 votes |
public void connect() throws IOException { final ClientConfig configuration = new ClientConfig(); configuration.property(ClientProperties.READ_TIMEOUT, readTimeoutMillis); final AWSCredentialsProvider awsCredentialsProvider = elasticsearchAuthentication.getAwsCredentialsProvider(); if (awsCredentialsProvider != null) { configuration.property(REGION_NAME, elasticsearchAuthentication.getRegionName()); configuration.register(ElasticsearchRequestClientFilter.class); configuration.register(new InjectableAWSCredentialsProvider(awsCredentialsProvider), InjectableAWSCredentialsProvider.class); } final ClientBuilder builder = ClientBuilder.newBuilder() .withConfig(configuration); switch(sslMode) { case UNSECURE: builder.sslContext(SSLHelper.newAllTrustingSSLContext("SSL")); // fall-through case VERIFY_CA: builder.hostnameVerifier(SSLHelper.newAllValidHostnameVerifier()); // fall-through case STRICT: break; case OFF: // no TLS/SSL configuration } client = builder.build(); client.register(GZipEncoder.class); client.register(DeflateEncoder.class); client.register(EncodingFilter.class); if (REQUEST_LOGGER.isDebugEnabled()) { java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger(REQUEST_LOGGER_NAME); client.register(new LoggingFeature( julLogger, Level.FINE, REQUEST_LOGGER.isTraceEnabled() ? LoggingFeature.Verbosity.PAYLOAD_TEXT : LoggingFeature.Verbosity.HEADERS_ONLY, 65536)); } final JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider(); provider.setMapper(ElasticMappingSet.MAPPER); // Disable other JSON providers. client.property( PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, client.getConfiguration().getRuntimeType()), JacksonJaxbJsonProvider.class.getSimpleName()); client.register(provider); HttpAuthenticationFeature httpAuthenticationFeature = elasticsearchAuthentication.getHttpAuthenticationFeature(); if (httpAuthenticationFeature != null) { client.register(httpAuthenticationFeature); } updateClients(); }
Example #18
Source File: BaseApiTest.java From hugegraph with Apache License 2.0 | 4 votes |
public RestClient(String url) { this.client = ClientBuilder.newClient(); this.client.register(EncodingFilter.class); this.client.register(GZipEncoder.class); this.target = this.client.target(url); }
Example #19
Source File: JaxRsApplication.java From podcastpedia-web with MIT License | 3 votes |
/** * Register JAX-RS application components. */ public JaxRsApplication() { packages("org.podcastpedia.web.api"); // register features EncodingFilter.enableFor(this, GZipEncoder.class); }