mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged API-STRIKES-BACK (5.2.0) to HEAD (5.2)
125552 gjames: RA-652: Stack traces not returned, but in the log, only for 500 or debugging git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127536 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -31,13 +31,13 @@ public class ErrorResponse
|
||||
}
|
||||
|
||||
public ErrorResponse(String errorKey, int statusCode, String briefSummary,
|
||||
String descriptionURL, Map<String,Object> additionalState)
|
||||
String stackTrace, Map<String,Object> additionalState, String descriptionURL)
|
||||
{
|
||||
super();
|
||||
this.errorKey = errorKey;
|
||||
this.statusCode = statusCode;
|
||||
this.briefSummary = briefSummary;
|
||||
this.stackTrace = " ";
|
||||
this.stackTrace = stackTrace;
|
||||
this.additionalState = additionalState==null?null:Collections.unmodifiableMap(additionalState);
|
||||
this.descriptionURL = descriptionURL;
|
||||
}
|
||||
|
@@ -43,13 +43,8 @@ import org.codehaus.jackson.JsonGenerator;
|
||||
import org.codehaus.jackson.map.JsonMappingException;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.webscripts.AbstractWebScript;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.*;
|
||||
import org.springframework.extensions.webscripts.Description.RequiredCache;
|
||||
import org.springframework.extensions.webscripts.Format;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||
import org.springframework.extensions.webscripts.WrappingWebScriptResponse;
|
||||
import org.springframework.extensions.webscripts.servlet.WebScriptServletResponse;
|
||||
|
||||
/**
|
||||
@@ -207,19 +202,20 @@ public abstract class ApiWebScript extends AbstractWebScript
|
||||
*/
|
||||
public void renderErrorResponse(ErrorResponse errorResponse, final WebScriptResponse res) throws IOException {
|
||||
|
||||
String errorKey = errorResponse.getErrorKey();
|
||||
String logKey = " ";
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
if (Status.STATUS_INTERNAL_SERVER_ERROR == errorResponse.getStatusCode() || logger.isDebugEnabled())
|
||||
{
|
||||
errorKey = GUID.generate();
|
||||
logger.debug(errorKey+" : ApiWebScript : "+errorResponse.getStackTrace());
|
||||
logKey = GUID.generate();
|
||||
logger.error(logKey+" : "+errorResponse.getStackTrace());
|
||||
}
|
||||
|
||||
final ErrorResponse errorToWrite = new ErrorResponse(errorKey,
|
||||
final ErrorResponse errorToWrite = new ErrorResponse(errorResponse.getErrorKey(),
|
||||
errorResponse.getStatusCode(),
|
||||
errorResponse.getBriefSummary(),
|
||||
DefaultExceptionResolver.ERROR_URL,
|
||||
errorResponse.getAdditionalState());
|
||||
logKey,
|
||||
errorResponse.getAdditionalState(),
|
||||
DefaultExceptionResolver.ERROR_URL);
|
||||
|
||||
setContentInfoOnResponse(res, DEFAULT_JSON_CONTENT);
|
||||
|
||||
|
@@ -1,9 +1,6 @@
|
||||
package org.alfresco.rest.framework.tests.core;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
@@ -16,9 +13,7 @@ import org.alfresco.rest.framework.Api;
|
||||
import org.alfresco.rest.framework.core.ResourceLocator;
|
||||
import org.alfresco.rest.framework.core.ResourceLookupDictionary;
|
||||
import org.alfresco.rest.framework.core.ResourceWithMetadata;
|
||||
import org.alfresco.rest.framework.core.exceptions.DefaultExceptionResolver;
|
||||
import org.alfresco.rest.framework.core.exceptions.ErrorResponse;
|
||||
import org.alfresco.rest.framework.core.exceptions.SimpleMappingExceptionResolver;
|
||||
import org.alfresco.rest.framework.core.exceptions.*;
|
||||
import org.alfresco.rest.framework.jacksonextensions.ExecutionResult;
|
||||
import org.alfresco.rest.framework.resource.actions.ActionExecutor;
|
||||
import org.alfresco.rest.framework.resource.content.ContentInfo;
|
||||
@@ -295,8 +290,26 @@ public class ExecutionTests extends AbstractContextTest
|
||||
//System.out.println(errorMessage);
|
||||
assertTrue(errorMessage.contains("\"errorKey\":\"framework.exception.ApiDefault\""));
|
||||
assertTrue(errorMessage.contains("\"statusCode\":500"));
|
||||
assertTrue(errorMessage.contains("\"stackTrace\":\" \""));
|
||||
assertTrue(errorMessage.contains("\"stackTrace\":\""));
|
||||
assertTrue(errorMessage.contains("\"descriptionURL\":\""+DefaultExceptionResolver.ERROR_URL+"\""));
|
||||
|
||||
ErrorResponse anError = simpleMappingExceptionResolver.resolveException(new ApiException("nothing"));
|
||||
out = new ByteArrayOutputStream();
|
||||
executor.renderErrorResponse(anError, mockResponse(out));
|
||||
errorMessage = out.toString();
|
||||
System.out.println(errorMessage);
|
||||
assertTrue(errorMessage.contains("\"errorKey\":\"nothing\""));
|
||||
assertTrue(errorMessage.contains("\"statusCode\":500"));
|
||||
assertTrue(errorMessage.contains("\"stackTrace\":\""));
|
||||
|
||||
anError = simpleMappingExceptionResolver.resolveException(new EntityNotFoundException("2"));
|
||||
out = new ByteArrayOutputStream();
|
||||
executor.renderErrorResponse(anError, mockResponse(out));
|
||||
errorMessage = out.toString();
|
||||
System.out.println(errorMessage);
|
||||
assertTrue(errorMessage.contains("\"errorKey\":\"framework.exception.EntityNotFound\""));
|
||||
assertTrue(errorMessage.contains("\"statusCode\":404"));
|
||||
assertTrue("Only 500 errors should have a stracktrace", errorMessage.contains("\"stackTrace\":\" \""));
|
||||
}
|
||||
|
||||
private WebScriptResponse mockResponse() throws IOException
|
||||
|
Reference in New Issue
Block a user