From aac97df16e967ca97d5825218766787bdf1b627d Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Wed, 12 Oct 2016 13:06:42 +0200 Subject: HONEYCOMB-168 Replace deprecated GZip filter with handler Change-Id: Idb82d23d3e79289f356a875c3729c80bb53f2567 Signed-off-by: Maros Marsalek --- .../distro/restconf/HttpConnectorProvider.java | 2 +- .../distro/restconf/HttpsConnectorProvider.java | 2 +- .../infra/distro/restconf/JettyServerProvider.java | 26 +++++++++++++++------- .../infra/distro/restconf/RestconfModule.java | 1 - .../infra/distro/restconf/RestconfProvider.java | 4 +--- 5 files changed, 21 insertions(+), 14 deletions(-) (limited to 'infra/minimal-distribution/src/main/java') diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpConnectorProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpConnectorProvider.java index e3c9577e7..f298df1d5 100644 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpConnectorProvider.java +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpConnectorProvider.java @@ -22,7 +22,7 @@ import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; -public final class HttpConnectorProvider extends ProviderTrait { +final class HttpConnectorProvider extends ProviderTrait { @Inject private HoneycombConfiguration cfg; diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpsConnectorProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpsConnectorProvider.java index 8dca157a6..68c0fb5ac 100644 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpsConnectorProvider.java +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/HttpsConnectorProvider.java @@ -27,7 +27,7 @@ import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.SslConnectionFactory; import org.eclipse.jetty.util.ssl.SslContextFactory; -public final class HttpsConnectorProvider extends ProviderTrait { +final class HttpsConnectorProvider extends ProviderTrait { @Inject private HoneycombConfiguration cfg; 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 { +final class JettyServerProvider extends ProviderTrait { - 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 { 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 { 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 { mapping.setPathSpec("/*"); mapping.setConstraint(constraint); + ConstraintSecurityHandler security = new ConstraintSecurityHandler(); security.setConstraintMappings(Collections.singletonList(mapping)); security.setAuthenticator(new BasicAuthenticator()); security.setLoginService(service); diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfModule.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfModule.java index 846ed1b03..7799d7fde 100644 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfModule.java +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfModule.java @@ -23,7 +23,6 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.opendaylight.netconf.sal.rest.api.RestConnector; - public class RestconfModule extends AbstractModule { public static final String RESTCONF_HTTP = "restconf-http"; diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfProvider.java index 16a33ecbb..94d508c99 100644 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfProvider.java +++ b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/restconf/RestconfProvider.java @@ -24,9 +24,7 @@ import org.opendaylight.netconf.sal.rest.api.RestConnector; import org.opendaylight.netconf.sal.restconf.impl.RestconfProviderImpl; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber; - - -public class RestconfProvider extends ProviderTrait { +final class RestconfProvider extends ProviderTrait { @Inject private HoneycombConfiguration cfg; -- cgit 1.2.3-korg