Gzip compression on Jetty

Is there any way to turn on gzip compression on the Jetty server built by the UberJar gradle task ?

All my failed attemps get a ClassNotFoundException

java.lang.ClassNotFoundException: org.eclipse.jetty.server.handler.gzip.GzipHandler
        at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_212]
        at java.lang.ClassLoader.loadClassHelper(Unknown Source) ~[na:1.8.0_212]
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_212]
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_212]
        at org.eclipse.jetty.util.Loader.loadClass(Loader.java:86) ~[app.jar:na]
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.nodeClass(XmlConfiguration.java:364) ~[app.jar:na]
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:754) ~[app.jar:na]
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.itemValue(XmlConfiguration.java:1125) ~[app.jar:na]
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.value(XmlConfiguration.java:1030) ~[app.jar:na]
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.set(XmlConfiguration.java:457) ~[app.jar:na]
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:411) ~[app.jar:na]
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:298) ~[app.jar:na]
        at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:248) ~[app.jar:na]
        at org.eclipse.jetty.plus.webapp.EnvConfiguration.configure(EnvConfiguration.java:124) ~[app.jar:na]
        at org.eclipse.jetty.webapp.WebAppContext.configure(WebAppContext.java:479) ~[app.jar:na]
        at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1337) ~[app.jar:na]
        at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741) ~[app.jar:na]
        at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:505) ~[app.jar:na]
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [app.jar:na]
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) [app.jar:na]
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114) [app.jar:na]
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61) [app.jar:na]
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [app.jar:na]
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) [app.jar:na]
        at org.eclipse.jetty.server.Server.start(Server.java:387) [app.jar:na]
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114) [app.jar:na]
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61) [app.jar:na]
        at org.eclipse.jetty.server.Server.doStart(Server.java:354) [app.jar:na]
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [app.jar:na]
        at com.haulmont.cuba.uberjar.CubaJettyServer.start(CubaJettyServer.java:121) [app.jar:na]
        at com.haulmont.cuba.uberjar.ServerRunner.execute(ServerRunner.java:249) [app.jar:na]
        at com.haulmont.cuba.uberjar.ServerRunner.main(ServerRunner.java:39) [app.jar:na]

Hi Alejandro,

Did you get any further with this? My approach also failed but not with a class not found exception, I put the following line in the buildUberJar task:

webJettyConfPath = 'modules/core/web/META-INF/jetty-test-web.xml'

And in that file:

    <Call name="insertHandler">
        <Arg>
            <New id="GzipHandler" class="org.eclipse.jetty.server.handler.gzip.GzipHandler">
                <Set name="minGzipSize"><Property name="jetty.gzip.minGzipSize" deprecated="gzip.minGzipSize" default="2048"/></Set>

                <Set name="checkGzExists"><Property name="jetty.gzip.checkGzExists" deprecated="gzip.checkGzExists" default="false"/></Set>

                <Set name="compressionLevel"><Property name="jetty.gzip.compressionLevel" deprecated="gzip.compressionLevel"
                                                       default="-1"/>
                </Set>
                <Set name="excludedAgentPatterns">
                    <Array type="String">
                        <Item><Property name="jetty.gzip.excludedUserAgent" deprecated="gzip.excludedUserAgent" default=".*MSIE.6\.0.*"/></Item>
                    </Array>
                </Set>

                <Set name="includedMethods">
                    <Array type="String">
                        <Item>GET</Item>
                        <Item>POST</Item>
                    </Array>
                </Set>
                <Set name="includedPaths">
                    <Array type="String">
                        <Item>/*</Item>
                    </Array>
                </Set>
            </New>
        </Arg>
    </Call>
</Configure>

The server starts up, but there is no web port open so am stuck at that point at the moment

Mark,

I will try with your configuration in the coming days and let you know the outcome.

Hi,

Unfortunately, now there is no possibility to define a custom handler for Jetty server in uberjar.
The issue was created: Add ability to specify custom Handler in Jetty configuration file · Issue #5 · cuba-platform/uberjar · GitHub

Regards,
Oleg.

Oleg,

Thanks for this clarification and creating the issue.

Alejandro

2 posts were split to a new topic: UberJar & CubaRestApiServlet not found