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

126242 gjames: RA-878:All api errors should return the standard error object


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127571 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jamal Kaabi-Mofrad
2016-06-02 21:40:03 +00:00
parent 00c3315166
commit f17a4d19cf
24 changed files with 382 additions and 236 deletions

View File

@@ -18,27 +18,29 @@
*/
package org.alfresco.rest.api;
import java.io.IOException;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.alfresco.repo.web.scripts.TenantWebScriptServletRuntime;
import org.alfresco.rest.framework.tools.ApiAssistant;
import org.springframework.extensions.config.ServerProperties;
import org.springframework.extensions.surf.util.URLDecoder;
import org.springframework.extensions.webscripts.Match;
import org.springframework.extensions.webscripts.RuntimeContainer;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.*;
import org.springframework.extensions.webscripts.servlet.ServletAuthenticatorFactory;
public class PublicApiTenantWebScriptServletRuntime extends TenantWebScriptServletRuntime
{
private static final Pattern CMIS_URI_PATTERN = Pattern.compile(".*/cmis/versions/[0-9]+\\.[0-9]+/.*");
private ApiAssistant apiAssistant;
public PublicApiTenantWebScriptServletRuntime(RuntimeContainer container, ServletAuthenticatorFactory authFactory, HttpServletRequest req,
HttpServletResponse res, ServerProperties serverProperties)
HttpServletResponse res, ServerProperties serverProperties, ApiAssistant apiAssistant)
{
super(container, authFactory, req, res, serverProperties);
this.apiAssistant = apiAssistant;
}
/* (non-Javadoc)
@@ -121,4 +123,24 @@ public class PublicApiTenantWebScriptServletRuntime extends TenantWebScriptServl
{
return "PublicApiTenantServletRuntime";
}
@Override
protected void renderErrorResponse(Match match, Throwable exception, WebScriptRequest request, WebScriptResponse response) {
//If its cmis or not an exception then use the default behaviour
if (CMIS_URI_PATTERN.matcher(req.getRequestURI()).matches() || !(exception instanceof Exception))
{
super.renderErrorResponse(match, exception, request, response);
}
else
{
try {
apiAssistant.renderException((Exception)exception, response);
} catch (IOException e) {
logger.error("Internal error", e);
throw new WebScriptException("Internal error", e);
}
}
}
}