Google Guice on Google Appengine: Matching Worker _ah

I have a Google appengine / guice / wicket app. My problem is that due to the matching, I can no longer access the / _ah / admin page.

My servlet module says:

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

still, it was more or less expected that access to / _ah / admin would give 404.

The problem is that I did not find a workaround.

I tried different combinations of serveRegex (), but even

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

leads to problems because the Wicket dispatch URL is being violated. The application continues to repeat the Path (for example, / list becomes / list / list, etc.).

Any ideas?

+3
source share
4 answers

Spring/GAE, UrlRewriteFilter. , . , .

<!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>

+2

:

, GuiceFilter, , _ah/* , Guice . Guice /_ah/*, /_ah/warmup, /_ah/warmup .

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);
    }
}

web.xml :

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

com.google.inject.servlet.GuiceFilter

+5

, serveRegex

serveRegex("/(?!_ah).*").with( WicketServlet.class, getWicketServletParams() );
+3

I know this is a pretty old question with an anchor accepted, however the solution is more straight forward than rewriting the URL. In your Guice servlet module, you can pass the 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
source

Source: https://habr.com/ru/post/1745978/


All Articles