Hi Please use last 9.4.26.v20200117 version as 9.2.x is not supported anymore. here you will find an example how to use GZIPHandler https://github.com/eclipse/jetty.project/blob/jetty-9.4.x/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ManyHandlers.java
On Wed, Feb 5, 2020 at 4:18 PM Visinescu, Daniel < [email protected]> wrote: > > > Dear all, > > > > I am using JETTY 9.2.24 Embedded with various handlers and tried multiple > options to enable GZIP compression. > > Can anybody help out in setting up GZIP ?Any feedback is appreciated since > the code below comes from Jetty 6 upgraded to 9.0.x and then latest > distribution > > > > The clients accepts the compression but the server does not provided it > > > > Kind Regards, > > Daniel > > > > *import *org.eclipse.jetty.deploy.App; > *import *org.eclipse.jetty.deploy.DeploymentManager; > *import *org.eclipse.jetty.deploy.providers.WebAppProvider; > *import *org.eclipse.jetty.server.*; > *import *org.eclipse.jetty.server.handler.ContextHandlerCollection; > *import *org.eclipse.jetty.server.handler.HandlerCollection; > *import *org.eclipse.jetty.util.resource.Resource; > *import *org.eclipse.jetty.util.ssl.SslContextFactory; > *import *org.eclipse.jetty.webapp.WebAppContext; > > *import *javax.servlet.ServletContext; > *import *java.io.File; > *import *java.io.IOException; > *import *java.net.URL; > *import *java.net.URLClassLoader; > > > *public class *TestServer { > > *private static *Server *mServer *= *null*; > > > > *public static final *String *AUTH_DIR *= *"auth/"*; > *public static final *String *WEBAPPS_DIR *= *"webapps/"*; > > > > */** * Starts the server */ **public static void *main(String[] > args) { > *new *TestServer(args); > } > > > > */** * * @param **args * > > *the command line options */ **public *TestServer(String[] args) { > > *try *{ > startWebServer(); > } *catch *(Exception e) { > System.*exit*(-1); > } > } > > > > > > */** * Starts the web server */ **private void *startWebServer() > *throws > *Exception { > > > > *// start the web server **mServer *= *new *Server(); > > String mWapPath = *"C:**\\**WAP"*; > > > > *// Make all WebContexts use the LST folder *File mLST = *new *File( > *"c:**\\**LST"*+ File.*separator *+ *"jetty"*); > *if *(!mLST.exists()) { > *try *{ > mLST.mkdir(); > } > *catch*(SecurityException ignored){ > > } > } > > *int *mPort =8080; > *int *mSecurePort = 8443; > *int *mRequestHeaderSize = 32768; > > *if *(mSecurePort <= 0) { > *throw new *IllegalArgumentException(*"Port number for HTTPS > connector is mandatory"*); > } > HttpConfiguration http_config = *null*; > *if *(mPort > 0) { > > *// HTTP Configuration *http_config = *new *HttpConfiguration(); > http_config.setSecureScheme(*"https"*); > http_config.setSecurePort(mSecurePort); > http_config.setOutputBufferSize(32768); > http_config.setRequestHeaderSize(mRequestHeaderSize); > > > *// HTTP connector *ServerConnector http = *new *ServerConnector( > *mServer*, *new *HttpConnectionFactory(http_config)); > http.setPort(mPort); > http.setIdleTimeout(30000); > *mServer*.addConnector(http); > } > > > *// SSL Context Factory for HTTPS (and SPDY) *String mKeyStorePath = > *"mypath"*; > SslContextFactory sslContextFactory = *new * > SslContextFactory.Server(); > sslContextFactory.setKeyStorePath(mKeyStorePath); > sslContextFactory.setKeyStorePassword(*"password"*); > sslContextFactory.setKeyManagerPassword(*"password"*); > > > > *// HTTPS Configuration *HttpConfiguration https_config = > (http_config == *null *? *new *HttpConfiguration() : *new * > HttpConfiguration(http_config)); > https_config.setRequestHeaderSize(mRequestHeaderSize); > https_config.setOutputBufferSize(32768); > https_config.addCustomizer(*new *SecureRequestCustomizer()); > > > > *// HTTPS connector *ServerConnector https = *new *ServerConnector( > *mServer*, > *new *SslConnectionFactory(sslContextFactory, *"http/1.1"*), > *new *HttpConnectionFactory(https_config)); > https.setPort(mSecurePort); > https.setIdleTimeout(500000); > *mServer*.addConnector(https); > > > WebAppContext mWapContext = *new *WebAppContext(); > mWapContext.setAttribute(ServletContext.*TEMPDIR*, mLST); > mWapContext.setContextPath(*"/"*); > mWapContext.setDisplayName(*"[Server]"*); > mWapContext.setConfigurationClasses(*new *String[]{ > *"org.eclipse.jetty.annotations.AnnotationConfiguration"*, > *"org.eclipse.jetty.webapp.WebXmlConfiguration"*}); > mWapContext.setLogUrlOnStart(*true*); > *try *{ > mWapContext.setBaseResource(Resource.*newResource*(mWapPath)); > } *catch *(IOException ignored) { > } > > > > *// Setup handlers *HandlerCollection mRootHandlers = *new * > HandlerCollection(); > > > *// Handling Context(s) *ContextHandlerCollection mAppCtxHndCol = *new > *ContextHandlerCollection(); > mAppCtxHndCol.setHandlers(*new *Handler[]{ mWapContext }); > mRootHandlers.addHandler(mAppCtxHndCol); > > > *// Install WebApp Provider *String mWebAppDir = mWapPath + > *WEBAPPS_DIR*; > WebAppProvider mAppProvider = *new *WebAppProvider(){ > @Override > *protected *App createApp(String filename){ > *return super*.createApp(filename); > } > > }; > mAppProvider.setMonitoredDirName(mWebAppDir); > > > */* The default descriptor is a web.xml format file that is applied to the > context * before the standard WEB-INF/web.xml. Defaults to > WebAppContext.WEB_DEFAULTS_XML */ *mAppProvider.setDefaultsDescriptor( > *null*); > > > > > > > > */* == Enable annotation processing. Servlet 3.0 API == * * The > 'web-app' element in the web.xml must contain * the attribute: > metadata-complete="false" * So that the .war will be scanned for @ > annotations for dependancy injection */ /* ScanInterval pause > between scans in seconds, or 0 for no scan after the initial scan.*/ * > mAppProvider.setScanInterval(0); > > */* For debug/testing */ *mAppProvider.setExtractWars(*true*); > > > > */* Classloader to use parent classes first, instead of bundeled ones. > non-default.. */ // mAppProvider.setParentLoaderPriority(true); /* > Setup Deployment manager */ *DeploymentManager mDeployMgr = *new * > DeploymentManager(); > mDeployMgr.addAppProvider(mAppProvider); > mDeployMgr.setContextAttribute(ServletContext.*TEMPDIR*, mLST); > mDeployMgr.setContexts(mAppCtxHndCol); > > > > > > > *// Set Classloader of Context to be sane (needed for JSTL) // JSP > requires a non-System classloader, this simply wraps the // embedded > System classloader in a way that makes it suitable // for JSP to use > *ClassLoader jspClassLoader = *new *URLClassLoader(*new *URL[0], > *this*.getClass().getClassLoader()); > mWapContext.setClassLoader(jspClassLoader); > > > *// Manually call JettyJasperInitializer on context startup * > mWapContext.addBean(*new *JspStarter(mWapContext)); > > > > */* Setup & Run server */ **mServer*.addBean(mDeployMgr); > *mServer*.setHandler(mRootHandlers); > > > *try *{ > *mServer*.start(); > *mServer*.join(); > } *catch *(Exception e) { > e.printStackTrace(); > } > > > } > > } > > > _______________________________________________ > jetty-users mailing list > [email protected] > To change your delivery options, retrieve your password, or unsubscribe > from this list, visit > https://www.eclipse.org/mailman/listinfo/jetty-users -- Olivier
_______________________________________________ jetty-users mailing list [email protected] To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users
