Hello again,
sadly it worked only by mistake before.
I want to have an error jsp that is shown on all errors of the Sling
post servlet and that displays the according error message.
I thought, that the Throwable.jsp placed below the node for the resource
type is what I wanted but it worked only by accident as I created a NPE
that lead to this page.
Based on Bertrands example I would like to show what I mean:
1.The container node for the resource type
$ curl -u admin:admin -Fsling:resourceType=posterror
http://localhost:8080/apps/posterror
2. The html form
$ echo '<html><body><form method="post"> <input type="hidden"
name=":sendError" value="true"> <input type="text" name="aProperty">
<input type="submit"> </form></body></html>' > /tmp/posterror.jsp
$ curl -u admin:admin -T/tmp/posterror.jsp
http://localhost:8080/apps/posterror/posterror.jsp
3. The general error handler that I would like to show up because the
post of the HTML form in the step before is not unauthenticated.
$ echo 'This is a general error handler' > /tmp/Throwable.jsp
$ curl -u admin:admin -T /tmp/Throwable.jsp
http://localhost:8080/apps/posterror/Throwable.jsp
4. The form whose submit should lead to the rendering of the
Throwable.jsp. How can I make that happen? Is that a bug or is there an
other way to do that?
$ curl http://localhost:8080/apps/posterror.html
5. If I create a 500.jsp like this it gets rendered instead of the
Throwable.jsp. Why is that the case as I would have expected it to be a
"401 Unauthorized" error?
$ echo 'Error 500:
<%=request.getAttribute("javax.servlet.error.message")%>, Exception:
<%=request.getAttribute("javax.servlet.error.exception")%>' > /tmp/500.jsp
$ curl -u admin:admin -T /tmp/500.jsp
http://localhost:8080/apps/posterror/500.jsp
6. Deleting the 500.jsp for debugging reasons
$ curl -u admin:admin -F":operation=delete"
http://localhost:8080/apps/posterror/500.jsp
Help is much appreciated!
Thanks,
Sandro
Am 08.07.15 um 22:01 schrieb Sandro Boehme:
Yeah! I've found the solution.
I've just have to send ":sendError=true" with the post request.
The only documentation I've found is the javadoc [1].
I think I could add the information about that parameter at the "Special
Parameters" paragraph of the "manipulating content" page [2] like:
":sendError
Setting this parameter to true (case insensitive) allows to use custom
error handling as described in the Errorhandling documentation [3]"
If there is no veto I would do that.
There is already a test case for that:
ErrorHandlingTest.test_errorhandling_POST_operation_SlingPostServlet()
It sends a post to /apps/testNode and seem to use the resource type for
the resolution of the error handler.
[1] -
https://sling.apache.org/apidocs/sling7/org/apache/sling/servlets/post/SlingPostConstants.html#RP_SEND_ERROR
[2] -
http://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html#special-parameters
[3] -
https://sling.apache.org/documentation/the-sling-engine/errorhandling.html
Best,
Sandro
Am 06.07.15 um 16:00 schrieb Sandro Boehme:
Am 06.07.15 um 15:20 schrieb Sandro Boehme:
Hi Bertrand,
Am 06.07.15 um 14:25 schrieb Bertrand Delacretaz:
Hi Sandro,
On Mon, Jul 6, 2015 at 2:00 PM, Sandro Boehme <[email protected]>
wrote:
Am 06.07.15 um 11:16 schrieb Bertrand Delacretaz:
...debugging the
SlingServletResolver.handleError method should help as well....
The processing flow does not seem to go through this method as the
debugger
does not stop there....
The below example works for me, comparing with what you are doing
might help?
There are integration tests for this in ErrorHandlingTest [1] but they
dont seem to test the resource-specific error handlers - if you can
add some tests for that while investigating that would be great, of
course.
I'd be happy if I could do that.
$ curl -u admin:admin -Fsling:resourceType=xyz
http://localhost:8080/apps/xyz
...
<title>Content created /apps/xyz</title>
...
$ echo '<% if(true) throw new IllegalStateException("this cannot
work"); %>' > /tmp/xyz.jsp
$ curl -u admin:admin -T/tmp/xyz.jsp
http://localhost:8080/apps/xyz/xyz.jsp
$ echo 'This is the custom error handler' >
/tmp/IllegalStateException.jsp
$ curl -u admin:admin -T /tmp/IllegalStateException.jsp
http://localhost:8080/apps/xyz/IllegalStateException.jsp
$ curl http://localhost:8080/apps/xyz.html
This is the custom error handler
Yeah, it works for me as well! Thanks for this error page example it
runs through the handleError() methods as you wrote.
I'll use the time between some family celebrations to compare with my
code and let you and the list (archive) know about the results.
As a quick check I've added your error handler jsp to the resource
folder and added the throw statement to my page. It works and shows the
custom error page! Next I will check for the right exception and
resource type in my case.
Best,
Sandro