tinkerwell / jodd

Automatically exported from code.google.com/p/jodd
0 stars 0 forks source link

Madvoc and Lagarto issue under Jetty #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It seems that Madvoc and Lagarto do not work together when application is 
deployed under Jetty server.

I am getting the following error:
java.lang.IllegalStateException: STREAM
    at org.eclipse.jetty.server.Response.getWriter(Response.java:635)
    at jodd.lagarto.filter.LagartoServletFilter.doFilter(LagartoServletFilter.java:63)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1187)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:425)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:494)
    at org.eclipse.jetty.server.session.SessionHandler.handle(SessionHandler.java:182)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:933)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:362)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:867)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:113)
    at org.eclipse.jetty.server.Server.handle(Server.java:334)
    at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:559)
    at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:992)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:541)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:203)
    at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:406)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:462)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:436)
    at java.lang.Thread.run(Thread.java:662)

Can you help me to resolve this issue?

Madvoc alone works correctly.

Original issue reported on code.google.com by bandino....@gmail.com on 30 Mar 2012 at 1:38

GoogleCodeExporter commented 9 years ago
Thank you for letting us know!

I will check this asap; i suppose you are using the latest jodd and jetty?

Original comment by igor.spasic on 30 Mar 2012 at 3:18

GoogleCodeExporter commented 9 years ago
I was using Jetty 7.0.1 and JODD 3.3.2.

The problem seems to be because one filter is using response.getWriter() and 
another one is using  response.getOutputStream().

Original comment by bandino....@gmail.com on 30 Mar 2012 at 6:05

GoogleCodeExporter commented 9 years ago
Hi,

Do you have any progress on this issue? Any tips how to resolve this?

I have found a "workaround" (below), but it introduces some other issues: 
Set-Cookie header is not sent in the response (which is very serious since it 
is used for JSESSIONID), so it is not a fix, but might give you a clue what is 
the problem.

class jodd.lagarto.filter.SimpleLagartoServletFilter:

public void doFilter(ServletRequest servletRequest, ServletResponse 
servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        String actionPath = DispatcherUtil.getServletPath(request);

        if (acceptActionPath(request, actionPath) == false) {
            filterChain.doFilter(servletRequest, servletResponse);
            return;
        }

        // JETTY FIX: Without this the below fix will not work
        // However, this line makes issues with Set-Cookie header
        servletResponse.getOutputStream().flush();

        CharArrayResponseWrapper wrapper = new CharArrayResponseWrapper(response);
        filterChain.doFilter(servletRequest, wrapper);
        char[] content = wrapper.toCharArray();

        if ((content != null) && (content.length != 0)) {
            if (log.isDebugEnabled()) {
                log.debug("Lagarto is about to parse: " + actionPath);
            }
            try {
                content = parse(content, request);
            } catch (Exception ex) {
                log.error("Error parsing", ex);
                throw new ServletException(ex);
            }

            // JETTY FIX: Original lines code
            //Writer out = servletResponse.getWriter();
            //out.write(content);

            // JETTY FIX: Replaced code with the fix
            ServletOutputStream sout = servletResponse.getOutputStream();
            sout.write(new String(content).getBytes());
        }
    }

Original comment by bandino....@gmail.com on 1 Apr 2012 at 9:16

GoogleCodeExporter commented 9 years ago
thank you for the fix submission, will take a look!

sorry on slow response, was on a business trip :( btw, is there any reason for 
not using the latest jetty 7.6.x? maybe they fixed it inside ;)))

Original comment by igor.spasic on 1 Apr 2012 at 11:07

GoogleCodeExporter commented 9 years ago
I have just tried with the latest stable build 7.6.2.v20120308 and the issue 
still happens :( 

Original comment by bandino....@gmail.com on 2 Apr 2012 at 7:15

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Ok, I am trying to recreate the issue:) It's interesting: I've deployed jodd 
example application on Jetty (uphea; that uses all jodd frameworks) and the 
demo seems to works on jetty.

However, the sample application from jodd codebase fails with exact exception.

Thank you for your patience, working on it!

Original comment by igor.spasic on 2 Apr 2012 at 4:27

GoogleCodeExporter commented 9 years ago
Update: I've figured that if both Lagarto and Decora filters are enabled, then 
there is no exception. So now I will try not to use simple 
CharArrayResponseWrapper, but to use BufferResponseWrapper (from Decora).

Original comment by igor.spasic on 2 Apr 2012 at 9:12

GoogleCodeExporter commented 9 years ago
Ok, the fix is ready (i hope;), just need couple of minor things to clean and 
that's it;)

@bandino: please check the email, i want to send you a beta jars, so you can 
test it/have it sooner.

Original comment by igor.spasic on 3 Apr 2012 at 2:37

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r1044.

Original comment by igor.spasic on 4 Apr 2012 at 9:51