简体   繁体   English

Tapestry:如何将不赞成使用的URL重定向到错误页面

[英]Tapestry: How to redirect deprecated URLs to an error page

I have legacy web application built using apache Tapestry. 我有使用apache Tapestry构建的旧版Web应用程序。 I have deprecated most of the application's functionality except few pages. 除少数页面外,我已弃用了大多数应用程序功能。 I want this application to be running in production, but I want to redirect deprecated pages/URLs to some error page with 404 error code. 我希望此应用程序可以在生产环境中运行,但是我想将已弃用的页面/ URL重定向到带有404错误代码的某些错误页面。 Where should I configure it? 我应该在哪里配置它? I have web.xml and jboss-web.xml. 我有web.xml和jboss-web.xml。 Do I need to do it in some Tapestry configuration file? 我是否需要在一些Tapestry配置文件中执行此操作?

You can contribute a RequestFilter to the RequestHandler service, ie in your AppModule: 您可以将RequestFilter贡献给RequestHandler服务,即在您的AppModule中:

public void contributeRequestHandler(
              OrderedConfiguration<RequestFilter> configuration)
{
    // Each contribution to an ordered configuration has a name,
    // When necessary, you may set constraints to precisely control
    // the invocation order of the contributed filter within the pipeline.

    configuration.add("DeprecatedURLs", new RequestFilter() {
        @Override
        public boolean service(Request request,
                               Response response,
                               RequestHandler handler) throws IOException
        {
            String path = request.getPath();
            if (isDeprecated(path))
            {
                response.sendError(404, "Not found");
                return;
            }

            return handler.service(request, response);
        }
    }, "before:*");
}

Notice the before:* ordering constraint, it should register this filter as the first in RequestHandler 's configuration . 请注意before:*排序约束,它应将此过滤器注册为RequestHandler的配置中的第一个过滤器。

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

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