You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Daniel Soneira <da...@joyn-it.at> on 2011/12/14 15:20:16 UTC
Throwing RestartResponseException within RequestCycleListener [1.5
- incl. quickstart]
Hi there,
Throwing a RestartResponseException in a custom RequestCycleListener
does not yield the result I was hoping for.
Instead of redirecting to the specified page the DefaultExceptionMapper
only shows an Unexpected RuntimeException page.
The equivalent code (within a custom RequestCycle) used to work in 1.4.
Here's the log:
ERROR - DefaultExceptionMapper - Unexpected error occurred
org.apache.wicket.RestartResponseException
The listener tries do redirect the very FIRST request - so you have to
restart the jetty server when analyzing the problem.
Attached you'll find a quickstart that demonstrates the problem.
Note: The code is essentially the same as in WICKET-3248.
Any help on this matter is appreciated.
I can also create a JIRA issue if needed.
Kind regards,
Daniel Soneira
--
www.joyn-it.at
Re: Throwing RestartResponseException within RequestCycleListener
[1.5 - incl. quickstart]
Posted by Daniel Soneira <da...@joyn-it.at>.
OK, I've managed to get rid of all exceptions that were logged.
Here's the working code:
@Override
public void onBeginRequest(RequestCycle cycle) {
Session session = Session.get();
if (session.getMetaData(REDIRECTED_JSESSIONID) == null) {
logger.debug("first application request - redirecting to
loading page");
session.setMetaData(REDIRECTED_JSESSIONID, Boolean.TRUE);
String url = getServletRequestContextPath() + "/" +
cycle.getRequest().getUrl();
cycle.replaceAllRequestHandlers(new
RenderPageRequestHandler(new PageProvider(newLoadingPage(url)),
RedirectPolicy.ALWAYS_REDIRECT));
cycle.getResponse().reset();
}
}
It sure is MORE code than the previous one-liner (throwing the exception).
If the user should not use a RestartResponseException within a
RequestCycleListener in 1.5 any more (since it worked in 1.4) I suggest
this to be stated in its JavaDoc.
I'm also not sure in which cases it _IS_ considered to be OK to do so?!
Cheers,
Daniel
- - - - - - - -
Side note:
The resetting of the response was in the right direction but only doing
it AFTER setting a new request handler eliminates the following exception:
java.lang.IllegalStateException: Header was already written to response!
at
org.apache.wicket.protocol.http.HeaderBufferingWebResponse.checkHeader(HeaderBufferingWebResponse.java:64)
at
org.apache.wicket.protocol.http.HeaderBufferingWebResponse.setDateHeader(HeaderBufferingWebResponse.java:134)
at
org.apache.wicket.protocol.http.BufferedWebResponse$SetDateHeaderAction.invoke(BufferedWebResponse.java:310)
at
org.apache.wicket.protocol.http.BufferedWebResponse.writeTo(BufferedWebResponse.java:580)
at
org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:185)
at
org.apache.wicket.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:167)
at
org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:750)
at
org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
at
org.apache.wicket.request.cycle.RequestCycle.executeExceptionRequestHandler(RequestCycle.java:301)
at
org.apache.wicket.request.cycle.RequestCycle.executeExceptionRequestHandler(RequestCycle.java:310)
at
org.apache.wicket.request.cycle.RequestCycle.executeExceptionRequestHandler(RequestCycle.java:310)
at
org.apache.wicket.request.cycle.RequestCycle.executeExceptionRequestHandler(RequestCycle.java:310)
at
org.apache.wicket.request.cycle.RequestCycle.executeExceptionRequestHandler(RequestCycle.java:310)
at
org.apache.wicket.request.cycle.RequestCycle.executeExceptionRequestHandler(RequestCycle.java:310)
at
org.apache.wicket.request.cycle.RequestCycle.executeExceptionRequestHandler(RequestCycle.java:310)
at
org.apache.wicket.request.cycle.RequestCycle.executeExceptionRequestHandler(RequestCycle.java:310)
at
org.apache.wicket.request.cycle.RequestCycle.executeExceptionRequestHandler(RequestCycle.java:310)
at
org.apache.wicket.request.cycle.RequestCycle.executeExceptionRequestHandler(RequestCycle.java:310)
at
org.apache.wicket.request.cycle.RequestCycle.executeExceptionRequestHandler(RequestCycle.java:310)
at
org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:224)
at
org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:280)
at
org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:162)
at
org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:218)
at
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1326)
at
org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:479)
at
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at
org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:520)
at
org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:227)
at
org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:940)
at
org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:409)
at
org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:186)
at
org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:874)
at
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
at org.eclipse.jetty.server.Server.handle(Server.java:349)
at
org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:441)
at
org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:904)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:565)
at
org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:217)
at
org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:50)
at
org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:245)
at
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:598)
at
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:533)
at java.lang.Thread.run(Unknown Source)
On 14.12.2011 15:45, Daniel Soneira wrote:
> The code doing the redirect implements
> IRequestCycleListener#onBeginRequest - which returns void.
>
> Here's the code snippet:
> @Override
> public void onBeginRequest(RequestCycle cycle) {
> Session session = Session.get();
> if (session.getMetaData(REDIRECTED_JSESSIONID) == null) {
> logger.debug("first application request - redirecting to
> loading page");
> session.setMetaData(REDIRECTED_JSESSIONID, Boolean.TRUE);
> String url = getServletRequestContextPath() + "/" +
> cycle.getRequest().getUrl();
> throw new RestartResponseException(newLoadingPage(url));
> }
> }
>
> I've tried the following which "kind of" works (but still don't get
> why throwing that Exception is not supported in 1.5) :
>
> cycle.getResponse().reset(); // not sure if needed?
> cycle.replaceAllRequestHandlers(new RenderPageRequestHandler(new
> PageProvider(newLoadingPage(url))));
>
> Now the redirect is done but the log shows the following stack trace
> (which doesn't looks right):
>
> ERROR - DefaultExceptionMapper - Unexpected error occurred
> org.eclipse.jetty.io.RuntimeIOException: java.io.IOException: Closed
> at
> org.eclipse.jetty.io.UncheckedPrintWriter.setError(UncheckedPrintWriter.java:110)
> at
> org.eclipse.jetty.io.UncheckedPrintWriter.write(UncheckedPrintWriter.java:283)
> at
> org.eclipse.jetty.io.UncheckedPrintWriter.write(UncheckedPrintWriter.java:298)
> at java.io.PrintWriter.append(Unknown Source)
> at
> org.apache.wicket.protocol.http.servlet.ServletWebResponse.write(ServletWebResponse.java:106)
> at
> org.apache.wicket.protocol.http.HeaderBufferingWebResponse.write(HeaderBufferingWebResponse.java:174)
> at
> org.apache.wicket.protocol.http.BufferedWebResponse$WriteCharSequenceAction.invoke(BufferedWebResponse.java:161)
> at
> org.apache.wicket.protocol.http.BufferedWebResponse.writeTo(BufferedWebResponse.java:580)
> at
> org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:247)
> at
> org.apache.wicket.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:167)
> at
> org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:750)
> at
> org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
> at
> org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:252)
> at
> org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:209)
> at
> org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:280)
> at
> org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:162)
> at
> org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:218)
> at
> org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1326)
> at
> org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:479)
> at
> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
> at
> org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:520)
> at
> org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:227)
> at
> org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:940)
> at
> org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:409)
> at
> org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:186)
> at
> org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:874)
> at
> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
> at
> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
> at org.eclipse.jetty.server.Server.handle(Server.java:349)
> at
> org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:441)
> at
> org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:904)
> at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:565)
> at
> org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:217)
> at
> org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:50)
> at
> org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:245)
> at
> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:598)
> at
> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:533)
> at java.lang.Thread.run(Unknown Source)
> Caused by: java.io.IOException: Closed
> at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:147)
> at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:96)
> at java.io.ByteArrayOutputStream.writeTo(Unknown Source)
> at org.eclipse.jetty.server.HttpWriter.write(HttpWriter.java:283)
> at org.eclipse.jetty.server.HttpWriter.write(HttpWriter.java:107)
> at org.eclipse.jetty.server.HttpWriter.write(HttpWriter.java:96)
> at
> org.eclipse.jetty.io.UncheckedPrintWriter.write(UncheckedPrintWriter.java:274)
> ... 36 more
>
> On 14.12.2011 15:28, Martin Grigorov wrote:
>> Hi,
>>
>> No need to throw exceptions.
>> You just need to return IRequestHandler impl that should be used to
>> handle the error (I assume you talk about
>> IRequestCycleListener#onException())
>> Try with: return new RenderPageRequestHandler(new
>> PageProvider(SomePage.class))
>>
>> On Wed, Dec 14, 2011 at 4:20 PM, Daniel Soneira
>> <da...@joyn-it.at> wrote:
>>> Hi there,
>>>
>>> Throwing a RestartResponseException in a custom RequestCycleListener
>>> does
>>> not yield the result I was hoping for.
>>> Instead of redirecting to the specified page the
>>> DefaultExceptionMapper only
>>> shows an Unexpected RuntimeException page.
>>> The equivalent code (within a custom RequestCycle) used to work in 1.4.
>>>
>>> Here's the log:
>>> ERROR - DefaultExceptionMapper - Unexpected error occurred
>>> org.apache.wicket.RestartResponseException
>>>
>>> The listener tries do redirect the very FIRST request - so you have to
>>> restart the jetty server when analyzing the problem.
>>>
>>> Attached you'll find a quickstart that demonstrates the problem.
>>> Note: The code is essentially the same as in WICKET-3248.
>>>
>>> Any help on this matter is appreciated.
>>> I can also create a JIRA issue if needed.
>>>
>>> Kind regards,
>>> Daniel Soneira
>>> --
>>> www.joyn-it.at
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Throwing RestartResponseException within RequestCycleListener
[1.5 - incl. quickstart]
Posted by Daniel Soneira <da...@joyn-it.at>.
The code doing the redirect implements
IRequestCycleListener#onBeginRequest - which returns void.
Here's the code snippet:
@Override
public void onBeginRequest(RequestCycle cycle) {
Session session = Session.get();
if (session.getMetaData(REDIRECTED_JSESSIONID) == null) {
logger.debug("first application request - redirecting to
loading page");
session.setMetaData(REDIRECTED_JSESSIONID, Boolean.TRUE);
String url = getServletRequestContextPath() + "/" +
cycle.getRequest().getUrl();
throw new RestartResponseException(newLoadingPage(url));
}
}
I've tried the following which "kind of" works (but still don't get why
throwing that Exception is not supported in 1.5) :
cycle.getResponse().reset(); // not sure if needed?
cycle.replaceAllRequestHandlers(new RenderPageRequestHandler(new
PageProvider(newLoadingPage(url))));
Now the redirect is done but the log shows the following stack trace
(which doesn't looks right):
ERROR - DefaultExceptionMapper - Unexpected error occurred
org.eclipse.jetty.io.RuntimeIOException: java.io.IOException: Closed
at
org.eclipse.jetty.io.UncheckedPrintWriter.setError(UncheckedPrintWriter.java:110)
at
org.eclipse.jetty.io.UncheckedPrintWriter.write(UncheckedPrintWriter.java:283)
at
org.eclipse.jetty.io.UncheckedPrintWriter.write(UncheckedPrintWriter.java:298)
at java.io.PrintWriter.append(Unknown Source)
at
org.apache.wicket.protocol.http.servlet.ServletWebResponse.write(ServletWebResponse.java:106)
at
org.apache.wicket.protocol.http.HeaderBufferingWebResponse.write(HeaderBufferingWebResponse.java:174)
at
org.apache.wicket.protocol.http.BufferedWebResponse$WriteCharSequenceAction.invoke(BufferedWebResponse.java:161)
at
org.apache.wicket.protocol.http.BufferedWebResponse.writeTo(BufferedWebResponse.java:580)
at
org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:247)
at
org.apache.wicket.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:167)
at
org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:750)
at
org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
at
org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:252)
at
org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:209)
at
org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:280)
at
org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:162)
at
org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:218)
at
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1326)
at
org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:479)
at
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at
org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:520)
at
org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:227)
at
org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:940)
at
org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:409)
at
org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:186)
at
org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:874)
at
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
at org.eclipse.jetty.server.Server.handle(Server.java:349)
at
org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:441)
at
org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:904)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:565)
at
org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:217)
at
org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:50)
at
org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:245)
at
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:598)
at
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:533)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: Closed
at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:147)
at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:96)
at java.io.ByteArrayOutputStream.writeTo(Unknown Source)
at org.eclipse.jetty.server.HttpWriter.write(HttpWriter.java:283)
at org.eclipse.jetty.server.HttpWriter.write(HttpWriter.java:107)
at org.eclipse.jetty.server.HttpWriter.write(HttpWriter.java:96)
at
org.eclipse.jetty.io.UncheckedPrintWriter.write(UncheckedPrintWriter.java:274)
... 36 more
On 14.12.2011 15:28, Martin Grigorov wrote:
> Hi,
>
> No need to throw exceptions.
> You just need to return IRequestHandler impl that should be used to
> handle the error (I assume you talk about
> IRequestCycleListener#onException())
> Try with: return new RenderPageRequestHandler(new PageProvider(SomePage.class))
>
> On Wed, Dec 14, 2011 at 4:20 PM, Daniel Soneira
> <da...@joyn-it.at> wrote:
>> Hi there,
>>
>> Throwing a RestartResponseException in a custom RequestCycleListener does
>> not yield the result I was hoping for.
>> Instead of redirecting to the specified page the DefaultExceptionMapper only
>> shows an Unexpected RuntimeException page.
>> The equivalent code (within a custom RequestCycle) used to work in 1.4.
>>
>> Here's the log:
>> ERROR - DefaultExceptionMapper - Unexpected error occurred
>> org.apache.wicket.RestartResponseException
>>
>> The listener tries do redirect the very FIRST request - so you have to
>> restart the jetty server when analyzing the problem.
>>
>> Attached you'll find a quickstart that demonstrates the problem.
>> Note: The code is essentially the same as in WICKET-3248.
>>
>> Any help on this matter is appreciated.
>> I can also create a JIRA issue if needed.
>>
>> Kind regards,
>> Daniel Soneira
>> --
>> www.joyn-it.at
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Throwing RestartResponseException within RequestCycleListener
[1.5 - incl. quickstart]
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
No need to throw exceptions.
You just need to return IRequestHandler impl that should be used to
handle the error (I assume you talk about
IRequestCycleListener#onException())
Try with: return new RenderPageRequestHandler(new PageProvider(SomePage.class))
On Wed, Dec 14, 2011 at 4:20 PM, Daniel Soneira
<da...@joyn-it.at> wrote:
> Hi there,
>
> Throwing a RestartResponseException in a custom RequestCycleListener does
> not yield the result I was hoping for.
> Instead of redirecting to the specified page the DefaultExceptionMapper only
> shows an Unexpected RuntimeException page.
> The equivalent code (within a custom RequestCycle) used to work in 1.4.
>
> Here's the log:
> ERROR - DefaultExceptionMapper - Unexpected error occurred
> org.apache.wicket.RestartResponseException
>
> The listener tries do redirect the very FIRST request - so you have to
> restart the jetty server when analyzing the problem.
>
> Attached you'll find a quickstart that demonstrates the problem.
> Note: The code is essentially the same as in WICKET-3248.
>
> Any help on this matter is appreciated.
> I can also create a JIRA issue if needed.
>
> Kind regards,
> Daniel Soneira
> --
> www.joyn-it.at
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org