[ 
https://jira.duraspace.org/browse/DS-1207?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=26123#comment-26123
 ] 

Nestor Oviedo commented on DS-1207:
-----------------------------------

We've been working on this and noticed that cocoon handles the 
ResourceNotFoundException as a special case. If you take a look at method 
org.apache.cocoon.components.treeprocessor.sitemap.ErrorHandlerHelper.prepareErrorHandler(...)
 (the second one) you will see it checks if the exception is instance of 
ResourceNotFoundException, and logs only the exception message.
The problem is that when the PageNotFoundTransformer throws the 
ResourceNotFoundException, that exception gets wrapped in a SAXException, which 
is re-wrapped as an ProcessingExcepion again because the SAXException isn't a 
ProcessingException, but the orignial ResourceNotFoundException IS a 
ProcessingException ...
We've seen that addBody() methods are invoked from 
org.dspace.app.xmlui.wing.AbstractWingTransformer.startElement() method, which 
can throw only a SAXException (defined in org.xml.sax.ContentHandler class). 
That's the reason because the ResourceNotFoundException is wrapped in a 
SAXException the first time.

So, we had two options:
- patch the SAX class to allow trhowing a ProcessingException
- patch the Cocoon class to adapt the already existent 
ResourceNotFoundException handling

We thought the right fix was by patching the method prepareErrorHandler() from 
Cocoon class 
org.apache.cocoon.components.treeprocessor.sitemap.ErrorHandlerHelper. 

The original code said:
        if (ex instanceof ResourceNotFoundException) {
            this.handledErrorsLogger.error(ex.getMessage());
        } else {
            this.handledErrorsLogger.error(ex.getMessage(), ex);
        }

and we chaged the if condition to check for the root cause of the exception, 
instead of the exception itself. The new code looks like:
        Throwable rootException = ExceptionUtils.getRootCause(ex);
        if (rootException instanceof ResourceNotFoundException) {
            this.handledErrorsLogger.error(rootException.getMessage());
        } else {
            this.handledErrorsLogger.error(ex.getMessage(), ex);
        }

NOTE: class ExceptionUtils is org.apache.commons.lang.exception.ExceptionUtils 
from the Apache Commons Lang package.

As an extra work, we modified the PageNotFoundTransformer in order to:
- avoid throwing the exception when there has been a redirect before
- avoid adding elements to the DRI (to the body or to the pageMeta), because 
the exception will be catched by the main error handler to render the error 
page witch the 404 response code.

We could create a Pull Request for this fix, but we are not very about the 
class ErrorHandlerHelper, because it is a cocoon class ...

What should be done in this case to create the Pull Request correctly?

Of course, any comment will be very welcome.
Regards

                
> ResourceNotFoundException on redirect
> -------------------------------------
>
>                 Key: DS-1207
>                 URL: https://jira.duraspace.org/browse/DS-1207
>             Project: DSpace
>          Issue Type: Bug
>    Affects Versions: 1.8.2, 3.0
>            Reporter: Nestor Oviedo
>              Labels: ResourceNotFoundException, redirect
>
> When the request is redirected to another URL, the cocoon log shows a 
> ResourceNotFoundException thrown from the 
> org.dspace.app.xmlui.aspect.general.PageNotFoundTransformer transformer 
> (referenced in aspects/aspects.xmap when no aspect matched the URI).
> This transformer checks if the DRI body is empty and then throws the 
> exception, but never checks if it was empty because a redirect ocurred.
> Although this error is never seen by the user, it goes to the log and is very 
> annoying.
> To reproduce this error just get a default dspace installation and go to the 
> /login page. Then check the cocoon log .

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Dspace-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dspace-devel

Reply via email to