Discussion:
Howto display 404 cause of response on custom error page?
Per Newgro
2012-11-26 14:14:33 UTC
Permalink
Hi,

i'm looking for a way to display the cause of a 404 send by myself on my custom error page.

In a behavior i do
<code>
throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Missing subsite in behavior");
</code>

It is displayed in my custom error page

<code>
@MountPath("404.html")
public class PageNotFound extends AbstractErrorPage {

public PageNotFound() {
super();
}

@Override
protected void setHeaders(WebResponse response) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
super.setHeaders(response);
}
}
</code>

But i wouuld like to display the cause of the 404 to. If i debug i can see the cause deep inside the response. But i can't imagine that i have to rebuild the path to the cause by myself.

Thanks for helping me
Per

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
Martin Grigorov
2012-11-26 14:55:18 UTC
Permalink
Hi,

See ErrorAttributes.java.
By Servlet spec several request attributes are available when the web
container does error dispatching.
Post by Per Newgro
Hi,
i'm looking for a way to display the cause of a 404 send by myself on my custom error page.
In a behavior i do
<code>
throw new
AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Missing
subsite in behavior");
</code>
It is displayed in my custom error page
<code>
@MountPath("404.html")
public class PageNotFound extends AbstractErrorPage {
public PageNotFound() {
super();
}
@Override
protected void setHeaders(WebResponse response) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
super.setHeaders(response);
}
}
</code>
But i wouuld like to display the cause of the 404 to. If i debug i can see
the cause deep inside the response. But i can't imagine that i have to
rebuild the path to the cause by myself.
Thanks for helping me
Per
---------------------------------------------------------------------
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>
Stefan Renz
2012-11-26 15:49:27 UTC
Permalink
Hi,

we had a similar requirement, so we did the following:

instead of throwing a AbortWithHttpErrorCodeException, we throw a
semantic exception. In your case, throw MissingSubsiteException( "your
message" ).

How to make Wicket aware of such an exception and implement a proper
reaction/response?

In your application's #init()-Method, add a RequestCycleListener (e.g.
extends org.apache.wicket.request.cycle.AbstractRequestCycleListener)
which implements #onException() to dispatch to a particular error page
depending on the exception passed in. AFAIK, this is regular Wicket
stuff and nothing terribly internal (right?).


We have a bunch of error pages which are regular WebPages with
#isErrorPage() returning true. Those are triggered via the mentioned
RequestCycleListener by means of a
org.apache.wicket.request.handler.PageProvider, which can be used to
initialize the page just as you may need it. For example, by passing the
exception's message, or the exception itself to also display the stack
trace.

Such an error page can also set a status code by using #getResponse() in
#onBeforeRender(), i.e. set a HttpResponseCode.SC_BAD_REQUEST for
missing parameters.

I hope this helps,
bye
Stefan
Post by Martin Grigorov
Hi,
See ErrorAttributes.java.
By Servlet spec several request attributes are available when the web
container does error dispatching.
Post by Per Newgro
Hi,
i'm looking for a way to display the cause of a 404 send by myself on my
custom error page.
In a behavior i do
<code>
throw new
AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Missing
subsite in behavior");
</code>
It is displayed in my custom error page
<code>
@MountPath("404.html")
public class PageNotFound extends AbstractErrorPage {
public PageNotFound() {
super();
}
@Override
protected void setHeaders(WebResponse response) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
super.setHeaders(response);
}
}
</code>
But i wouuld like to display the cause of the 404 to. If i debug i can see
the cause deep inside the response. But i can't imagine that i have to
rebuild the path to the cause by myself.
Thanks for helping me
Per
---------------------------------------------------------------------
--
im Auftrag der eFonds Solutions AG, +49-89-579494-3417


---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
Per Newgro
2012-11-27 18:45:05 UTC
Permalink
Thanks you both for your suggestions. I will try it tomorrow and come
back if i got more questions :-)

Thanks
Per
Post by Stefan Renz
Hi,
instead of throwing a AbortWithHttpErrorCodeException, we throw a
semantic exception. In your case, throw MissingSubsiteException( "your
message" ).
How to make Wicket aware of such an exception and implement a proper
reaction/response?
In your application's #init()-Method, add a RequestCycleListener (e.g.
extends org.apache.wicket.request.cycle.AbstractRequestCycleListener)
which implements #onException() to dispatch to a particular error page
depending on the exception passed in. AFAIK, this is regular Wicket
stuff and nothing terribly internal (right?).
We have a bunch of error pages which are regular WebPages with
#isErrorPage() returning true. Those are triggered via the mentioned
RequestCycleListener by means of a
org.apache.wicket.request.handler.PageProvider, which can be used to
initialize the page just as you may need it. For example, by passing the
exception's message, or the exception itself to also display the stack
trace.
Such an error page can also set a status code by using #getResponse() in
#onBeforeRender(), i.e. set a HttpResponseCode.SC_BAD_REQUEST for
missing parameters.
I hope this helps,
bye
Stefan
Post by Martin Grigorov
Hi,
See ErrorAttributes.java.
By Servlet spec several request attributes are available when the web
container does error dispatching.
Post by Per Newgro
Hi,
i'm looking for a way to display the cause of a 404 send by myself on my
custom error page.
In a behavior i do
<code>
throw new
AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Missing
subsite in behavior");
</code>
It is displayed in my custom error page
<code>
@MountPath("404.html")
public class PageNotFound extends AbstractErrorPage {
public PageNotFound() {
super();
}
@Override
protected void setHeaders(WebResponse response) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
super.setHeaders(response);
}
}
</code>
But i wouuld like to display the cause of the 404 to. If i debug i can see
the cause deep inside the response. But i can't imagine that i have to
rebuild the path to the cause by myself.
Thanks for helping me
Per
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org

Loading...