2012-10-18 57 views
3

我已經配置了jetty以使用jetty maven運行我的web應用程序。 Jetty應該是一種輕量級的開發替代品,因此它不需要web.xml中的所有東西。更具體地說,我想在web.xml中刪除一個過濾器。在jetty的web.xml中刪除過濾器

我試圖使用overrideDescriptor配置屬性,但這隻允許我重寫web.xml,而不是替換它。因此,過濾器仍然存在。

任何想法如何在不修改原始web.xml文件的情況下移除過濾器?

回答

0

由於沒有答案,我會發布我的解決方案,這是不完美的。

<!-- 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文件並刪除一個偵聽器。

0

的強大解決方案將是您的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

+1

千萬不要這麼做!您基本上正在使用特定於服務器的安全漏洞利用,這可能會在較新的服務器版本中修復,並且不一定存在於不同的服務器中。換句話說,具有這樣的web.xml的webapp是不可移植的。相關問題報告:https://bugzilla.redhat.com/show_bug.cgi?id = 1069911 – BalusC

0

你可以更換過濾器類的替代-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>