Solved

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

Posted on 2004-10-31
725 Views
Last Modified: 2010-08-05
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.

0
Question by:maximkr
    10 Comments
     
    LVL 13

    Expert Comment

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

    java -Xms256m -Xmx512m
    0
     

    Author Comment

    by:maximkr
    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
     

    Author Comment

    by:maximkr
    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
     

    Author Comment

    by:maximkr
    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
     
    LVL 13

    Expert Comment

    by:petmagdy
    why r u using redirect, r u redirecting to a Web component outside ur Tomcat or jetty?

    please explain what do loginaction do
    0
     

    Author Comment

    by:maximkr
    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
     
    LVL 13

    Expert Comment

    by:petmagdy
    is this struts action, or normal servlet?
    0
     

    Author Comment

    by:maximkr
    Its JSP with
    <%
    at the begin and
    %>
    at the end.

    Please see code sample in the very first message
    0
     
    LVL 13

    Accepted Solution

    by:
    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
     

    Author Comment

    by:maximkr
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Suggested Solutions

    New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
    Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
    This video Micro Tutorial is the first in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles al…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    846 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now