Hello,
I have been reading these discussions :
http://jersey.576304.n2.nabble.com/Jersey-Guice-JSP-how-to-td5349718.html
http://jersey.576304.n2.nabble.com/WebPageContentRegex-and-Guice-integration-td3615214.html
So I have now two possibilities to serve static content and would like to know
the implications of each (or simply which one is best):
First I can simply use "filter" instead of "serve" as suggested in the first
discussion:
Map<String, String> params = new HashMap<String, String>();
params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "mypackage");
params.put(ServletContainer.PROPERTY_WEB_PAGE_CONTENT_REGEX, "/.*\\.(html|xsd)");
filter("/*").through(GuiceContainer.class, params);
All my tests pass but I am wondering what it means exactly to use "filter"
instead of "serve" ....
The second possiblity is to go on using "serve" following the second
discussion,
get the same bug as describe in the first link and then finding a workaround I
am not so sure about:
bind(StaticWrapperServlet.class);
serve("*.xsd", "*.html").with(StaticWrapperServlet.class);
Map<String, String> params = new HashMap<String, String>();
params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "mypackage");
serve("/*").through(GuiceContainer.class, params);
@Singleton
public class StaticWrapperServlet extends HttpServlet {
public void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
RequestDispatcher rd =
getServletContext().getNamedDispatcher("default");
HttpServletRequest wrapped = new HttpServletRequestWrapper(req) {
/**
* I really don't know why this is needed and working ....
*/
public String getPathInfo() {
return null;
}
};
rd.forward(wrapped, resp);
}
}
The workaround is to return null when I override "getPathInfo". Is this safe ?
Thanks for your help.
- Pierre