Problem with Jetty: java.lang.IllegalStateException: Commited and java.lang.IllegalStateException: Not EDITABLE exceptions under load

I have the following JSP code:
<%@ page buffer="128kb" errorPage="/jsp/Error.jsp" isThreadSafe="true"%>
...
<%
    response.setContentType("text/html; charset="+Config.getInstance().getEncoding());
    response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
    response.setHeader("Pragma","no-cache"); //HTTP 1.0
    response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
...
    String lastPath = request.getParameter("last_path");
    if (lastPath != null) {
        if(URLDecoder.decode(lastPath, "UTF-8").indexOf("TSFrame.jsp?ID=") != -1) {
            redirect(lastPath);
            return;
        } else if(URLDecoder.decode(lastPath, "UTF-8").indexOf("TSFrame.jsp") == -1){
            session.setAttribute("MAIN_FRAME_GO_TO", lastPath);
            redirect(request.getContextPath() + "/jsp/TSFrame.jsp");
            return;
        }        
    }
    redirect(request.getContextPath() + "/jsp/SwitchAction.jsp");

%>

Under low load all works fine, but under high load I got following exception:
java.lang.IllegalStateException: Commited
      at org.mortbay.http.HttpResponse.sendRedirect(HttpResponse.java:448)
      at
org.mortbay.jetty.servlet.ServletHttpResponse.sendRedirect(ServletHttp
Response.java:432)
      at jsp.login.LoginAction_jsp.redirect(LoginAction_jsp.java:43)
      at jsp.login.LoginAction_jsp._jspService(LoginAction_jsp.java:173)
      at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

Also I got the following under load:
16:49:26.234 WARN!! GET
/TrackStudio/jsp/task/subtasks/Subtasks.jsp?ID=651 HTTP/1.1
java.lang.IllegalStateException: Not EDITABLE
      at org.mortbay.http.HttpMessage.setVersion(HttpMessage.java:542)
      at
org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:913)
      at org.mortbay.http.HttpConnection.handle(HttpConnection.java:807)
      at
org.mortbay.http.SocketListener.handleConnection(SocketListener.java:2
18)

How this can happend ? Seems like we don't send any content before redirect and have enough buffer.

maximkrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

petmagdyCommented:
please try to increase the jetty Java memory process like this:

java -Xms256m -Xmx512m
0
maximkrAuthor Commented:
Don't help. I don't think that problem is the load itself, the bug occurs only on this page when several users login the same time. Just test it: 5 users login the same time and  4 of them got this exception. It have no chance to eat all memory/threads/etc

The second (Not EDITABLE) exception also occurs only on the specific page.
0
maximkrAuthor Commented:
Another strange exception under load:

java.lang.IllegalStateException: BAD is not EDITABLE
      at org.mortbay.http.HttpResponse.writeHeader(HttpResponse.java:248)
      at org.mortbay.http.BufferedOutputStream.writeHeader(BufferedOutputStream.java:105)
      at org.mortbay.http.HttpOutputStream.writeHeader(HttpOutputStream.java:420)
      at org.mortbay.http.HttpConnection.commit(HttpConnection.java:717)
      at org.mortbay.http.HttpConnection.outputNotify(HttpConnection.java:530)
      at org.mortbay.http.HttpOutputStream.notify(HttpOutputStream.java:556)
      at org.mortbay.http.HttpOutputStream.outputNotify(HttpOutputStream.java:541)
      at org.mortbay.http.BufferedOutputStream.flush(BufferedOutputStream.java:178)
      at org.mortbay.http.ChunkingOutputStream.flush(ChunkingOutputStream.java:67)
      at org.mortbay.http.HttpOutputStream.flush(HttpOutputStream.java:486)
      at org.mortbay.http.HttpResponse.commit(HttpResponse.java:489)
      at org.mortbay.http.HttpResponse.sendRedirect(HttpResponse.java:451)
      at org.mortbay.jetty.servlet.ServletHttpResponse.sendRedirect(ServletHttpResponse.java:432)
      at jsp.SwitchAction_jsp.redirect(SwitchAction_jsp.java:69)
      at jsp.SwitchAction_jsp._jspService(SwitchAction_jsp.java:213)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

maximkrAuthor Commented:
Just tried with Tomcat 4 - the same problems:

java.lang.IllegalStateException
        at org.apache.catalina.connector.HttpResponseFacade.sendRedirect(HttpResponseFacade.java:173)
        at org.apache.jsp.LoginAction$jsp.redirect(LoginAction$jsp.java:56)
        at org.apache.jsp.LoginAction$jsp._jspService(LoginAction$jsp.java:216)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
0
petmagdyCommented:
why r u using redirect, r u redirecting to a Web component outside ur Tomcat or jetty?

please explain what do loginaction do
0
maximkrAuthor Commented:
No, LoginAction just check that username/password is correct, update cookies (set new password to cookies) and redirect to page that actually show data. I found the following topic:
http://www.jguru.com/faq/view.jsp?EID=501393

It seems that we got this problem because we can't set cookie and redirect in the same servlet. But I don't understand how to handle this correctly - where we should set up cookies ?
0
petmagdyCommented:
is this struts action, or normal servlet?
0
maximkrAuthor Commented:
Its JSP with
<%
at the begin and
%>
at the end.

Please see code sample in the very first message
0
petmagdyCommented:
sorry i missed to look at the begining of the thread

first move the first 4 lines of:

   response.setContentType("text/html; charset="+Config.getInstance().getEncoding());
    response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
    response.setHeader("Pragma","no-cache"); //HTTP 1.0
    response.setDateHeader ("Expires", 0); //prevents caching at the proxy server

to the redirected jsps

second instead of sendRedirect use forward like this:

    getServletConfig().getServletContext().getRequestDispatcher("SwitchAction.jsp").forward(request,response);

the jsp provided is relative path, assuming that all ur jsp r in the same directory, please try this and tell me the result




0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
maximkrAuthor Commented:
Got some problems with paths (it can't find SwitchAction.jsp, will investigate tomorrow) and the following warning:

Invalid length: Content-Length=1304 written=1410 for http://localhost:8888/TrackStudio/jsp/login/LoginAction.jsp

Seems like some headers was sent before.

But I still have 2 major questions:
1) Why buffers don't work ? I expect that 128 k should be enough to store all headers before we finish page generation.
2) In LoginAction.jsp we also setup cookies. As I understand, I can't setup cookies in servlet that forward or redirect control. How we should to setup it ?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.