简体   繁体   English

使用web.xml重定向AppEngine域

[英]AppEngine domain redirect using web.xml

I want to intercept all incoming requests eg 我想拦截所有传入的请求,例如

http://subdomain.domain.org/path/to/resource

to

https://appengineid.appspot.com/path/to/resource

for any possible /path/to/resource 对于任何可能的/ path / to / resource

Is this possible with the app engine web.xml deployment descriptor? 应用引擎web.xml部署描述符是否可以实现? When I search this topic all the documentation or questions/answers relate to transforming/translating the /path/to/resource part of a request rather than the subdomain.domain.tld part? 当我搜索此主题时,所有文档或问题/答案都与转换/翻译请求的/ path / to / resource部分有关,而不是subdomain.domain.tld部分?

Thanks 谢谢

QUESTION EDIT/UPDATE: 问题编辑/更新:

Both of the above URLs point to the exact same instance of an app engine application. 以上两个URL都指向App Engine应用程序的完全相同的实例。 I don't want to URL pattern match on the /path/to/resource because this would "match" requests to both URLs. 我不想在/ path / to / resource上进行URL模式匹配,因为这会“匹配”对两个URL的请求。 I want to URL pattern match on the domain part of the URL, so that any requests to subdomain.domain.org are redirected to appengineid.appspot.com, and then, so that no cycle is encountered any requests to appengineid.appspot.com are ignored by the redirecting filter and are handled by the rest of the web deployment descriptor. 我想在URL的域部分上进行URL模式匹配,以便将对subdomain.domain.org的所有请求都重定向到appengineid.appspot.com,然后,这样就不会遇到对appengineid.appspot.com的任何请求的循环。重定向过滤器将忽略它们,并由其余的Web部署描述符处理。

It seems to be that a Filter will solve your problem. 看来,筛选器可以解决您的问题。 You create a new filter in your web.xml, like this: 您可以在web.xml中创建一个新的过滤器,如下所示:

     <filter> 
         <filter-name>yourFilterName</filter-name>
         <filter-class>com.acme.filter.YourNewFilter</filter-class> 
     </filter> 
     <filter-mapping> 
         <filter-name>yourFilterName</filter-name>
         <url-pattern>/path/to/resource/*</url-pattern> 
      </filter-mapping>

Your filter class will be something like this: 您的过滤器类将如下所示:

public class YourNewFilter extends MyGenericFilter implements Filter {

  public void doFilter(final ServletRequest request,
                       final ServletResponse response,
                       FilterChain chain)
       throws java.io.IOException, javax.servlet.ServletException  { 
      ServletContext context= getServletContext();
      req.getRequestURL().toString() // use this method to get the end of the URL
      RequestDispatcher rd= context.getRequestDispatcher("https://appengineid.appspot.com/path/to/resource/" + end of the URL
     );
      rd.forward(request, response);

  } 
} 

It is gonna intercept all requests in one domain and dispatch it to another. 它会拦截一个域中的所有请求,然后将其分发给另一个域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM