java.lang.IllegalStateException: WRITER, after upgrading Jetty from 8.x to 9.3.21

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

java.lang.IllegalStateException: WRITER, after upgrading Jetty from 8.x to 9.3.21

Neehal
This post was updated on .
Hi,
I see the below exception when I try to load my application(https://domain/) in the browser.

java.lang.IllegalStateException: WRITER
        at
org.eclipse.jetty.server.Response.getOutputStream(Response.java:862)
[192:org.eclipse.jetty.server:9.3.21.v20170918]
        at
org.eclipse.jetty.rewrite.handler.RedirectRegexRule.apply(RedirectRegexRule.java:99)
[189:org.eclipse.jetty.rewrite:9.3.21.v20170918]
        at
org.eclipse.jetty.rewrite.handler.RegexRule.matchAndApply(RegexRule.java:75)
[189:org.eclipse.jetty.rewrite:9.3.21.v20170918]
        at
org.eclipse.jetty.rewrite.handler.RuleContainer.apply(RuleContainer.java:169)
[189:org.eclipse.jetty.rewrite:9.3.21.v20170918]
        at
org.eclipse.jetty.rewrite.handler.RuleContainer.matchAndApply(RuleContainer.java:149)
[189:org.eclipse.jetty.rewrite:9.3.21.v20170918]
        at
org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:330)
[189:org.eclipse.jetty.rewrite:9.3.21.v20170918]
        at
org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:104)
[216:org.ops4j.pax.web.pax-web-jetty:6.0.9]
        at
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
[192:org.eclipse.jetty.server:9.3.21.v20170918]
        at org.eclipse.jetty.server.Server.handle(Server.java:534)
[192:org.eclipse.jetty.server:9.3.21.v20170918]
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:333)
[192:org.eclipse.jetty.server:9.3.21.v20170918]
        at
org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
[192:org.eclipse.jetty.server:9.3.21.v20170918]
        at
org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:283)
[184:org.eclipse.jetty.io:9.3.21.v20170918]
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:108)
[184:org.eclipse.jetty.io:9.3.21.v20170918]
        at
org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:251)
[184:org.eclipse.jetty.io:9.3.21.v20170918]
        at
org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:283)
[184:org.eclipse.jetty.io:9.3.21.v20170918]
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:108)
[184:org.eclipse.jetty.io:9.3.21.v20170918]
        at
org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)
[184:org.eclipse.jetty.io:9.3.21.v20170918]
        at
org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303)
[195:org.eclipse.jetty.util:9.3.21.v20170918]
        at
org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148)
[195:org.eclipse.jetty.util:9.3.21.v20170918]
        at
org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136)
[195:org.eclipse.jetty.util:9.3.21.v20170918]
        at
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)
[195:org.eclipse.jetty.util:9.3.21.v20170918]
        at
org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589)
[195:org.eclipse.jetty.util:9.3.21.v20170918]
        at java.lang.Thread.run(Thread.java:748) [?:?]



I have my app deployed on a certain path 'https://domain/xyz'.
Now, I have a added a Rule to the RewriteHandler in my jetty.xml, as below: which redirects '/' to '/xyz'
<Call name="addRule">
        <Arg>
          <New class="org.eclipse.jetty.rewrite.handler.RedirectRegexRule">
            <Set name="regex">^/$</Set>
            <Set name="location">/xyz</Set>
          </New>
        </Arg>
      </Call> 

I see above exception when I try to hit https://domain/

I checked the class org.eclipse.jetty.rewrite.handler.RedirectRegexRule,
where the problem is reported at(line number 99).

85     @Override
86        protected String apply(String target, HttpServletRequest request,
HttpServletResponse response, Matcher matcher)
87                throws IOException
88        {
89            target=_location;
90            for (int g=1;g<=matcher.groupCount();g++)
91            {
92                String group = matcher.group(g);
93                target=target.replaceAll("\\$"+g,group);
94            }
95            
96            target = response.encodeRedirectURL(target);
97          
response.setHeader("Location",RedirectUtil.toRedirectURL(request,target));
98            response.setStatus(_statusCode);
99            response.getOutputStream().flush(); // no output / content
100          response.getOutputStream().close();
101          return target;
102      }

Jetty 8 didn't have this problem because it did the following in the 'apply'
method. It just redirected the response.

@Override
    protected String apply(String target, HttpServletRequest request,
HttpServletResponse response, Matcher matcher)
            throws IOException
    {
        target=_replacement;
        for (int g=1;g<=matcher.groupCount();g++)
        {
            String group = matcher.group(g);
            target=target.replaceAll("\\$"+g,group);
        }

        response.sendRedirect(response.encodeRedirectURL(target));
        return target;
    }


I am using karaf 4.1.5 container with has jetty v9.3.21.

Is there something we could do to fix this one? or get around it?

Regards,
Neehal




--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html