在 MobileFirst Platform Foundation 应用程序的 websphere liberty 配置文件中禁用堆栈跟踪

disable stack trace in websphere liberty profile for MobileFirst Platform Foundation apps

当您从浏览器(例如 http://mywebserver.com/myApp/ThisIsaFileThatDoesNotExist)访问 Worklight 服务器上的无效 URL 时,堆栈跟踪会在您的浏览器上闪烁。

我们需要禁用堆栈跟踪(出于安全原因)。 我们的设置是 MobileFirst Platform Foundation 6.3 和 WebSphere Liberty Profile 8.5.5。

以下是浏览器中显示的消息。

"应用程序抛出异常class 'com.worklight.core.auth.impl.AuthenticationFilter.doFilter:272' java.lang.RuntimeException:java.io.FileNotFoundException:SRVE0190E:找不到文件:/ThisIsaFileThatDoesNotExist 在 com.worklight.core.auth.impl.AuthenticationFilter.doFilter(AuthenticationFilter.java:272) 在 com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:207) 在 [内部 classes] 原因:java.io.FileNotFoundException:SRVE0190E:找不到文件:/ThisIsaFileThatDoesNotExist 在 com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.handleRequest(DefaultExtensionProcessor.java:528) 在 [内部 classes] 在 com.worklight.core.auth.impl.AuthenticationFilter$1.execute(AuthenticationFilter.java:217) 在 com.worklight.core.auth.impl.AuthenticationServiceBean.accessResource(AuthenticationServiceBean.java:76) 在 com.worklight.core.auth.impl.AuthenticationFilter.doFilter(AuthenticationFilter.java:222) ... 还有 2 个

我们需要禁用显示堆栈跟踪,因为它被认为是一个问题。

您需要为 MobileFirst 运行时创建自定义 JSP 错误页面。您可以让自定义错误页面说出您想要说的任何内容。

为此,您需要拆开运行时 WAR(解压缩),并向部署描述符添加自定义错误页面。我使用 this page 作为如何创建自定义错误页面的示例。我将示例 "error.jsp" 文件放在 WAR 文件的根目录中(与 WEB-INF 和 META-INF 目录一起),并将其放在 WEB-INF/web.xml 文件,就在结束“/web-app”标签之前:

<error-page>
   <error-code>404</error-code>
   <location>/error.jsp</location>
</error-page>

然后我将文件压缩到修改后的 WAR 文件中,并用那个文件替换服务器上的 WAR 文件。完成此操作后,我启动了 MobileFirst Platform Server,并使用我定义的自定义错误页面(在 error.jsp 文件中)访问任何不存在的 URL,而不是默认错误页面。

可能有 other/better 方法来解决这个问题(特别是,最好将自定义错误页面文件重新定位到 WEB-INF/classes/conf 目录中,只是为了避免在WAR 文件的根目录),但这对我来说很好用。