You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Sandro Boehme <sa...@gmx.de> on 2015/07/02 10:19:40 UTC

Errorpage for the Sling Resource Editor

Hello,

for the Resource Editor's [1] property page I would like to switch the 
addition and update of the properties from being ajax calls to be 
regular page requests. But on an error a new an plain error page is 
rendered while I would like to get my Resource Editor page [4] rendered 
with the error data as request attributes that I can use to show the 
error there.
The Resource Editor uses a Resource Provider [2], that wraps the 
resources to add a resource type marker. Based on that marker the 
ResourceProviderBasedResourceDecorator [3] changes the resource type of 
a resource that leads to the JSP [4] to be rendered.

I checked the errorhandling page [5] for Sling but couldn't get it 
working with that information.

Any hint is much appreciated!

Best,

Sandro


[1] - https://sling.apache.org/documentation/bundles/resource-editor.html
     - contrib/explorers/resourceeditor/README

[2] - 
http://svn.apache.org/viewvc/sling/trunk/contrib/explorers/resourceeditor/src/main/java/org/apache/sling/reseditor/resource/

[3] - 
http://svn.apache.org/viewvc/sling/trunk/contrib/explorers/resourceeditor/src/main/java/org/apache/sling/reseditor/resource/ResourceProviderBasedResourceDecorator.java?view=markup

[4] - 
http://svn.apache.org/viewvc/sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor/html.jsp?view=markup

[5] - 
https://sling.apache.org/documentation/the-sling-engine/errorhandling.html

Re: Errorpage for the Sling Resource Editor

Posted by Sandro Boehme <sa...@gmx.de>.
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 <sa...@gmx.de>
>>>> 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
>>
>>
>
>


Re: Errorpage for the Sling Resource Editor

Posted by Sandro Boehme <sa...@gmx.de>.
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 <sa...@gmx.de>
>>> 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
>
>


Re: Errorpage for the Sling Resource Editor

Posted by Sandro Boehme <sa...@gmx.de>.
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 <sa...@gmx.de>
>> 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


Re: Errorpage for the Sling Resource Editor

Posted by Sandro Boehme <sa...@gmx.de>.
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 <sa...@gmx.de> 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.

Thanks again!

Sandro


>
> -Bertrand
>
> [1] https://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolver/errorhandler/ErrorHandlingTest.java
>


Re: Errorpage for the Sling Resource Editor

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Sandro,

On Mon, Jul 6, 2015 at 2:00 PM, Sandro Boehme <sa...@gmx.de> 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.

$ 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

-Bertrand

[1] https://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolver/errorhandler/ErrorHandlingTest.java

Re: Errorpage for the Sling Resource Editor

Posted by Sandro Boehme <sa...@gmx.de>.
Hi Bertrand,

Am 06.07.15 um 11:16 schrieb Bertrand Delacretaz:
> Hi Sandro,
>
> On Mon, Jul 6, 2015 at 10:07 AM, Sandro Boehme <sa...@gmx.de> wrote:
>> to be more concrete, I've added a Throwable.jsp and a 500.jsp to
>>
>> "contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor/errorhandler"...
>
> AFAIK those will only apply to resources of type
> sling/resource-editor/errorhandler
>
>> and
>> "contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor"
>
> Those should apply if a Throwable is thrown or sendResult(500) is
> called while processing a resource of the sling/resource-editor type.
yes, the resource type is "sling/resource-editor". Thanks for your 
infos, it's good to know that this files should apply.

>
> If you want to debug, grepping the DEBUG logs for "candidate" lists
> which scripts/servlets are considered, and 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.
I debugged from the SlingPostServlet on and saw that 
AbstractPostOperation.run() line 144
set the error:

"        } catch (Exception e) {

             log.error("Exception during response processing.", e);
             response.setError(e);
	 }"

and AbstractPostResponse:prepare() line 296
rendered the error page:
"            if (getError() != null) {
                 setStatus(500, getError().toString());
                 setTitle("Error while processing " + path);
              }"
...
But I don't see something that decides when an error page should be shown.
It looks like there is no simple answer so if there is no quick idea on 
what I could try I would have a look at the integration tests for custom 
error pages and/or would start from plain vanilla error page examples.

Thanks,

Sandro


>
> -Bertrand
>


Re: Errorpage for the Sling Resource Editor

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Sandro,

On Mon, Jul 6, 2015 at 10:07 AM, Sandro Boehme <sa...@gmx.de> wrote:
> to be more concrete, I've added a Throwable.jsp and a 500.jsp to
>
> "contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor/errorhandler"...

AFAIK those will only apply to resources of type
sling/resource-editor/errorhandler

> and
> "contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor"

Those should apply if a Throwable is thrown or sendResult(500) is
called while processing a resource of the sling/resource-editor type.

If you want to debug, grepping the DEBUG logs for "candidate" lists
which scripts/servlets are considered, and debugging the
SlingServletResolver.handleError method should help as well.

-Bertrand

Re: Errorpage for the Sling Resource Editor

Posted by Sandro Boehme <sa...@gmx.de>.
Hallo again,

to be more concrete, I've added a Throwable.jsp and a 500.jsp to

"contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor/errorhandler"

and

"contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor"

but still the default white error page shows up with the 500 status.
Does someone have an idea what's wrong with the configuration and how I 
can show an error page for the resource editor?

Best,

Sandro

Am 02.07.15 um 10:19 schrieb Sandro Boehme:
> Hello,
>
> for the Resource Editor's [1] property page I would like to switch the
> addition and update of the properties from being ajax calls to be
> regular page requests. But on an error a new an plain error page is
> rendered while I would like to get my Resource Editor page [4] rendered
> with the error data as request attributes that I can use to show the
> error there.
> The Resource Editor uses a Resource Provider [2], that wraps the
> resources to add a resource type marker. Based on that marker the
> ResourceProviderBasedResourceDecorator [3] changes the resource type of
> a resource that leads to the JSP [4] to be rendered.
>
> I checked the errorhandling page [5] for Sling but couldn't get it
> working with that information.
>
> Any hint is much appreciated!
>
> Best,
>
> Sandro
>
>
> [1] - https://sling.apache.org/documentation/bundles/resource-editor.html
>      - contrib/explorers/resourceeditor/README
>
> [2] -
> http://svn.apache.org/viewvc/sling/trunk/contrib/explorers/resourceeditor/src/main/java/org/apache/sling/reseditor/resource/
>
>
> [3] -
> http://svn.apache.org/viewvc/sling/trunk/contrib/explorers/resourceeditor/src/main/java/org/apache/sling/reseditor/resource/ResourceProviderBasedResourceDecorator.java?view=markup
>
>
> [4] -
> http://svn.apache.org/viewvc/sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor/html.jsp?view=markup
>
>
> [5] -
> https://sling.apache.org/documentation/the-sling-engine/errorhandling.html
>