You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Jean-Claude Vogel <vo...@gmail.com> on 2007/10/05 16:19:14 UTC
Error handling and action seems incompatible
Hello,
I have a problem with action usage in error handling in sitemap.
The problem is that when I have an error handle by 'exportExceptionHandler'
I loose the XML stream generated by 'GENERATOR LINE' (see following
pipeline). So in a browser I receive only a status code return but no xml
error stream. When I suppress the 'THIS LINE' line of the sitemap I get my
xml error stream in the browser.
So I would like to know why the fact to use an action here
(exportExceptionHandler) changes the XML stream in handle-errors.
I add that even if there are other solutions to make the same thing, I would
like to keep my ExceptionHandlerAction class (or similar) to be able to have
specific actions in my code.
I would to use error-handling in my pipeline like that :
<map:pipeline>
...
<map:handle-errors>
<map:select type="exception">
<map:when test="exportException">
<map:generate type="exception"/> GENERATOR LINE
<map:act type="exportExceptionHandler" /> THIS LINE
<map:serialize type="xml" />
</map:when>
</map:select>
</map:handle-errors>
...
</map:pipeline>
Following is my Action implementation named 'exportExceptionHandler' in my
code :
public class ExceptionHandlerAction implements Action {
/** General log stream */
private static final Log log = LogFactory.getLog(
ExceptionHandlerAction.class);
/** HTTP status code in success case */
static final int SUCCESS_STATUS_CODE = 200;
/** HTTP status code in bad request case */
static final int BAD_REQUEST_STATUS_CODE = 444;//RAPHAEL'S HACK
/** HTTP status code in internal server error case */
static final int INTERNAL_SERVER_ERROR_STATUS_CODE = 500;
public Map act(Redirector redirector,
SourceResolver resolver,
Map objectModel,
String source,
Parameters parameters) throws Exception {
int statusCode = INTERNAL_SERVER_ERROR_STATUS_CODE;
Throwable throwable = ObjectModelHelper.getThrowable(objectModel);
Throwable cause = throwable.getCause();
if (cause instanceof BadParameterException) {
statusCode = BAD_REQUEST_STATUS_CODE;
} else if (cause instanceof MissingParameterException) {
statusCode = BAD_REQUEST_STATUS_CODE;
}
StringBuffer msg = new StringBuffer("************ Status Code : ");
msg.append(statusCode).append("\ncaused by : ").append(cause);
log.warn(msg);
System.out.println("On est bien passé par là");
redirector.sendStatus(statusCode);
return objectModel;
}
}
Thank for all reply.
Re: Error handling and action seems incompatible
Posted by so...@apache.org.
Thanks for the link. I will read the article. This may explain why
<map:handle-errors> is often ignored. I expected the bug to be
related to redirection with map:generate, map:mount, or
map:redirect-to, but the redirects are usually within a <map:act
typ="resource-exists">.
I may eventually debug Cocoon, but have managed so far with extra
validation to prevent rather than catch errors..
solprovider
On 10/6/07, Alexander Daniel <al...@gmx.at> wrote:
> "A User's Look at the Cocoon Architecture" by Matthew Langham and
> Carsten Ziegeler [1] explains it very well: Matchers, and selectors
> are executed immediately when the sitemap is processed. But
> generators, transformers, and serializers are not executed
> immediately. They are chained to build the processing pipeline. Only
> when a pipeline is complete (when a serializer is added) is the whole
> pipeline executed.
> Alex
> [1] http://www.peachpit.com/articles/article.aspx?p=30037&seqNum=1
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Error handling and action seems incompatible
Posted by Alexander Daniel <al...@gmx.at>.
"A User's Look at the Cocoon Architecture" by Matthew Langham and
Carsten Ziegeler [1] explains it very well: Matchers, and selectors
are executed immediately when the sitemap is processed. But
generators, transformers, and serializers are not executed
immediately. They are chained to build the processing pipeline. Only
when a pipeline is complete (when a serializer is added) is the whole
pipeline executed.
The ExceptionHandlerAction does a redirect by using
redirector.sendStatus(statusCode) which sends a content-less response
to the browser, i.e. the generators, transformers and serializers are
never executed because the pipeline is terminated.
You can use
CocoonComponentManager.getCurrentEnvironment().setStatus(500);
to set the status code without terminating the pipeline.
Alex
[1] http://www.peachpit.com/articles/article.aspx?p=30037&seqNum=1
On 05.10.2007, at 16:19, Jean-Claude Vogel wrote:
> Hello,
>
> I have a problem with action usage in error handling in sitemap.
>
> The problem is that when I have an error handle by
> 'exportExceptionHandler' I loose the XML stream generated by
> 'GENERATOR LINE' (see following pipeline). So in a browser I
> receive only a status code return but no xml error stream. When I
> suppress the 'THIS LINE' line of the sitemap I get my xml error
> stream in the browser.
>
> So I would like to know why the fact to use an action here
> (exportExceptionHandler) changes the XML stream in handle-errors.
>
> I add that even if there are other solutions to make the same
> thing, I would like to keep my ExceptionHandlerAction class (or
> similar) to be able to have specific actions in my code.
>
> I would to use error-handling in my pipeline like that :
> <map:pipeline>
> ...
> <map:handle-errors>
> <map:select type="exception">
> <map:when test="exportException">
> <map:generate type="exception"/> GENERATOR
> LINE
> <map:act type="exportExceptionHandler" />
> THIS LINE
> <map:serialize type="xml" />
> </map:when>
> </map:select>
> </map:handle-errors>
> ...
> </map:pipeline>
>
>
>
> Following is my Action implementation named
> 'exportExceptionHandler' in my code :
>
> public class ExceptionHandlerAction implements Action {
> /** General log stream */
> private static final Log log = LogFactory.getLog
> (ExceptionHandlerAction.class);
>
> /** HTTP status code in success case */
> static final int SUCCESS_STATUS_CODE = 200;
> /** HTTP status code in bad request case */
> static final int BAD_REQUEST_STATUS_CODE = 444;//RAPHAEL'S HACK
> /** HTTP status code in internal server error case */
> static final int INTERNAL_SERVER_ERROR_STATUS_CODE = 500;
>
>
> public Map act(Redirector redirector,
> SourceResolver resolver,
> Map objectModel,
> String source,
> Parameters parameters) throws Exception {
>
> int statusCode = INTERNAL_SERVER_ERROR_STATUS_CODE;
>
> Throwable throwable = ObjectModelHelper.getThrowable
> (objectModel);
> Throwable cause = throwable.getCause();
>
> if (cause instanceof BadParameterException) {
> statusCode = BAD_REQUEST_STATUS_CODE;
> } else if (cause instanceof MissingParameterException) {
> statusCode = BAD_REQUEST_STATUS_CODE;
> }
>
> StringBuffer msg = new StringBuffer("************ Status
> Code : ");
> msg.append(statusCode).append("\ncaused by : ").append(cause);
> log.warn(msg);
>
> System.out.println("On est bien passé par là");
>
>
> redirector.sendStatus(statusCode);
>
> return objectModel;
> }
> }
>
> Thank for all reply.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org