Google Guice on Google Appengine: mapping with working _ah

后端 未结 4 946
孤独总比滥情好
孤独总比滥情好 2021-01-14 17:55

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:

<
相关标签:
4条回答
  • 2021-01-14 18:37

    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>
    

    0 讨论(0)
  • 2021-01-14 18:41

    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

    0 讨论(0)
  • 2021-01-14 18:45

    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 );
    
    0 讨论(0)
  • 2021-01-14 18:48

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

    serveRegex("/(?!_ah).*").with( WicketServlet.class, getWicketServletParams() );
    
    0 讨论(0)
提交回复
热议问题