0

Using google guice and I'd like to have all server requests (/*) flow to my servlet file except static content. If needed, I'm good with placing static content into a /static folder. I just need to pick up servelet requests to the root.

Here is the code that works:

//Holds @GET @POST, etc
bind(MyTemplateResource1.class);
bind(MyTemplateResource2.class);

// this serves MyTemplateResource1..2... and any other servlet files
serve("/server/*").with(GuiceContainer.class); 

// this serves the static content
serveRegex("/(images|css|html)/.*").with(GuiceContainer.class); 

However, if I take out /server my static content also gets routed to MyTemplateResource. e.g.:

serve("/*").with(GuiceContainer.class); 

What is the best way to allow all static content to flow freely while routing Servlet content to one or more Resource files even when the servlet url can start from the root?

JStark
  • 2,788
  • 2
  • 29
  • 37

1 Answers1

0

I've had a similar problem (I was actually googling for a regex mask and found your question), so basically:

  1. Create a Map for Parameters
  2. Add a reference for WebPageContentRegex, and add the static file regexps
  3. Make sure that you use filter instead of serve, and pass the map

In code, it works as such:

    bind(HostController.class, LoginController.class, ConfirmInviteController.class, LogoutController.class, ResetPasswordController.class, ChangePasswordController.class);

    Map<String, String> initParams = new TreeMap<String, String>();

    initParams.put("com.sun.jersey.config.property.WebPageContentRegex", "/.*\\.(jpg|ico|png|gif|html|id|txt|css|js)");

    filter("/*").through(GuiceContainer.class, initParams);

Hope that helps

aldrinleal
  • 3,559
  • 26
  • 33