Hello I checked your scenario and indeed, you're right - it's not working. But why?
The problem is - if you DON'T add a "default" servlet mapped to "/", it's NOT org.eclipse.jetty.servlet.DefaultServlet that is added by pax-web-jetty (and only this org.eclipse.jetty.servlet.DefaultServlet handles this fancy "precompressed" option which seems reall y cool). It's org.ops4j.pax.web.service.jetty.internal.ResourceServlet that is added. Why? Because Jetty's default servlet serves "welcome files" Only after detecting that request URL "is a directory" - but it's not that easy to state this when running in OSGi. PaxWeb's jetty.internal.ResourceServlet has special "resource manager" that handles such cases (and properly delegates to "welcome files" when detecting "a directory"), but it doesn't handle "precompressed" init param. Even direct request to http://localhost:8181/war-bundle/index.html (which doesn't rely on welcome files) doesn't work, because Jetty's DefaultServlet's doesn't use proper org.eclipse.jetty.server.handler.ContextHandler#_baseResource "root directory" in this call: "qtp326128611-165@9223" prio=5 tid=0xa5 nid=NA runnable java.lang.Thread.State: RUNNABLE at org.eclipse.jetty.server.handler.*ContextHandler.getResource* (ContextHandler.java:1806) at org.eclipse.jetty.servlet.*DefaultServlet.getResource* (DefaultServlet.java:428) at org.eclipse.jetty.server.ResourceContentFactory.getContent(ResourceContentFactory.java:59) at org.eclipse.jetty.server.ResourceService.doGet(ResourceService.java:235) at org.eclipse.jetty.servlet.DefaultServlet.doGet(DefaultServlet.java:454) at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) ... You can check https://ops4j1.jira.com/browse/PAXWEB-1189 and see how I've configured GZIP compression at GzipHandler level. BTW, In Pax Web 8, I'm trying to better handle such cases related to redirects, "/" mapping, "default" servlets and unified resource management across Jetty/Undertow/Tomcat servers. regards Grzegorz Grzybek śr., 22 kwi 2020 o 10:45 Jakub Herkel <[email protected]> napisał(a): > I would like to ask if someone knows how to configure default servlet or > replace it? I use karaf 4.3.0 RC1 with PAX Web 7.2.14 (pax-http-jetty) > > We have angular app with very simple web.xml > > <welcome-file-list> > <welcome-file>index.html</welcome-file> > </welcome-file-list> > <display-name>chronos</display-name> > > It works but now we would like to add support for static compression (i.e > index.html also will have indext.html.br and index.html.gz). Jetty has a > support for this via "precompressed" init param. > But I don't know how to apply this init param for default servlet. I have > tried to replace default servlet in my web.xml: > > <servlet> > <servlet-name>test</servlet-name> > > <servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class> > <display-name>test</display-name> > <init-param> > <param-name>precompressed</param-name> > <param-value>br=.br,gzip=.gz</param-value> > </init-param> > <init-param> > <param-name>dirAllowed</param-name> > <param-value>false</param-value> > </init-param> > <load-on-startup>0</load-on-startup> > </servlet> > > <servlet-mapping> > <servlet-name>test</servlet-name> > <url-pattern>/</url-pattern> > </servlet-mapping> > > I can see my servlet via http-list command : > ID │ Servlet │ Servlet-Name │ State │ > Alias │ Url > ────┼─────────────────────┼────────────────────────────┼─────────────┼───────┼───────────────────────────────────────────────────────────────────────────── > > 147 │ CXFNonSpringServlet │ cxf-osgi-transport-servlet │ Deployed │ > /cxf │ [/cxf/*] > 329 │ ResourceServlet │ default │ Deployed │ > // │ [//] > 329 │ JspServletWrapper │ jsp │ Deployed > │ │ [//*.jsp, //*.jspx, //*.jspf, //*.xsp, //*.JSP, //*.JSPX, > //*.JSPF, //*.XSP] > 329 │ │ test │ Deployed > │ │ [//] > > but when I tried http://localhost:8181 I got > > URI: / > STATUS: 404 > MESSAGE: Not Found > SERVLET: test > Powered by Jetty:// 9.4.22.v20191022 > > I guess that there is something wrong with loading of resources. I also > tried set resourceBase to / but without success. Could anybody show me the > way how to set it up? > > best regards > > jakub > > -- > -- > ------------------ > OPS4J - http://www.ops4j.org - [email protected] > > --- > You received this message because you are subscribed to the Google Groups > "OPS4J" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ops4j/3ad2e518-f61c-4c74-af71-b66bce1bd2c5%40googlegroups.com > <https://groups.google.com/d/msgid/ops4j/3ad2e518-f61c-4c74-af71-b66bce1bd2c5%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- -- ------------------ OPS4J - http://www.ops4j.org - [email protected] --- You received this message because you are subscribed to the Google Groups "OPS4J" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/CAAdXmhpsaLnE7A7OXtzZ8f4EbQy4xTZyGac9FcRBewviPborRw%40mail.gmail.com.
