Search in sources :

Example 1 with SettingsService

use of com.khartec.waltz.service.settings.SettingsService in project waltz by khartec.

the class Main method enableGZIP.

private void enableGZIP() {
    SettingsService settingsService = ctx.getBean(SettingsService.class);
    Boolean gzipEnabled = settingsService.getValue(GZIP_ENABLED_NAME).map(x -> x.equalsIgnoreCase("true")).orElse(false);
    if (gzipEnabled) {
        // now fetch the minimum size
        int minimumLength = settingsService.getValue(GZIP_MIN_SIZE_NAME).map(Integer::parseInt).orElse(8192);
        after(((request, response) -> {
            if (response.body() != null && response.body().length() >= minimumLength) {
                response.header("Content-Encoding", "gzip");
            }
        }));
        LOG.info("Enabled GZIP (size: " + minimumLength + ")");
    } else {
        LOG.info("GZIP not enabled");
    }
}
Also used : Endpoint(com.khartec.waltz.web.endpoints.Endpoint) WebUtilities.reportException(com.khartec.waltz.web.WebUtilities.reportException) Logger(org.slf4j.Logger) StaticResourcesEndpoint(com.khartec.waltz.web.endpoints.api.StaticResourcesEndpoint) LoggerFactory(org.slf4j.LoggerFactory) BaseDataExtractor(com.khartec.waltz.web.endpoints.extracts.BaseDataExtractor) SettingsService(com.khartec.waltz.service.settings.SettingsService) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DuplicateKeyException(com.khartec.waltz.common.exception.DuplicateKeyException) LoggingUtilities(com.khartec.waltz.common.LoggingUtilities) DIConfiguration(com.khartec.waltz.service.DIConfiguration) InsufficientPrivelegeException(com.khartec.waltz.common.exception.InsufficientPrivelegeException) Request(spark.Request) Map(java.util.Map) Response(spark.Response) Spark(spark.Spark) SettingsService(com.khartec.waltz.service.settings.SettingsService) Endpoint(com.khartec.waltz.web.endpoints.Endpoint) StaticResourcesEndpoint(com.khartec.waltz.web.endpoints.api.StaticResourcesEndpoint)

Aggregations

LoggingUtilities (com.khartec.waltz.common.LoggingUtilities)1 DuplicateKeyException (com.khartec.waltz.common.exception.DuplicateKeyException)1 InsufficientPrivelegeException (com.khartec.waltz.common.exception.InsufficientPrivelegeException)1 DIConfiguration (com.khartec.waltz.service.DIConfiguration)1 SettingsService (com.khartec.waltz.service.settings.SettingsService)1 WebUtilities.reportException (com.khartec.waltz.web.WebUtilities.reportException)1 Endpoint (com.khartec.waltz.web.endpoints.Endpoint)1 StaticResourcesEndpoint (com.khartec.waltz.web.endpoints.api.StaticResourcesEndpoint)1 BaseDataExtractor (com.khartec.waltz.web.endpoints.extracts.BaseDataExtractor)1 Map (java.util.Map)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 Request (spark.Request)1 Response (spark.Response)1 Spark (spark.Spark)1