3

I have a Google Appengine/Guice/Wicket Application. My problem is that due to the mapping I can't access the /_ah/admin Page anymore.

My Servlet Module says:

serve( "/*" ).with( WicketServlet.class, getWicketServletParams() );

so far it is more or less expected that accessing /_ah/admin gives a 404.

I problem is that I don't find a workaround.

I tried different combinations of serveRegex(), but even

serveRegex( "/.*" ).with( WicketServlet.class, getWicketServletParams() );

leads to problems, as the URL dispatching of Wicket gets broken. The application keeps on repeating the Path (e.g. /list becomes /list/list etc.).

Any ideas?

Marcus
  • 8,601
  • 4
  • 24
  • 24

4 Answers4

5

I have found a more elegant solution :

Instead of using the GuiceFilter, subclass it to intercept _ah/* calls and let the servlet container do its regular job instead of letting Guice intercepting it. Here I prevent Guice from intercepting /_ah/* but /_ah/warmup because /_ah/warmup is supposed to be handled by the programmer.

package com.kya.guice.mvc;

import java.io.IOException;
import java.util.regex.Pattern;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import com.google.inject.servlet.GuiceFilter;

public class GaeSafeGuiceFilter extends GuiceFilter {

    private static final Pattern p = Pattern.compile("/_ah/.*");

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest)request;

        if (p.matcher(req.getRequestURI()).matches() && !req.getRequestURI().equals("/_ah/warmup")) {
            chain.doFilter(request, response);
            return ;
        }

        super.doFilter(request, response, chain);
    }
}

You then just have to change your web.xml with :

<filter>
    <filter-name>guiceFilter</filter-name>
    <filter-class>com.kya.guice.mvc.GaeSafeGuiceFilter</filter-class>
</filter>

instead of com.google.inject.servlet.GuiceFilter

Salomon BRYS
  • 9,247
  • 5
  • 29
  • 44
  • Thanks for your solution, I am trying to allow use of jsp file and a collect all servlet. I just add a condition to not filter with guicefilter when the url contains "*.jsp" – Patrice De Saint Steban Apr 30 '14 at 23:32
3

Just for reference, here is a way to do it with serveRegex

serveRegex("/(?!_ah).*").with( WicketServlet.class, getWicketServletParams() );
husayt
  • 14,553
  • 8
  • 53
  • 81
2

I solved the same problem with Spring/GAE using the UrlRewriteFilter. Please take a look at the source here. I assume a similar solution could be used for your situation.

<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.0//EN" "http://tuckey.org/res/dtds/urlrewrite3.0.dtd">
<urlrewrite>
    <rule>
        <from>^/appstats/(.*)$</from>
        <to last="true">/appstats/$1</to>
    </rule>
    <rule>
        <from>^/_ah/(.*)$</from>
        <to last="true">/_ah/$1</to>
    </rule>
    <rule>
        <from>^/(.*)$</from>
        <to last="true">/app/$1</to>
    </rule>

Taylor Leese
  • 51,004
  • 28
  • 112
  • 141
  • 1
    Well, I just took the _ah filter config, I guess that breaks the filter chain and makes the _ah work again. Thanks. – Marcus May 19 '10 at 14:42
0

I know this is is a pretty old question with an accepted anser, however the solution is more straight forward than URL rewriting. In your Guice servlet module you can pass configuration parameters as follows:


Map wicketParams = new HashMap(3);
wicketParams.put(WicketFilter.IGNORE_PATHS_PARAM, "/_ah/*");
wicketParams.put(WicketFilter.FILTER_MAPPING_PARAM, ROOT_FILTER_MAPPING_URL);
filter("/*").through(GuiceWicketFilter.class, wicketParams );
James A Wilson
  • 14,611
  • 5
  • 29
  • 31