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.