I次のコードを持っている:防止HeartbeatServlet nullポインタ例外がログに記録する書き込みから
HeartbeatServlet.java:
public final void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession(false);
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
if (session != null) {
compAjaxResponse ajaxResponse = new compAjaxResponse();
ajaxResponse.addAction(new JavascriptAction("sendNextBeat", "setTimeout(\"sendHeartBeat()\"," + MILLIS_PER_SECOND * HEARTBEAT_INTERVAL + ")", true));
if (CSGNotificationTracker.hasNotificationChanged()) {
ajaxResponse.addAction(new InnerHtmlAjaxAction("importantMessage", CSGNotificationTracker.getNotificationHtml()));
}
response.getWriter().write(ajaxResponse.getResponse(request));
}
return;
}
GZIPResponseWrapper.java:ユーザーはせずにブラウザを終了
public class GZIPResponseWrapper extends HttpServletResponseWrapper {
protected HttpServletResponse origResponse = null;
protected ServletOutputStream stream = null;
protected PrintWriter writer = null;
public GZIPResponseWrapper(HttpServletResponse response) {
super(response);
origResponse = response;
}
public ServletOutputStream createOutputStream() throws IOException {
return (new GZIPResponseStream(origResponse));
}
public void finishResponse() {
try {
if (writer != null) {
writer.close();
} else {
if (stream != null) {
stream.close();
}
}
} catch (IOException e) {}
}
public void flushBuffer() throws IOException {
stream.flush();
}
public ServletOutputStream getOutputStream() throws IOException {
if (writer != null) {
throw new IllegalStateException("getWriter() has already been
called!");
}
if (stream == null)
stream = createOutputStream();
return (stream);
}
public PrintWriter getWriter() throws IOException {
if (writer != null) {
return (writer);
}
if (stream != null) {
throw new IllegalStateException("getOutputStream() has already been
called!");
}
stream = createOutputStream();
writer = new PrintWriter(new OutputStreamWriter(stream, "UTF-8"));
return (writer);
}
public void setContentLength(int length) {}
}
ログアウトすると、複数のハートビートnullpointer例外がログに書き込まれます。
例外:
[7/14/17 9:20:46:326 EDT] 000001e8 webapp E
com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet
Error]-[compHeartbeatServlet]: java.lang.NullPointerException
2017-07-14 11:03:09.340 | at
com.csg.service.performance.gzip.GZIPResponseWrapper.flushBuffer
(GZIPResponseWrapper.java:39)
2017-07-14 11:03:09.340 | at
com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest
(ServletWrapper.java:816)
2017-07-14 11:03:09.340 | at
com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest
(ServletWrapper.java:480)
2017-07-14 11:03:09.340 | at
com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest
(ServletWrapperImpl.java:178)
2017-07-14 11:03:09.340 | at
com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget
(WebAppFilterChain.java:136)
2017-07-14 11:03:09.340 | at
com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter
(WebAppFilterChain.java:97)
2017-07-14 11:03:09.340 | at
com.comp.compservice.security.xss.XssFilter.doFilter(XssFilter.java:33)
2017-07-14 11:03:09.340 | at
com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter
(FilterInstanceWrapper.java:195)
2017-07-14 11:03:09.340 | at
com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter
(WebAppFilterChain.java:91)
2017-07-14 11:03:09.340 | at
com.csg.service.performance.gzip.GZIPFilter.doFilter(GZIPFilter.java:32)
2017-07-14 11:03:09.340 | at
com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter
(FilterInstanceWrapper.java:195)
2017-07-14 11:03:09.340 | at
com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter
(WebAppFilterChain.java:91)
2017-07-14 11:03:09.340 | at
com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter
(WebAppFilterManager.java:967)
2017-07-14 11:03:09.340 | at
com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters
(WebAppFilterManager.java:1107)
2017-07-14 11:03:09.340 | at
com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest
(CacheServletWrapper.java:87)
2017-07-14 11:03:09.340 | at
com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:940)
2017-07-14 11:03:09.340 | at
com.ibm.ws.webcontainer.WSWebContainer.handleRequest
(WSWebContainer.java:1817)
2017-07-14 11:03:09.340 | at
com.ibm.ws.webcontainer.channel.WCChannelLink.ready
(WCChannelLink.java:200)
2017-07-14 11:03:09.340 | at
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination
(HttpInboundLink.java:463)
2017-07-14 11:03:09.340 | at
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest
(HttpInboundLink.java:530)
2017-07-14 11:03:09.340 | at
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest
(HttpInboundLink.java:316)
2017-07-14 11:03:09.340 | at
com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete
(HttpICLReadCallback.java:88)
2017-07-14 11:03:09.340 | at
com.ibm.ws.ssl.channel.impl.SSLReadServiceContext
$SSLReadCompletedCallback.complete(SSLReadServiceContext.java:1820)
2017-07-14 11:03:09.340 | at
com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted
(AioReadCompletionListener.java:175)
2017-07-14 11:03:09.340 | at
com.ibm.io.async.AbstractAsyncFuture.invokeCallback
(AbstractAsyncFuture.java:217)
2017-07-14 11:03:09.340 | at
com.ibm.io.async.AsyncChannelFuture.fireCompletionActions
(AsyncChannelFuture.java:161)
2017-07-14 11:03:09.340 | at
com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
2017-07-14 11:03:09.340 | at
com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
2017-07-14 11:03:09.340 | at
com.ibm.io.async.ResultHandler.runEventProcessingLoop
(ResultHandler.java:775)
2017-07-14 11:03:09.340 | at
com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
2017-07-14 11:03:09.340 | at
com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1881)
我々がそれらを取得する場合、私は単にログファイルは、彼らがあるべきよりもはるかに大きいことを引き起こしているとして、それらがログに書き込まれたくない罰金です。私は立ち往生しているように見えるので、誰かが効率的な方法を持っていたのだろうかと思っていました。前もって感謝します。
編集: @jmehrensこのようなことを考えていますか?私jmehrens与えられた提案を使用して
public void flushBuffer() throws IOException {
if (stream != null) {
stream.flush();
}
}
他にもあるように、単に 'flushBuffer'にヌルチェックを追加しないのはなぜですか? – jmehrens
それはNPEを止めるはずですが、それは恐らく大きな問題の症状でしょう。 – jmehrens
しかし私はそれが私がhahaをするように言われていることに同意します。私が取り組んでいる他のいくつかのプロジェクトが終わると、私はそれをもっと見ていきます。これは機能しているように見えるので、私はその質問を閉じるつもりです。助けてくれてありがとう! –