Apache Tapestry:如何将不推荐的URL重定向到错误页面

Apache Tapestry:如何将不推荐的URL重定向到错误页面,apache,web-applications,jboss,tapestry,Apache,Web Applications,Jboss,Tapestry,我使用apache Tapestry构建了遗留web应用程序。除少数页面外,我已经弃用了应用程序的大部分功能。我希望此应用程序在生产环境中运行,但我希望将不推荐使用的页面/URL重定向到某个错误页面,错误代码为404。我应该在哪里配置它?我有web.xml和jboss-web.xml。是否需要在某些Tapestry配置文件中执行此操作?您可以向RequestHandler服务提供RequestFilter,即在AppModule中: public void contributeRequestHa

我使用apache Tapestry构建了遗留web应用程序。除少数页面外,我已经弃用了应用程序的大部分功能。我希望此应用程序在生产环境中运行,但我希望将不推荐使用的页面/URL重定向到某个错误页面,错误代码为404。我应该在哪里配置它?我有web.xml和jboss-web.xml。是否需要在某些Tapestry配置文件中执行此操作?

您可以向RequestHandler服务提供RequestFilter,即在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:*");
}
public void contributeRequestHandler(
OrderedConfiguration(配置)
{
//对有序配置的每个贡献都有一个名称,
//必要时,可以设置约束以精确控制
//管道中已贡献筛选器的调用顺序。
add(“DeprecatedURLs”,newrequestfilter(){
@凌驾
公共布尔服务(请求,
回应,,
RequestHandler)抛出IOException
{
字符串路径=request.getPath();
如果(isDeprecated(路径))
{
响应。发送错误(404,“未找到”);
返回;
}
返回处理程序。服务(请求、响应);
}
},“之前:”;
}

请注意:排序约束之前的
,它应该将此过滤器注册为第一个进入。

我在该遗留应用程序代码中没有看到类似AppModule或RequestHandler的内容。我真的对tapestry一无所知。我只是在web.xml文件中看到TapestryFilter配置如下。ResourcesApp org.apache.tapestry5.TapestryFilter ResourcesApp/*它应该是
ResourcesAppModule
而不是
AppModule
,因为您的过滤器是name
ResourcesApp
。如果你不了解Tapestry,也不想在你的“传统”应用程序中学习一点这项任务,你可以在你的应用程序前面设置HTTP代理,如Apache或NGINX,并在那里处理那些不推荐的URL。对不起,忘了问一下,你有哪个Tapestry版本?