Skip to main content



      Home
Home » Eclipse Projects » Equinox » gzip compression
gzip compression [message #82893] Mon, 05 February 2007 16:50 Go to next message
Eclipse UserFriend
Originally posted by: s0347354.sms.ed.ac.uk

Hey all,

I am trying to apply GZIP compression to certain mime types downloaded
from Jetty (running in the osgi http service).

I normally do this by adding a filter to my web.xml file....
e.g.
<filter>
<filter-name>2WayFilter</filter-name>
<filter-class>com.osmoticweb.gzipfilter.GZIP2WayFilter</filter-class >
</filter>

<filter-mapping>
<filter-name>2WayFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


What could I add to the plugin.xml to achieve the same effect? If it is
not as simple as just adding something to the plugin.xml, can someone
give me an example of how to do this programatically?

Thanks very much!

Will
Re: gzip compression [message #83313 is a reply to message #82893] Wed, 14 February 2007 14:06 Go to previous messageGo to next message
Eclipse UserFriend
Hi Will,

The OSGi HttpService does not currently support Filters and subsequently
either does http.registry ... at least directly.

For the moment here's what I'd suggest...
Take a look in equinox-incubator/org.eclipse.equinox.helper as the
FilterServletAdaptor might help.
The FilterServletAdaptor let's you wrap another Servlet with a Filter so
that all requests to that servlet are filtered.
If you're filtering "resources" you'll need to mix it with the
ResourceServlet.
--
Here's a quick example using where I've modified the sample.http.Activator:
Filter filter = new Filter() {
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
System.out.println("Filtered");
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig) throws ServletException {
}
};
httpService.registerServlet("/helloworld.html", new
FilterServletAdaptor(filter, null, new ResourceServlet("/helloworld.html")),
null, null);
--
If you want to use the FilterServletAdaptor along with the http.registry
extensions you could wrap all the logic in a single Servlet and then
delegate
e.g. something like ...
public MyServlet() {
this.delegate = new FilterServletAdaptor(filter, null, new
ResourceServlet("/helloworld.html"));
} ... and then delegate the other methods

however I'd instead suggest creating an IExecutableExtensionFactory to
manufacture the Servlet.
--

In terms of mapping, the obvious difference is that the filter is applied
per resource/servlet instead of by context scoped URL. An implementation
"could" introduce native Filtering at the URL level and still achieve good
component isolation however that would require new API. That might be worth
a look post 3.3.

HTH
-Simon

"Will Ryan" <s0347354@sms.ed.ac.uk> wrote in message
news:eq88r8$nru$1@utils.eclipse.org...
> Hey all,
>
> I am trying to apply GZIP compression to certain mime types downloaded
> from Jetty (running in the osgi http service).
>
> I normally do this by adding a filter to my web.xml file....
> e.g.
> <filter>
> <filter-name>2WayFilter</filter-name>
> <filter-class>com.osmoticweb.gzipfilter.GZIP2WayFilter</filter-class >
> </filter>
>
> <filter-mapping>
> <filter-name>2WayFilter</filter-name>
> <url-pattern>/*</url-pattern>
> </filter-mapping>
>
>
> What could I add to the plugin.xml to achieve the same effect? If it is
> not as simple as just adding something to the plugin.xml, can someone give
> me an example of how to do this programatically?
>
> Thanks very much!
>
> Will
Re: gzip compression [message #83341 is a reply to message #83313] Thu, 15 February 2007 09:33 Go to previous message
Eclipse UserFriend
Originally posted by: s0347354.sms.ed.ac.uk

Cheers Simon for all your help. I'll give that a go.

Will

Simon Kaegi wrote:
> Hi Will,
>
> The OSGi HttpService does not currently support Filters and subsequently
> either does http.registry ... at least directly.
>
> For the moment here's what I'd suggest...
> Take a look in equinox-incubator/org.eclipse.equinox.helper as the
> FilterServletAdaptor might help.
> The FilterServletAdaptor let's you wrap another Servlet with a Filter so
> that all requests to that servlet are filtered.
> If you're filtering "resources" you'll need to mix it with the
> ResourceServlet.
> --
> Here's a quick example using where I've modified the sample.http.Activator:
> Filter filter = new Filter() {
> public void destroy() {
> }
> public void doFilter(ServletRequest request, ServletResponse response,
> FilterChain chain) throws IOException, ServletException {
> System.out.println("Filtered");
> chain.doFilter(request, response);
> }
> public void init(FilterConfig filterConfig) throws ServletException {
> }
> };
> httpService.registerServlet("/helloworld.html", new
> FilterServletAdaptor(filter, null, new ResourceServlet("/helloworld.html")),
> null, null);
> --
> If you want to use the FilterServletAdaptor along with the http.registry
> extensions you could wrap all the logic in a single Servlet and then
> delegate
> e.g. something like ...
> public MyServlet() {
> this.delegate = new FilterServletAdaptor(filter, null, new
> ResourceServlet("/helloworld.html"));
> } ... and then delegate the other methods
>
> however I'd instead suggest creating an IExecutableExtensionFactory to
> manufacture the Servlet.
> --
>
> In terms of mapping, the obvious difference is that the filter is applied
> per resource/servlet instead of by context scoped URL. An implementation
> "could" introduce native Filtering at the URL level and still achieve good
> component isolation however that would require new API. That might be worth
> a look post 3.3.
>
> HTH
> -Simon
>
> "Will Ryan" <s0347354@sms.ed.ac.uk> wrote in message
> news:eq88r8$nru$1@utils.eclipse.org...
>> Hey all,
>>
>> I am trying to apply GZIP compression to certain mime types downloaded
>> from Jetty (running in the osgi http service).
>>
>> I normally do this by adding a filter to my web.xml file....
>> e.g.
>> <filter>
>> <filter-name>2WayFilter</filter-name>
>> <filter-class>com.osmoticweb.gzipfilter.GZIP2WayFilter</filter-class >
>> </filter>
>>
>> <filter-mapping>
>> <filter-name>2WayFilter</filter-name>
>> <url-pattern>/*</url-pattern>
>> </filter-mapping>
>>
>>
>> What could I add to the plugin.xml to achieve the same effect? If it is
>> not as simple as just adding something to the plugin.xml, can someone give
>> me an example of how to do this programatically?
>>
>> Thanks very much!
>>
>> Will
>
>
Previous Topic:Problems by JSF/JSTL Examples ServerSide
Next Topic:coding to org.osgi.framework only...what will I lose versus org.eclipse.core.runtime?
Goto Forum:
  


Current Time: Sat Jul 26 19:55:16 EDT 2025

Powered by FUDForum. Page generated in 0.20359 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top