Hi Joakim,
I tried adding the MovedContextHandler to the server config as below:
<Get name="handler">
<Call name="addHandler">
<Arg>
<New class="org.eclipse.jetty.server.handler.MovedContextHandler">
<Set name="contextPath">/</Set>
<Set name="newContextURL">/xyz</Set>
<Set name="permanent">true</Set>
<Set name="discardPathInfo">false</Set>
<Set name="discardQuery">false</Set>
</New>
</Arg>
</Call>
</Get>
I see the context handler taking effect when I start the server.
Started o.e.j.s.h.MovedContextHandler@6216e9d3{/,null,AVAILABLE}
But I don’t see the context getting moved to ‘https://domain/xyz’ when I try to
hit ‘https://domain/’. I see a warning though.
Can't find the request for https://domain/'s Observer
Regards,
Neehal
From: [email protected] <[email protected]> On
Behalf Of Joakim Erdfelt
Sent: Wednesday, May 16, 2018 4:13 PM
To: JETTY user mailing list <[email protected]>
Subject: Re: [jetty-users] [Jetty 9.3.x] java.lang.IllegalStateException:
WRITER, when using RedirectRegexRule in jetty.xml
Have you considered MovedContextHandler instead?
https://www.eclipse.org/jetty/documentation/current/moved-context-handler.html
Joakim Erdfelt / [email protected]<mailto:[email protected]>
On Wed, May 16, 2018 at 5:03 AM, Neehal Shaikh
<[email protected]<mailto:[email protected]>> wrote:
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<http://org.eclipse.jetty.io>.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:283)
[184:org.eclipse.jetty.io:9.3.21.v20170918]
at
org.eclipse.jetty.io<http://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<http://org.eclipse.jetty.io>.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:283)
[184:org.eclipse.jetty.io:9.3.21.v20170918]
at
org.eclipse.jetty.io<http://org.eclipse.jetty.io>.FillInterest.fillable(FillInterest.java:108)
[184:org.eclipse.jetty.io:9.3.21.v20170918]
at
org.eclipse.jetty.io<http://org.eclipse.jetty.io>.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)
[184:org.eclipse.jetty.io:9<http://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(jetty
9.3.21),
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.x 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
_______________________________________________
jetty-users mailing list
[email protected]<mailto:[email protected]>
To change your delivery options, retrieve your password, or unsubscribe from
this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
_______________________________________________
jetty-users mailing list
[email protected]
To change your delivery options, retrieve your password, or unsubscribe from
this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users