Merged searchapi (5.2.1) to 5.2.N (5.2.1)

129774 gjames: SEARCH-113: Moving more api logic to helper classes, using a "trait" style


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130165 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gethin James
2016-09-06 14:14:29 +00:00
parent ff2ce9d706
commit bfd32ef859
26 changed files with 1555 additions and 1303 deletions

View File

@@ -25,29 +25,30 @@
*/
package org.alfresco.rest.api;
import java.io.IOException;
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.alfresco.rest.framework.tools.ApiAssistant;
import org.alfresco.rest.framework.tools.ResponseWriter;
import org.springframework.extensions.config.ServerProperties;
import org.springframework.extensions.surf.util.URLDecoder;
import org.springframework.extensions.webscripts.*;
import org.springframework.extensions.webscripts.*;
import org.springframework.extensions.webscripts.servlet.ServletAuthenticatorFactory;
public class PublicApiTenantWebScriptServletRuntime extends TenantWebScriptServletRuntime
public class PublicApiTenantWebScriptServletRuntime extends TenantWebScriptServletRuntime implements ResponseWriter
{
private static final Pattern CMIS_URI_PATTERN = Pattern.compile(".*/cmis/versions/[0-9]+\\.[0-9]+/.*");
private ApiAssistant apiAssistant;
private ApiAssistant apiAssistant;
public PublicApiTenantWebScriptServletRuntime(RuntimeContainer container, ServletAuthenticatorFactory authFactory, HttpServletRequest req,
HttpServletResponse res, ServerProperties serverProperties, ApiAssistant apiAssistant)
HttpServletResponse res, ServerProperties serverProperties, ApiAssistant apiAssistant)
{
super(container, authFactory, req, res, serverProperties);
this.apiAssistant = apiAssistant;
this.apiAssistant = apiAssistant;
}
/* (non-Javadoc)
@@ -130,24 +131,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);
}
}
}
@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 {
renderException((Exception)exception, response, apiAssistant);
} catch (IOException e) {
logger.error("Internal error", e);
throw new WebScriptException("Internal error", e);
}
}
}
}