我正在使用一個websphere liberty profile webserver,我已經部署了幾個應用程序。 這些應用程序正在發送請求消息,我想創建一個servlet過濾器而不更改應用程序 因此我可以看到應用程序正在發送和接收的內容。另外我想添加新的請求標題。創建一個servlet-filter websphere liberty配置文件?
0
A
回答
3
您可以使用ServletContainerInitializer來註冊新的ServletFilters。增加了一個響應報頭的示例實現可能是這樣的:
public class SCI implements ServletContainerInitializer {
@Override
public void onStartup(Set<Class<?>> arg0, ServletContext arg1)
throws ServletException {
arg1.addFilter("myFilter", MyFilter.class).addMappingForUrlPatterns(null, false, "/*");
}
}
的MyFilter類是這樣的:
public static class MyFilter implements Filter {
@Override
public void destroy() { }
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
if (arg1 instanceof HttpServletResponse) {
((HttpServletResponse) arg1).addHeader("Test", "Test");
}
arg2.doFilter(arg0, arg1);
}
@Override
public void init(FilterConfig arg0) throws ServletException { }
}
然後,您需要此使用文件名爲META-INF註冊/服務/ ServletContainerInitializer應包含的Servlet容器初始化的完全限定類名稱,例如:
test.SCI
通常你在一個罐子裏我這些打包n中的應用程序,但因爲你不想更新應用程序,而不是你配置的服務器是這樣的:
<featureManager>
<feature>bells-1.0</feature>
</featureManager>
<library id="init">
<file name="path/to/jar"/>
</library>
<bell libraryRef="init"/>
的ServletContainerInitializer將被用於所有啓動Web應用程序允許您添加過濾器。請注意,這將針對所有已啓動的Web應用程序(包括集成到Liberty運行時的應用程序)調用,例如管理中心和REST連接器。
相關問題
- 1. WebSphere Liberty配置文件JAXBContext ClassCastException
- 2. Websphere Application Server Liberty 17.0.0.2 - 配置文件
- 3. WebSphere Liberty配置文件日誌
- 4. 在Websphere Liberty配置文件中啓用Gzip壓縮liberty配置文件
- 5. Websphere Liberty配置文件 - 事務Websphere MQ連接工廠
- 6. 使用多個websphere liberty配置文件服務器而不是單個websphere 8?
- 7. 在Websphere Liberty配置文件中使用bouncycastle
- 8. 如何在Bluemix上啓用verbosegc WebSphere Liberty配置文件
- 9. WebSphere Liberty配置文件:找不到上下文根
- 10. wasspmsclient不支持在websphere 8.5 liberty配置文件
- 11. 在WebSphere Liberty中配置env-entry值?
- 12. Websphere Liberty配置文件AdminCenter頁面未加載
- 13. WebSphere Liberty配置文件和Subversion源代碼管理
- 14. 替換爲websphere中的WSCallHelper.clearStatementCache(連接)Liberty配置文件
- 15. java.lang.NoClassDefFoundError:javax/validation/groups/Websphere Liberty配置文件中的缺省值
- 16. Liberty配置文件配置問題(log4j2)
- 17. 如何在Websphere Liberty配置文件中啓用wmqJmsClient-1.1功能?
- 18. WebSphere Liberty配置文件連接器端口
- 19. 在Websphere Liberty中配置多個出站SSL設置?
- 20. liberty配置文件的默認安裝位置
- 21. 如何將安全角色映射到websphere Liberty配置文件中的ldap組
- 22. 如何在websphere liberty配置文件中設置絕對會話超時?
- 23. 在Websphere Liberty配置文件中使用ejb無狀態的CODI 8.5.5
- 24. 基於Tomcat配置的Worklight WAS Liberty配置文件配置
- 25. 無法在Websphere 6.中創建配置文件,RAD 7.5 Windows 7
- 26. 以編程方式配置WebSphere 8.5 Liberty Profile的方法?
- 27. Liberty配置文件服務器
- 28. websphere liberty配置文件 - 將數據庫連接錯誤添加到日誌中
- 29. 當我啓動websphere v8.5 liberty配置文件時出現跟隨錯誤
- 30. 新創建的Websphere配置文件在創建後未在RAD中顯示
這是我正在尋找,但對於一些reasen這是行不通的。 我是對的,我可以將類包裝在一個罐子裏? –
是的,您需要將類和META-INF打包到同一個jar文件中。上面的代碼在我們2月份的測試版上進行了測試,它確實有效。如果沒有日誌,很難知道爲什麼它不能正常工作,但要確保安裝了鈴聲-1.0功能。 – Alasdair
非常感謝。它現在正在工作,我的問題是maven沒有正確地打包META-INF目錄。 –