Created
June 8, 2016 08:07
-
-
Save ensonic/f47946a07941545cda12336ff9509f35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 20249c9759a51280fa34df7c3c312859adcdd57e Mon Sep 17 00:00:00 2001 | |
From: Stefan Sauer <ensonic@users.sf.net> | |
Date: Tue, 7 Jun 2016 16:14:41 +0200 | |
Subject: [PATCH] Server: add gzip support | |
Add a gzip handler for the static resources. | |
--- | |
OpenRobertaParent/pom.xml | 29 +++++++++++++--------- | |
OpenRobertaServer/pom.xml | 10 +++++--- | |
.../de/fhg/iais/roberta/main/ServerStarter.java | 22 +++++++++++++++- | |
3 files changed, 45 insertions(+), 16 deletions(-) | |
diff --git a/OpenRobertaParent/pom.xml b/OpenRobertaParent/pom.xml | |
index 14724d7..79f862e 100644 | |
--- a/OpenRobertaParent/pom.xml | |
+++ b/OpenRobertaParent/pom.xml | |
@@ -1,7 +1,7 @@ | |
<?xml version="1.0" encoding="utf-8"?> | |
-<!-- Copyright 2014, 2015 The Open Roberta project. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Licensed | |
- under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | |
- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS | |
+<!-- Copyright 2014, 2015 The Open Roberta project. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Licensed | |
+ under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | |
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS | |
OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
@@ -28,7 +28,7 @@ | |
<!-- the server and the crosscompiler SHOULD be compatible between(including) the following two versions of software deployed on the ROBOT --> | |
<validversionrange.From>1.4.0</validversionrange.From> | |
<validversionrange.To>2.0.0</validversionrange.To> | |
- | |
+ | |
<robot.menutype>custom</robot.menutype> | |
<browser.visibility>false</browser.visibility> | |
<!-- use the hsql protocol for a standalone database server as in jdbc:hsqldb:hsql://localhost/oradb | |
@@ -36,19 +36,19 @@ | |
the developer default is using the embedded version | |
the official version is using the standalone server (see the profile "deployofficialserver" above and the ora.sh script how to do that) --> | |
<hibernate.connection.url>jdbc:hsqldb:file:db/openroberta-db</hibernate.connection.url> | |
- | |
+ | |
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format> | |
<buildTimeStamp>${maven.build.timestamp}</buildTimeStamp> | |
- | |
+ | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | |
- | |
+ | |
<source.level>1.7</source.level> | |
<maven.compiler.target>1.7</maven.compiler.target> | |
<maven.compiler.source>1.7</maven.compiler.source> | |
- | |
+ | |
<maven.min-version>3.2.0</maven.min-version> | |
- | |
+ | |
<guice.verion>3.0</guice.verion> | |
<jersey.version>1.18.2</jersey.version> | |
<jetty.version>9.2.5.v20141112</jetty.version> | |
@@ -58,7 +58,7 @@ | |
<dbusjava.version>0.9.0-beta</dbusjava.version> | |
<jna.version>3.2.7</jna.version> | |
<ev3.websocket.version>1.3.0</ev3.websocket.version> | |
- | |
+ | |
<ev3embedded.version>2.0.0-SNAPSHOT</ev3embedded.version> | |
</properties> | |
@@ -106,7 +106,7 @@ | |
<artifactId>EV3Runtime</artifactId> | |
<version>${ev3embedded.version}</version> | |
</dependency> | |
- | |
+ | |
<dependency> | |
<groupId>de.fhg.iais.openroberta</groupId> | |
<artifactId>OpenRobertaServer</artifactId> | |
@@ -116,7 +116,7 @@ | |
<groupId>de.fhg.iais.openroberta</groupId> | |
<artifactId>OpenRobertaRobot</artifactId> | |
<version>${project.version}</version> | |
- </dependency> | |
+ </dependency> | |
<dependency> | |
<groupId>org.slf4j</groupId> | |
@@ -144,6 +144,11 @@ | |
<version>${jetty.version}</version> | |
</dependency> | |
<dependency> | |
+ <groupId>org.eclipse.jetty</groupId> | |
+ <artifactId>jetty-servlets</artifactId> | |
+ <version>${jetty.version}</version> | |
+ </dependency> | |
+ <dependency> | |
<groupId>org.eclipse.jetty.websocket</groupId> | |
<artifactId>websocket-server</artifactId> | |
<version>${jetty.version}</version> | |
diff --git a/OpenRobertaServer/pom.xml b/OpenRobertaServer/pom.xml | |
index f7dc2c5..ffa449f 100644 | |
--- a/OpenRobertaServer/pom.xml | |
+++ b/OpenRobertaServer/pom.xml | |
@@ -1,7 +1,7 @@ | |
<?xml version="1.0" encoding="utf-8"?> | |
-<!-- Copyright 2014, 2015 The Open Roberta project. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Licensed | |
- under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | |
- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS | |
+<!-- Copyright 2014, 2015 The Open Roberta project. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Licensed | |
+ under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | |
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS | |
OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
@@ -32,6 +32,10 @@ | |
<artifactId>jetty-servlet</artifactId> | |
</dependency> | |
<dependency> | |
+ <groupId>org.eclipse.jetty</groupId> | |
+ <artifactId>jetty-servlets</artifactId> | |
+ </dependency> | |
+ <dependency> | |
<groupId>org.eclipse.jetty.websocket</groupId> | |
<artifactId>websocket-server</artifactId> | |
</dependency> | |
diff --git a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/main/ServerStarter.java b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/main/ServerStarter.java | |
index 1aaad93..3ce95a0 100644 | |
--- a/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/main/ServerStarter.java | |
+++ b/OpenRobertaServer/src/main/java/de/fhg/iais/roberta/main/ServerStarter.java | |
@@ -1,6 +1,9 @@ | |
package de.fhg.iais.roberta.main; | |
import java.io.IOException; | |
+import java.util.Arrays; | |
+import java.util.HashSet; | |
+import java.util.Set; | |
import java.util.Properties; | |
import org.eclipse.jetty.server.Handler; | |
@@ -12,6 +15,7 @@ import org.eclipse.jetty.server.session.HashSessionManager; | |
import org.eclipse.jetty.server.session.SessionHandler; | |
import org.eclipse.jetty.servlet.DefaultServlet; | |
import org.eclipse.jetty.servlet.ServletContextHandler; | |
+import org.eclipse.jetty.servlets.gzip.GzipHandler; | |
import org.eclipse.jetty.websocket.servlet.WebSocketServlet; | |
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; | |
import org.slf4j.Logger; | |
@@ -46,6 +50,17 @@ import joptsimple.OptionSpec; | |
public class ServerStarter { | |
private static final Logger LOG = LoggerFactory.getLogger(ServerStarter.class); | |
+ private static final String[] GZIPABLE_MIME_TYPES_VALUES = new String[] { | |
+ "application/javascript", | |
+ "image/svg+xml", | |
+ "text/css", | |
+ "text/html", | |
+ "text/javascript", | |
+ "text/xml", | |
+ }; | |
+ private static final Set<String> GZIPABLE_MIME_TYPES = | |
+ new HashSet<String>(Arrays.asList(GZIPABLE_MIME_TYPES_VALUES)); | |
+ | |
private final Properties properties; | |
private Injector injector; | |
@@ -144,13 +159,18 @@ public class ServerStarter { | |
wsHandler.setContextPath("/ws"); | |
wsHandler.addServlet(WebSocketServiceServlet.class, "/*"); | |
+ // static files | |
ResourceHandler staticResourceHandler = new ResourceHandler(); | |
staticResourceHandler.setDirectoriesListed(true); | |
staticResourceHandler.setResourceBase("staticResources"); | |
+ GzipHandler gzipedStaticResourceHandler = new GzipHandler(); | |
+ gzipedStaticResourceHandler.setMimeTypes(GZIPABLE_MIME_TYPES); | |
+ gzipedStaticResourceHandler.setHandler(staticResourceHandler); | |
+ | |
HandlerList handlers = new HandlerList(); | |
handlers.setHandlers(new Handler[] { | |
- staticResourceHandler, | |
+ gzipedStaticResourceHandler, | |
versionedHttpHandler, | |
wsHandler, | |
deprecatedHttpHandler | |
-- | |
2.8.0.rc3.226.g39d4020 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment