diff options
author | Maros Marsalek <mmarsale@cisco.com> | 2016-10-12 13:06:42 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2016-10-13 07:16:38 +0000 |
commit | aac97df16e967ca97d5825218766787bdf1b627d (patch) | |
tree | 405bb0d270d66cd87ccfbf7cbb30a7aa08ff50da /infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/JettyServerProvider.java | |
parent | 51d14eec11a226a11beb607421ef7ff656a7be0c (diff) |
HONEYCOMB-168 Replace deprecated GZip filter with handler
Change-Id: Idb82d23d3e79289f356a875c3729c80bb53f2567
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/JettyServerProvider.java')
-rw-r--r-- | infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/JettyServerProvider.java | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/JettyServerProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/JettyServerProvider.java index 6d055bf81..bc5fe8bc3 100644 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/JettyServerProvider.java +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/JettyServerProvider.java @@ -26,14 +26,21 @@ import org.eclipse.jetty.security.ConstraintSecurityHandler; import org.eclipse.jetty.security.HashLoginService; import org.eclipse.jetty.security.authentication.BasicAuthenticator; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.gzip.GzipHandler; import org.eclipse.jetty.util.security.Constraint; import org.eclipse.jetty.util.security.Password; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.webapp.WebAppContext; -public final class JettyServerProvider extends ProviderTrait<Server> { +final class JettyServerProvider extends ProviderTrait<Server> { - public static final String REALM = "HCRealm"; + private static final String REALM = "HCRealm"; + // Mime types to be compressed when requested + private static final String[] GZIP_MIME_TYPES = {"application/xml", + "xml", + "application/yang.data+xml", + "application/json", + "application/yang.data+json"}; @Inject private HoneycombConfiguration cfg; @@ -42,7 +49,6 @@ public final class JettyServerProvider extends ProviderTrait<Server> { protected Server create() { Server server = new Server(new QueuedThreadPool(cfg.restPoolMaxSize.get(), cfg.restPoolMinSize.get())); - // Load Realm for basic auth HashLoginService service = new HashLoginService(REALM); // Reusing the name as role @@ -52,15 +58,18 @@ public final class JettyServerProvider extends ProviderTrait<Server> { final URL resource = getClass().getResource("/"); WebAppContext webapp = new WebAppContext(resource.getPath(), cfg.restconfRootPath.get()); - ConstraintSecurityHandler security = getBaseAuth(service, webapp); - server.setHandler(security); - + server.setHandler(getGzip(service, webapp)); return server; } - private ConstraintSecurityHandler getBaseAuth(HashLoginService service, WebAppContext webapp) { - ConstraintSecurityHandler security = new ConstraintSecurityHandler(); + private GzipHandler getGzip(final HashLoginService service, final WebAppContext webapp) { + final GzipHandler gzipHandler = new GzipHandler(); + gzipHandler.setIncludedMimeTypes(GZIP_MIME_TYPES); + gzipHandler.setHandler(getBaseAuth(service, webapp)); + return gzipHandler; + } + private ConstraintSecurityHandler getBaseAuth(HashLoginService service, WebAppContext webapp) { Constraint constraint = new Constraint(); constraint.setName("auth"); constraint.setAuthenticate(true); @@ -70,6 +79,7 @@ public final class JettyServerProvider extends ProviderTrait<Server> { mapping.setPathSpec("/*"); mapping.setConstraint(constraint); + ConstraintSecurityHandler security = new ConstraintSecurityHandler(); security.setConstraintMappings(Collections.singletonList(mapping)); security.setAuthenticator(new BasicAuthenticator()); security.setLoginService(service); |