karouani / javasimon

Automatically exported from code.google.com/p/javasimon
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

web console servlet throws IllegalStateException WRITER/STREAM in jetty 9.x #124

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
in jetty 9.x, javasimon web-console servlet always throws IllegalStateException 
because it invoke HttpServletResponse's getOutputStream and getWriter method. 
and jetty only permit either STREAM(response.getOutputStream) or 
WRITER(response.getWriter) mode per request.
the stack trace:

2014-06-26 00:16:26.079:WARN:oejs.ServletHandler:qtp363988129-66: 
/profiler/resource/css/start/images/ui-bg_glass_75_79c9ec_1x400.png
java.lang.IllegalStateException: WRITER
    at org.eclipse.jetty.server.Response.getOutputStream(Response.java:930)
    at org.javasimon.console.ActionContext.getOutputStream(ActionContext.java:71)
    at org.javasimon.console.action.ResourceAction.copyStream(ResourceAction.java:89)
    at org.javasimon.console.action.ResourceAction.execute(ResourceAction.java:74)
    at org.javasimon.console.SimonConsoleRequestProcessor.processContext(SimonConsoleRequestProcessor.java:212)
    at org.javasimon.console.SimonConsoleRequestProcessor.processRequest(SimonConsoleRequestProcessor.java:189)
    at org.javasimon.console.SimonConsoleServlet.doGet(SimonConsoleServlet.java:84)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:751)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1666)
    at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:171)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1636)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1645)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:564)
....

What steps will reproduce the problem?
1.try demo spring-app with javasimon and deploy to jetty 9.x
2.producer some metrics value
3.view the chart in Simon console.

What is the expected output? What do you see instead?

do not throws any exception.

Original issue reported on code.google.com by bobw...@gmail.com on 25 Jun 2014 at 4:22

GoogleCodeExporter commented 8 years ago
2014-06-26 00:24:55.982:WARN:oejs.ServletHandler:qtp363988129-59: 
/profiler/resource/js/javasimon-customization.js
java.lang.IllegalStateException: STREAM
    at org.eclipse.jetty.server.Response.getWriter(Response.java:944)
    at org.javasimon.console.ActionContext.getWriter(ActionContext.java:76)
    at org.javasimon.console.action.ErrorAction.execute(ErrorAction.java:39)
    at org.javasimon.console.SimonConsoleRequestProcessor.processContext(SimonConsoleRequestProcessor.java:218)
    at org.javasimon.console.SimonConsoleRequestProcessor.processRequest(SimonConsoleRequestProcessor.java:189)
    at org.javasimon.console.SimonConsoleServlet.doGet(SimonConsoleServlet.java:84)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:751)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1666)
    at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:171)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1636)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1645)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:564)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:578)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1111)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:498)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1045)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:199)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:98)
    at org.eclipse.jetty.server.handler.StatisticsHandler.handle(StatisticsHandler.java:159)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:98)
    at org.eclipse.jetty.server.Server.handle(Server.java:461)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:284)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:244)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:534)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)

Original comment by bobw...@gmail.com on 25 Jun 2014 at 4:25

GoogleCodeExporter commented 8 years ago
i found when throws java.lang.IllegalStateException: STREAM. the OutputStream 
returned by response.getOutputStream() already closed.

Original comment by bobw...@gmail.com on 25 Jun 2014 at 4:26

GoogleCodeExporter commented 8 years ago
it was caused by ResourceAction that request "javasimon-customization.js". but 
the problem was if i don't create such file in package org,javasimon.xx , 
ResourceAction will throw an exception to SimonConsoleRequestProcessor. and the 
ErrorAction try to write error message by using HttpServletResponse.getWriter; 
but since ResourceAction already call HttpServletResponse.sendError(), so above 
exceptions was be thrown.

according to javadoc of HttpServletResponse.sendError():

    /**
     * Sends an error response to the client using the specified status
     * code and clears the buffer.
     * 
     * The server will preserve cookies and may clear or
     * update any headers needed to serve the error page as a valid response.
     *
     * If an error-page declaration has been made for the web application
     * corresponding to the status code passed in, it will be served back
     * the error page
     * 
     * <p>If the response has already been committed, this method throws 
     * an IllegalStateException.
     * After using this method, the response should be considered
     * to be committed and should not be written to.
     *
     * @param   sc  the error status code
     * @exception   IOException If an input or output exception occurs
     * @exception   IllegalStateException   If the response was committed
     *                      before this method call
     */
    public void sendError(int sc) throws IOException;

it should not write any error message to client after call this method.

Original comment by bobw...@gmail.com on 26 Jun 2014 at 2:59

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Two problems should be resolve:
1.provide better customization mechanism by lookup resource from external path 
rather get from classpath resource(org.javasimon.xx)
2.the call of HttpServletResponse.sendError() should be placed at ErrorAction.

Original comment by bobw...@gmail.com on 26 Jun 2014 at 3:10

GoogleCodeExporter commented 8 years ago
Hi bob, thank you for the report. I have to go through this code to find out 
more about it. From description I'd say that getting both writer and stream 
violates some servlet spec in generall, it just might have worked on some Jetty 
version before. If you feel like providing patch, it would be welcome.

Do the two problems from comment #5 directly relate to the first report?

Original comment by virgo47 on 26 Jun 2014 at 7:01

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
no, the comment #5 just a proposal to fix the problem.

Original comment by bobw...@gmail.com on 26 Jun 2014 at 7:06

GoogleCodeExporter commented 8 years ago
No concrete plans right now, closing it on this site due to move to GitHub.

Original comment by virgo47 on 29 Oct 2014 at 9:51