Created
October 21, 2015 17:47
-
-
Save joakime/e5fc2a45abb6d3b79b18 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package jetty; | |
import java.io.File; | |
import org.eclipse.jetty.server.Server; | |
import org.eclipse.jetty.server.ServerConnector; | |
import org.eclipse.jetty.server.handler.ContextHandler; | |
import org.eclipse.jetty.server.handler.gzip.GzipHandler; | |
import org.eclipse.jetty.servlet.DefaultServlet; | |
import org.eclipse.jetty.servlet.ServletContextHandler; | |
import org.eclipse.jetty.util.resource.Resource; | |
public class GzipHandlerExample | |
{ | |
public static void main(String[] args) throws Exception | |
{ | |
Server server = new Server(); | |
ServerConnector connector = new ServerConnector(server); | |
connector.setPort(8080); | |
server.addConnector(connector); | |
GzipHandler gzip = new GzipHandler(); | |
gzip.setIncludedMethods("GET","POST"); | |
gzip.setMinGzipSize(245); | |
gzip.setIncludedMimeTypes("text/plain","text/css","text/html","text/javascript"); | |
server.setHandler(gzip); | |
ServletContextHandler context = new ServletContextHandler(); | |
context.setContextPath("/"); | |
context.setBaseResource(Resource.newResource(new File("/path/to/static/files/"))); | |
context.setWelcomeFiles(new String[] { "index.html" }); | |
context.addAliasCheck(new ContextHandler.ApproveAliases()); | |
context.addServlet(HelloServlet.class,"/hello/*"); | |
context.addServlet(DefaultServlet.class,"/"); // always last, always on "/" | |
gzip.setHandler(context); | |
server.start(); | |
server.join(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment