Quantcast

Using ContainerResponseFilters

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Using ContainerResponseFilters

Marsh Eric
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



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using ContainerResponseFilters

Paul Sandoz-2
Hi,

Does the following help:

https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/container/filter/package-summary.html

?

Paul.

On Sep 22, 2010, at 10:00 AM, Marsh Eric wrote:

> 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
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using ContainerResponseFilters

Marsh Eric
Well, really not so much. I'd already found it and I'm not seeing where (in what file) to register the filters. Is that in web.xml? I went to the LoggingFilter java doc and tried to click through to the com.sun.jersey.api.container.filter link to try to learn more about the base class but the link is dead. At this point I don't understand how to associate the filter with a particular URL or even how to write the filter. Is it essentially a standard servlet filter? That's why I was hoping for a more in depth explanation.

On Sep 22, 2010, at 5:46 PM, Paul Sandoz wrote:

> Hi,
>
> Does the following help:
>
> https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/container/filter/package-summary.html
>
> ?
>
> Paul.
>
> On Sep 22, 2010, at 10:00 AM, Marsh Eric wrote:
>
>> 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
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using ContainerResponseFilters

Martin Matula-3

On Sep 23, 2010, at 1:15 AM, Marsh Eric wrote:

> Well, really not so much. I'd already found it and I'm not seeing  
> where (in what file) to register the filters. Is that in web.xml?

Yes.

> I went to the LoggingFilter java doc and tried to click through to  
> the com.sun.jersey.api.container.filter link to try to learn more  
> about the base class but the link is dead.

Weird - looks like a bug in the default javadoc doclet.

> At this point I don't understand how to associate the filter with a  
> particular URL or even how to write the filter. Is it essentially a  
> standard servlet filter?

ContainerResponseFilter is not a standard servlet filter.
ContainerResponseFilter is not associated with a URL - i.e. it gets  
called for each response and you need to do the URL matching yourself  
in the filter method to decide if the filter should do anything or not.
You can check this one out as an example:
https://jersey.dev.java.net/source/browse/jersey/trunk/jersey/contribs/jersey-oauth/oauth-server/src/main/java/com/sun/jersey/oauth/server/api/OAuthServerFilter.java?rev=4130&view=markup
Martin


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...