Merged API-STRIKES-BACK (5.2.0) to HEAD (5.2)

127226 gjames: RA-1064: Added a WebScriptExceptionResolver


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127592 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jamal Kaabi-Mofrad
2016-06-02 22:16:49 +00:00
parent 932c2fdc56
commit d5cb47936f
5 changed files with 91 additions and 26 deletions

View File

@@ -0,0 +1,36 @@
/*
* Copyright (C) 2005-2016 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.rest.framework.core.exceptions;
import org.springframework.extensions.webscripts.WebScriptException;
import javax.servlet.http.HttpServletResponse;
/**
* Resolves WebScriptExceptions
*
* @author Gethin James
*/
public class WebScriptExceptionResolver implements ExceptionResolver<WebScriptException> {
@Override
public ErrorResponse resolveException(WebScriptException ex) {
return new ErrorResponse(DefaultExceptionResolver.DEFAULT_MESSAGE_ID, ex.getStatus(), ex.getLocalizedMessage(), ex.getStackTrace(), null);
}
}

View File

@@ -73,6 +73,7 @@ public class ApiAssistant {
});
private ExceptionResolver<Exception> defaultResolver = new DefaultExceptionResolver();
private ExceptionResolver<WebScriptException> webScriptExceptionResolver;
private ExceptionResolver<Exception> resolver;
private JacksonHelper jsonHelper;
@@ -86,7 +87,15 @@ public class ApiAssistant {
public ErrorResponse resolveException(Exception ex)
{
ErrorResponse error = resolver.resolveException(ex);
ErrorResponse error = null;
if (ex instanceof WebScriptException)
{
error = webScriptExceptionResolver.resolveException((WebScriptException) ex);
}
else
{
error = resolver.resolveException(ex);
}
if (error == null)
{
error = defaultResolver.resolveException(ex);
@@ -195,6 +204,10 @@ public class ApiAssistant {
this.defaultResolver = defaultResolver;
}
public void setWebScriptExceptionResolver(ExceptionResolver<WebScriptException> webScriptExceptionResolver) {
this.webScriptExceptionResolver = webScriptExceptionResolver;
}
public void setResolver(ExceptionResolver<Exception> resolver) {
this.resolver = resolver;
}