我已经配置了jetty以使用jetty maven运行我的web应用程序。 Jetty应该是一种轻量级的开发替代品,因此它不需要web.xml中的所有东西。更具体地说,我想在web.xml中删除一个过滤器。在jetty的web.xml中删除过滤器
我试图使用overrideDescriptor配置属性,但这只允许我重写web.xml,而不是替换它。因此,过滤器仍然存在。
任何想法如何在不修改原始web.xml文件的情况下移除过滤器?
我已经配置了jetty以使用jetty maven运行我的web应用程序。 Jetty应该是一种轻量级的开发替代品,因此它不需要web.xml中的所有东西。更具体地说,我想在web.xml中删除一个过滤器。在jetty的web.xml中删除过滤器
我试图使用overrideDescriptor配置属性,但这只允许我重写web.xml,而不是替换它。因此,过滤器仍然存在。
任何想法如何在不修改原始web.xml文件的情况下移除过滤器?
由于没有答案,我会发布我的解决方案,这是不完美的。
<!-- Jetty configuration -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.5.v20120716</version>
<configuration>
<webApp>
<descriptor>src/main/webapp/mock-web.xml</descriptor>
[...]
</webApp>
[...]
</configuration>
</plugin>
这种方法的缺点是您必须维护两个几乎相同的web.xml文件。我还没有找到一个解决方案,允许我重写原始web.xml文件并删除一个侦听器。
的强大解决方案将是您的web.xml
使用2个XML实体:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document [
<!ENTITY webEntity1 SYSTEM 'webEntity1.xml'>
<!ENTITY webEntity2 SYSTEM 'webEntity2.xml'>
]>
<web-app>
&webEntity1;
&webEntity2;
</web-app>
而且在custom-web.xml
文件只是其中的1:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document [
<!ENTITY webEntity1 SYSTEM 'webEntity1.xml'>
]>
<web-app>
&webEntity1;
</web-app>
这样一来,在webEntity1.xml
你将宣布您的共享小服务程序,筛选器和映射,并在webEntity2.xml
中仅显示您不想在Jetty中使用的筛选器。
然后将配置码头插件这样的:
<configuration>
...
<webApp>
...
<descriptor>${project.basedir}/src/main/webapp/WEB-INF/custom-web.xml</descriptor>
</webApp>
...
</configuration>
我只是增加了一节我jetty plugin wiki page。
你可以更换过滤器类的替代-web.xml中PassThroughFilter:
public class PassThroughFilter implements Filter{
@Override
public void init(FilterConfig filterConfig) throws ServletException {}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
chain.doFilter(request, response);
}
@Override
public void destroy() {}
}
<filter>
<filter-name>OriginalFilter</filter-name>
<filter-class>mypackage.PassThroughFilter</filter-class>
</filter>
千万不要这么做!您基本上正在使用特定于服务器的安全漏洞利用,这可能会在较新的服务器版本中修复,并且不一定存在于不同的服务器中。换句话说,具有这样的web.xml的webapp是不可移植的。相关问题报告:https://bugzilla.redhat.com/show_bug.cgi?id = 1069911 – BalusC