Problem in short:
- GET on
pictures/pic.png
should first be treated by Jersey, then by tomcat itself - Reasons:
- tomcat knows when to send
304 Not Modified
. (The response is client-specific) pic.png
might need an update. The update should happen when a call to the picture is made.
- tomcat knows when to send
Long explanation:
I have a picture on a given URL. The picture might need a referesh. I want to do the freshness-check at the time of the request. Therefore, I coded a jersey resource handling the request on the picture URL. It refreshes the picture on the filesystem if necessary. I do not want to re-code a caching mechansim, but rely on tomcat's implementation. Therefore, I would like to "forward" the request in the internal handler chain. I tried return new Viewable(sb.toString());
, but a viewable is not a picture. What return type can I use?
I could let the concrete picture reside on another URL and send a 307 (Temporary Redirect). Always sending that as answer seems odd to me.
Possibly, the solution having the update at the "GET" method is wrong by design. Possibly, the "PUT"/"POST" method should update the picture and GET should always be handled by tomcat.
Why is the question titled "How can I emulate forward on 404 in jersey?". The feature
com.sun.jersey.config.feature.FilterForwardOn404
does a similar thing: If the resource cannot be handled by jersey, it is forwarded through filter/servlet chain. I think, my problem is similar to that.
Related question: How to return a PNG image from Jersey REST service method to the browser