You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Markus Rathgeb <ma...@gmail.com> on 2019/04/18 09:36:14 UTC

Karaf, Pax Web, Jetty, GzipHandler (compression)

Hi,

I would like to use gzip compression for
* my servlets registered using the "registerServlet" method of "HttpService"
* for a handler that provides static content of a directory added by jetty.xml

The programmatic registered servlets are the most important ones.
Would be nice if there is one global option to configure the default
behavior and if it is still configurable per servlet.

For the static content I am currently using that part of the jetty.xml
===
  <Get name="handler">
    <Call name="addHandler">
      <Arg>
        <New class="org.eclipse.jetty.server.handler.ContextHandler">
          <Set name="contextPath">/foo/static</Set>
          <Set name="handler">
            <New class="org.eclipse.jetty.server.handler.ResourceHandler">
              <Set name="resourceBase"><SystemProperty
name="http.base.conf" />/html-foo</Set>
              <Set name="directoriesListed">false</Set>
            </New>
          </Set>
        </New>
      </Arg>
    </Call>
    <Call name="addHandler">
      <Arg>
        <New class="org.eclipse.jetty.servlet.ServletContextHandler">
          <Set name="contextPath">/bar/static</Set>
          <Set name="resourceBase"><SystemProperty
name="http.base.conf" />/html-bar</Set>
          <Call name="addServlet">
            <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
            <Arg>/</Arg>
            <Call name="setInitParameter">
              <Arg>dirAllowed</Arg>
              <Arg>false</Arg>
            </Call>
          </Call>
        </New>
      </Arg>
    </Call>
  </Get>
===

Can you give me some tips / information / solution?

Best regards,
Markus

Re: Karaf, Pax Web, Jetty, GzipHandler (compression)

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Markus,

it's what I thought as well.

Good it works.

Regards
JB

On 23/04/2019 08:44, Markus Rathgeb wrote:
> Solved for me!
> See:https://groups.google.com/d/topic/ops4j/U-uglsVkaMU/discussion
> 
> I edited the jetty.xml and it seems the gzip handler is used for every servlet.
> 

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: Karaf, Pax Web, Jetty, GzipHandler (compression)

Posted by Markus Rathgeb <ma...@gmail.com>.
Solved for me!
See:https://groups.google.com/d/topic/ops4j/U-uglsVkaMU/discussion

I edited the jetty.xml and it seems the gzip handler is used for every servlet.

Re: Karaf, Pax Web, Jetty, GzipHandler (compression)

Posted by Markus Rathgeb <ma...@gmail.com>.
I want to add the handler to a servlet that is registered programmatically.
Currently my servlet is a subclass of "javax.servlet.http.HttpServlet".
This class is registered by using "httpService.registerServlet(alias,
new MyServlet(args), null, null);" in the activation method of an OSGi
component.

Optionally I would also like to know how to configure it using
jetty.xml but this is not really important.


Am Do., 18. Apr. 2019 um 13:43 Uhr schrieb Jean-Baptiste Onofré
<jb...@nanthrax.net>:
>
> Yeah, I remember to have use it with previous Jetty version.
>
> If I understand correct, you want to add the handler programmatically ?
> not via the jetty.xml right ?
>
> Regards
> JB
>
> On 18/04/2019 13:38, Markus Rathgeb wrote:
> > The GzipFilter is deprecated for Jetty >8 and does not contain any
> > logic anymore: https://github.com/eclipse/jetty.project/blob/jetty-9.4.x/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/GzipFilter.java
> >
> > Am Do., 18. Apr. 2019 um 13:33 Uhr schrieb Jean-Baptiste Onofré
> > <jb...@nanthrax.net>:
> >>
> >> Did you try to add the GzipFilter ?
> >>
> >> You can register the GzipFilter as a Filter service (using the http
> >> whiteboard pattern), providing mimeTypes and url-patterns as service
> >> properties.
> >>
> >> Regards
> >> JB
> >>
> >> On 18/04/2019 13:17, Markus Rathgeb wrote:
> >>> To be clear:
> >>> My whole setup is currently working WITHOUT the gzip compression (GzipHandler).
> >>> I just want to know what I need to do to add Jetty's GzipHandler to
> >>> programmatically registered servlets and to static content that is
> >>> currently already added by the jetty.xml.
> >>>
> >>> Am Do., 18. Apr. 2019 um 12:33 Uhr schrieb Jean-Baptiste Onofré
> >>> <jb...@nanthrax.net>:
> >>>>
> >>>> Hi Markus,
> >>>>
> >>>> Are you using jetty.xml in config property from org.ops4j.pax.web.cfg ?
> >>>> Else your configuration won't be loaded in the Karaf Jetty connector.
> >>>>
> >>>> Regards
> >>>> JB
> >>>>
> >>>> On 18/04/2019 11:36, Markus Rathgeb wrote:
> >>>>> Hi,
> >>>>>
> >>>>> I would like to use gzip compression for
> >>>>> * my servlets registered using the "registerServlet" method of "HttpService"
> >>>>> * for a handler that provides static content of a directory added by jetty.xml
> >>>>>
> >>>>> The programmatic registered servlets are the most important ones.
> >>>>> Would be nice if there is one global option to configure the default
> >>>>> behavior and if it is still configurable per servlet.
> >>>>>
> >>>>> For the static content I am currently using that part of the jetty.xml
> >>>>> ===
> >>>>>   <Get name="handler">
> >>>>>     <Call name="addHandler">
> >>>>>       <Arg>
> >>>>>         <New class="org.eclipse.jetty.server.handler.ContextHandler">
> >>>>>           <Set name="contextPath">/foo/static</Set>
> >>>>>           <Set name="handler">
> >>>>>             <New class="org.eclipse.jetty.server.handler.ResourceHandler">
> >>>>>               <Set name="resourceBase"><SystemProperty
> >>>>> name="http.base.conf" />/html-foo</Set>
> >>>>>               <Set name="directoriesListed">false</Set>
> >>>>>             </New>
> >>>>>           </Set>
> >>>>>         </New>
> >>>>>       </Arg>
> >>>>>     </Call>
> >>>>>     <Call name="addHandler">
> >>>>>       <Arg>
> >>>>>         <New class="org.eclipse.jetty.servlet.ServletContextHandler">
> >>>>>           <Set name="contextPath">/bar/static</Set>
> >>>>>           <Set name="resourceBase"><SystemProperty
> >>>>> name="http.base.conf" />/html-bar</Set>
> >>>>>           <Call name="addServlet">
> >>>>>             <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
> >>>>>             <Arg>/</Arg>
> >>>>>             <Call name="setInitParameter">
> >>>>>               <Arg>dirAllowed</Arg>
> >>>>>               <Arg>false</Arg>
> >>>>>             </Call>
> >>>>>           </Call>
> >>>>>         </New>
> >>>>>       </Arg>
> >>>>>     </Call>
> >>>>>   </Get>
> >>>>> ===
> >>>>>
> >>>>> Can you give me some tips / information / solution?
> >>>>>
> >>>>> Best regards,
> >>>>> Markus
> >>>>>
> >>>>
> >>>> --
> >>>> Jean-Baptiste Onofré
> >>>> jbonofre@apache.org
> >>>> http://blog.nanthrax.net
> >>>> Talend - http://www.talend.com
> >>
> >> --
> >> Jean-Baptiste Onofré
> >> jbonofre@apache.org
> >> http://blog.nanthrax.net
> >> Talend - http://www.talend.com
>
> --
> Jean-Baptiste Onofré
> jbonofre@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com

Re: Karaf, Pax Web, Jetty, GzipHandler (compression)

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Yeah, I remember to have use it with previous Jetty version.

If I understand correct, you want to add the handler programmatically ?
not via the jetty.xml right ?

Regards
JB

On 18/04/2019 13:38, Markus Rathgeb wrote:
> The GzipFilter is deprecated for Jetty >8 and does not contain any
> logic anymore: https://github.com/eclipse/jetty.project/blob/jetty-9.4.x/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/GzipFilter.java
> 
> Am Do., 18. Apr. 2019 um 13:33 Uhr schrieb Jean-Baptiste Onofré
> <jb...@nanthrax.net>:
>>
>> Did you try to add the GzipFilter ?
>>
>> You can register the GzipFilter as a Filter service (using the http
>> whiteboard pattern), providing mimeTypes and url-patterns as service
>> properties.
>>
>> Regards
>> JB
>>
>> On 18/04/2019 13:17, Markus Rathgeb wrote:
>>> To be clear:
>>> My whole setup is currently working WITHOUT the gzip compression (GzipHandler).
>>> I just want to know what I need to do to add Jetty's GzipHandler to
>>> programmatically registered servlets and to static content that is
>>> currently already added by the jetty.xml.
>>>
>>> Am Do., 18. Apr. 2019 um 12:33 Uhr schrieb Jean-Baptiste Onofré
>>> <jb...@nanthrax.net>:
>>>>
>>>> Hi Markus,
>>>>
>>>> Are you using jetty.xml in config property from org.ops4j.pax.web.cfg ?
>>>> Else your configuration won't be loaded in the Karaf Jetty connector.
>>>>
>>>> Regards
>>>> JB
>>>>
>>>> On 18/04/2019 11:36, Markus Rathgeb wrote:
>>>>> Hi,
>>>>>
>>>>> I would like to use gzip compression for
>>>>> * my servlets registered using the "registerServlet" method of "HttpService"
>>>>> * for a handler that provides static content of a directory added by jetty.xml
>>>>>
>>>>> The programmatic registered servlets are the most important ones.
>>>>> Would be nice if there is one global option to configure the default
>>>>> behavior and if it is still configurable per servlet.
>>>>>
>>>>> For the static content I am currently using that part of the jetty.xml
>>>>> ===
>>>>>   <Get name="handler">
>>>>>     <Call name="addHandler">
>>>>>       <Arg>
>>>>>         <New class="org.eclipse.jetty.server.handler.ContextHandler">
>>>>>           <Set name="contextPath">/foo/static</Set>
>>>>>           <Set name="handler">
>>>>>             <New class="org.eclipse.jetty.server.handler.ResourceHandler">
>>>>>               <Set name="resourceBase"><SystemProperty
>>>>> name="http.base.conf" />/html-foo</Set>
>>>>>               <Set name="directoriesListed">false</Set>
>>>>>             </New>
>>>>>           </Set>
>>>>>         </New>
>>>>>       </Arg>
>>>>>     </Call>
>>>>>     <Call name="addHandler">
>>>>>       <Arg>
>>>>>         <New class="org.eclipse.jetty.servlet.ServletContextHandler">
>>>>>           <Set name="contextPath">/bar/static</Set>
>>>>>           <Set name="resourceBase"><SystemProperty
>>>>> name="http.base.conf" />/html-bar</Set>
>>>>>           <Call name="addServlet">
>>>>>             <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
>>>>>             <Arg>/</Arg>
>>>>>             <Call name="setInitParameter">
>>>>>               <Arg>dirAllowed</Arg>
>>>>>               <Arg>false</Arg>
>>>>>             </Call>
>>>>>           </Call>
>>>>>         </New>
>>>>>       </Arg>
>>>>>     </Call>
>>>>>   </Get>
>>>>> ===
>>>>>
>>>>> Can you give me some tips / information / solution?
>>>>>
>>>>> Best regards,
>>>>> Markus
>>>>>
>>>>
>>>> --
>>>> Jean-Baptiste Onofré
>>>> jbonofre@apache.org
>>>> http://blog.nanthrax.net
>>>> Talend - http://www.talend.com
>>
>> --
>> Jean-Baptiste Onofré
>> jbonofre@apache.org
>> http://blog.nanthrax.net
>> Talend - http://www.talend.com

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: Karaf, Pax Web, Jetty, GzipHandler (compression)

Posted by Markus Rathgeb <ma...@gmail.com>.
The GzipFilter is deprecated for Jetty >8 and does not contain any
logic anymore: https://github.com/eclipse/jetty.project/blob/jetty-9.4.x/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/GzipFilter.java

Am Do., 18. Apr. 2019 um 13:33 Uhr schrieb Jean-Baptiste Onofré
<jb...@nanthrax.net>:
>
> Did you try to add the GzipFilter ?
>
> You can register the GzipFilter as a Filter service (using the http
> whiteboard pattern), providing mimeTypes and url-patterns as service
> properties.
>
> Regards
> JB
>
> On 18/04/2019 13:17, Markus Rathgeb wrote:
> > To be clear:
> > My whole setup is currently working WITHOUT the gzip compression (GzipHandler).
> > I just want to know what I need to do to add Jetty's GzipHandler to
> > programmatically registered servlets and to static content that is
> > currently already added by the jetty.xml.
> >
> > Am Do., 18. Apr. 2019 um 12:33 Uhr schrieb Jean-Baptiste Onofré
> > <jb...@nanthrax.net>:
> >>
> >> Hi Markus,
> >>
> >> Are you using jetty.xml in config property from org.ops4j.pax.web.cfg ?
> >> Else your configuration won't be loaded in the Karaf Jetty connector.
> >>
> >> Regards
> >> JB
> >>
> >> On 18/04/2019 11:36, Markus Rathgeb wrote:
> >>> Hi,
> >>>
> >>> I would like to use gzip compression for
> >>> * my servlets registered using the "registerServlet" method of "HttpService"
> >>> * for a handler that provides static content of a directory added by jetty.xml
> >>>
> >>> The programmatic registered servlets are the most important ones.
> >>> Would be nice if there is one global option to configure the default
> >>> behavior and if it is still configurable per servlet.
> >>>
> >>> For the static content I am currently using that part of the jetty.xml
> >>> ===
> >>>   <Get name="handler">
> >>>     <Call name="addHandler">
> >>>       <Arg>
> >>>         <New class="org.eclipse.jetty.server.handler.ContextHandler">
> >>>           <Set name="contextPath">/foo/static</Set>
> >>>           <Set name="handler">
> >>>             <New class="org.eclipse.jetty.server.handler.ResourceHandler">
> >>>               <Set name="resourceBase"><SystemProperty
> >>> name="http.base.conf" />/html-foo</Set>
> >>>               <Set name="directoriesListed">false</Set>
> >>>             </New>
> >>>           </Set>
> >>>         </New>
> >>>       </Arg>
> >>>     </Call>
> >>>     <Call name="addHandler">
> >>>       <Arg>
> >>>         <New class="org.eclipse.jetty.servlet.ServletContextHandler">
> >>>           <Set name="contextPath">/bar/static</Set>
> >>>           <Set name="resourceBase"><SystemProperty
> >>> name="http.base.conf" />/html-bar</Set>
> >>>           <Call name="addServlet">
> >>>             <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
> >>>             <Arg>/</Arg>
> >>>             <Call name="setInitParameter">
> >>>               <Arg>dirAllowed</Arg>
> >>>               <Arg>false</Arg>
> >>>             </Call>
> >>>           </Call>
> >>>         </New>
> >>>       </Arg>
> >>>     </Call>
> >>>   </Get>
> >>> ===
> >>>
> >>> Can you give me some tips / information / solution?
> >>>
> >>> Best regards,
> >>> Markus
> >>>
> >>
> >> --
> >> Jean-Baptiste Onofré
> >> jbonofre@apache.org
> >> http://blog.nanthrax.net
> >> Talend - http://www.talend.com
>
> --
> Jean-Baptiste Onofré
> jbonofre@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com

Re: Karaf, Pax Web, Jetty, GzipHandler (compression)

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Did you try to add the GzipFilter ?

You can register the GzipFilter as a Filter service (using the http
whiteboard pattern), providing mimeTypes and url-patterns as service
properties.

Regards
JB

On 18/04/2019 13:17, Markus Rathgeb wrote:
> To be clear:
> My whole setup is currently working WITHOUT the gzip compression (GzipHandler).
> I just want to know what I need to do to add Jetty's GzipHandler to
> programmatically registered servlets and to static content that is
> currently already added by the jetty.xml.
> 
> Am Do., 18. Apr. 2019 um 12:33 Uhr schrieb Jean-Baptiste Onofré
> <jb...@nanthrax.net>:
>>
>> Hi Markus,
>>
>> Are you using jetty.xml in config property from org.ops4j.pax.web.cfg ?
>> Else your configuration won't be loaded in the Karaf Jetty connector.
>>
>> Regards
>> JB
>>
>> On 18/04/2019 11:36, Markus Rathgeb wrote:
>>> Hi,
>>>
>>> I would like to use gzip compression for
>>> * my servlets registered using the "registerServlet" method of "HttpService"
>>> * for a handler that provides static content of a directory added by jetty.xml
>>>
>>> The programmatic registered servlets are the most important ones.
>>> Would be nice if there is one global option to configure the default
>>> behavior and if it is still configurable per servlet.
>>>
>>> For the static content I am currently using that part of the jetty.xml
>>> ===
>>>   <Get name="handler">
>>>     <Call name="addHandler">
>>>       <Arg>
>>>         <New class="org.eclipse.jetty.server.handler.ContextHandler">
>>>           <Set name="contextPath">/foo/static</Set>
>>>           <Set name="handler">
>>>             <New class="org.eclipse.jetty.server.handler.ResourceHandler">
>>>               <Set name="resourceBase"><SystemProperty
>>> name="http.base.conf" />/html-foo</Set>
>>>               <Set name="directoriesListed">false</Set>
>>>             </New>
>>>           </Set>
>>>         </New>
>>>       </Arg>
>>>     </Call>
>>>     <Call name="addHandler">
>>>       <Arg>
>>>         <New class="org.eclipse.jetty.servlet.ServletContextHandler">
>>>           <Set name="contextPath">/bar/static</Set>
>>>           <Set name="resourceBase"><SystemProperty
>>> name="http.base.conf" />/html-bar</Set>
>>>           <Call name="addServlet">
>>>             <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
>>>             <Arg>/</Arg>
>>>             <Call name="setInitParameter">
>>>               <Arg>dirAllowed</Arg>
>>>               <Arg>false</Arg>
>>>             </Call>
>>>           </Call>
>>>         </New>
>>>       </Arg>
>>>     </Call>
>>>   </Get>
>>> ===
>>>
>>> Can you give me some tips / information / solution?
>>>
>>> Best regards,
>>> Markus
>>>
>>
>> --
>> Jean-Baptiste Onofré
>> jbonofre@apache.org
>> http://blog.nanthrax.net
>> Talend - http://www.talend.com

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: Karaf, Pax Web, Jetty, GzipHandler (compression)

Posted by Markus Rathgeb <ma...@gmail.com>.
To be clear:
My whole setup is currently working WITHOUT the gzip compression (GzipHandler).
I just want to know what I need to do to add Jetty's GzipHandler to
programmatically registered servlets and to static content that is
currently already added by the jetty.xml.

Am Do., 18. Apr. 2019 um 12:33 Uhr schrieb Jean-Baptiste Onofré
<jb...@nanthrax.net>:
>
> Hi Markus,
>
> Are you using jetty.xml in config property from org.ops4j.pax.web.cfg ?
> Else your configuration won't be loaded in the Karaf Jetty connector.
>
> Regards
> JB
>
> On 18/04/2019 11:36, Markus Rathgeb wrote:
> > Hi,
> >
> > I would like to use gzip compression for
> > * my servlets registered using the "registerServlet" method of "HttpService"
> > * for a handler that provides static content of a directory added by jetty.xml
> >
> > The programmatic registered servlets are the most important ones.
> > Would be nice if there is one global option to configure the default
> > behavior and if it is still configurable per servlet.
> >
> > For the static content I am currently using that part of the jetty.xml
> > ===
> >   <Get name="handler">
> >     <Call name="addHandler">
> >       <Arg>
> >         <New class="org.eclipse.jetty.server.handler.ContextHandler">
> >           <Set name="contextPath">/foo/static</Set>
> >           <Set name="handler">
> >             <New class="org.eclipse.jetty.server.handler.ResourceHandler">
> >               <Set name="resourceBase"><SystemProperty
> > name="http.base.conf" />/html-foo</Set>
> >               <Set name="directoriesListed">false</Set>
> >             </New>
> >           </Set>
> >         </New>
> >       </Arg>
> >     </Call>
> >     <Call name="addHandler">
> >       <Arg>
> >         <New class="org.eclipse.jetty.servlet.ServletContextHandler">
> >           <Set name="contextPath">/bar/static</Set>
> >           <Set name="resourceBase"><SystemProperty
> > name="http.base.conf" />/html-bar</Set>
> >           <Call name="addServlet">
> >             <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
> >             <Arg>/</Arg>
> >             <Call name="setInitParameter">
> >               <Arg>dirAllowed</Arg>
> >               <Arg>false</Arg>
> >             </Call>
> >           </Call>
> >         </New>
> >       </Arg>
> >     </Call>
> >   </Get>
> > ===
> >
> > Can you give me some tips / information / solution?
> >
> > Best regards,
> > Markus
> >
>
> --
> Jean-Baptiste Onofré
> jbonofre@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com

Re: Karaf, Pax Web, Jetty, GzipHandler (compression)

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Markus,

Are you using jetty.xml in config property from org.ops4j.pax.web.cfg ?
Else your configuration won't be loaded in the Karaf Jetty connector.

Regards
JB

On 18/04/2019 11:36, Markus Rathgeb wrote:
> Hi,
> 
> I would like to use gzip compression for
> * my servlets registered using the "registerServlet" method of "HttpService"
> * for a handler that provides static content of a directory added by jetty.xml
> 
> The programmatic registered servlets are the most important ones.
> Would be nice if there is one global option to configure the default
> behavior and if it is still configurable per servlet.
> 
> For the static content I am currently using that part of the jetty.xml
> ===
>   <Get name="handler">
>     <Call name="addHandler">
>       <Arg>
>         <New class="org.eclipse.jetty.server.handler.ContextHandler">
>           <Set name="contextPath">/foo/static</Set>
>           <Set name="handler">
>             <New class="org.eclipse.jetty.server.handler.ResourceHandler">
>               <Set name="resourceBase"><SystemProperty
> name="http.base.conf" />/html-foo</Set>
>               <Set name="directoriesListed">false</Set>
>             </New>
>           </Set>
>         </New>
>       </Arg>
>     </Call>
>     <Call name="addHandler">
>       <Arg>
>         <New class="org.eclipse.jetty.servlet.ServletContextHandler">
>           <Set name="contextPath">/bar/static</Set>
>           <Set name="resourceBase"><SystemProperty
> name="http.base.conf" />/html-bar</Set>
>           <Call name="addServlet">
>             <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
>             <Arg>/</Arg>
>             <Call name="setInitParameter">
>               <Arg>dirAllowed</Arg>
>               <Arg>false</Arg>
>             </Call>
>           </Call>
>         </New>
>       </Arg>
>     </Call>
>   </Get>
> ===
> 
> Can you give me some tips / information / solution?
> 
> Best regards,
> Markus
> 

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com