users@jersey.java.net

Using ContainerResponseFilters

From: Marsh Eric <emarsh_at_mac.com>
Date: Wed, 22 Sep 2010 12:00:06 -0500

Hello,

I've spent a solid day on this problem and hope that someone can help me.

I'm working on a Netbeans web services project that uses Netbeans' "Create Restful Web Services" wizards. I don't want to change the generated files unless it is absolutely necessary to do so because the database is being modified often and consequently I often have to regenerate the files and don't want to lose work that had been done to them.

My project includes caching data downloaded from the iTunes store as per their instructions in the section of http://www.apple.com/itunesaffiliates/API/AffiliatesSearch2.1.pdf titled Cache Architecture. I'm trying to handle this by using a servlet filter before/after the Jersey web services and testing the response code after chain.dofilter(). If I get a 404 then I download the requested data from Apple and insert it into my database. At this point I would like to do a redirect/refresh/modify the response object/whatever so that I can return the new data to the client. I've pretty much hit a brick wall. At this point the response object has been marked as committed so I can't alter it do a redirect or anything else. I've tried using wrappers but it contains an internal CoyoteResponse that I can't get to and that's where it is marked as committed.

Doing some more reading I see that Jersey has it's own filters and from what I read evidently it's legal to modify the response after Jersey has returned it to the filter. It describes how to register a logging filter at https://jersey.dev.java.net/nonav/apidocs/1.0.3.1/jersey/com/sun/jersey/api/container/filter/LoggingFilter.html. This isn't all that helpful to me - I could really use some more complete examples on how to create and use the filters, especially as part of a Glassfish EE 6 web services project.

Are there any examples or tutorials available? Can anyone give me some tips or point me in the right direction on this one?

Thanks,

Eric