mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD (5.2) to 5.2.N (5.2.1)
127536 jkaabimofrad: 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/BRANCHES/DEV/5.2.N/root@127646 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -56,13 +56,13 @@ public class ErrorResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ErrorResponse(String errorKey, int statusCode, String briefSummary,
|
public ErrorResponse(String errorKey, int statusCode, String briefSummary,
|
||||||
String descriptionURL, Map<String,Object> additionalState)
|
String stackTrace, Map<String,Object> additionalState, String descriptionURL)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
this.errorKey = errorKey;
|
this.errorKey = errorKey;
|
||||||
this.statusCode = statusCode;
|
this.statusCode = statusCode;
|
||||||
this.briefSummary = briefSummary;
|
this.briefSummary = briefSummary;
|
||||||
this.stackTrace = " ";
|
this.stackTrace = stackTrace;
|
||||||
this.additionalState = additionalState==null?null:Collections.unmodifiableMap(additionalState);
|
this.additionalState = additionalState==null?null:Collections.unmodifiableMap(additionalState);
|
||||||
this.descriptionURL = descriptionURL;
|
this.descriptionURL = descriptionURL;
|
||||||
}
|
}
|
||||||
|
@@ -50,13 +50,8 @@ import org.codehaus.jackson.JsonGenerator;
|
|||||||
import org.codehaus.jackson.map.JsonMappingException;
|
import org.codehaus.jackson.map.JsonMappingException;
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.springframework.extensions.webscripts.AbstractWebScript;
|
import org.springframework.extensions.webscripts.*;
|
||||||
import org.springframework.extensions.webscripts.Cache;
|
|
||||||
import org.springframework.extensions.webscripts.Description.RequiredCache;
|
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;
|
import org.springframework.extensions.webscripts.servlet.WebScriptServletResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -214,19 +209,20 @@ public abstract class ApiWebScript extends AbstractWebScript
|
|||||||
*/
|
*/
|
||||||
public void renderErrorResponse(ErrorResponse errorResponse, final WebScriptResponse res) throws IOException {
|
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();
|
logKey = GUID.generate();
|
||||||
logger.debug(errorKey+" : ApiWebScript : "+errorResponse.getStackTrace());
|
logger.error(logKey+" : "+errorResponse.getStackTrace());
|
||||||
}
|
}
|
||||||
|
|
||||||
final ErrorResponse errorToWrite = new ErrorResponse(errorKey,
|
final ErrorResponse errorToWrite = new ErrorResponse(errorResponse.getErrorKey(),
|
||||||
errorResponse.getStatusCode(),
|
errorResponse.getStatusCode(),
|
||||||
errorResponse.getBriefSummary(),
|
errorResponse.getBriefSummary(),
|
||||||
DefaultExceptionResolver.ERROR_URL,
|
logKey,
|
||||||
errorResponse.getAdditionalState());
|
errorResponse.getAdditionalState(),
|
||||||
|
DefaultExceptionResolver.ERROR_URL);
|
||||||
|
|
||||||
setContentInfoOnResponse(res, DEFAULT_JSON_CONTENT);
|
setContentInfoOnResponse(res, DEFAULT_JSON_CONTENT);
|
||||||
|
|
||||||
|
@@ -26,10 +26,7 @@
|
|||||||
|
|
||||||
package org.alfresco.rest.framework.tests.core;
|
package org.alfresco.rest.framework.tests.core;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.Matchers.anyString;
|
||||||
@@ -42,9 +39,7 @@ import org.alfresco.rest.framework.Api;
|
|||||||
import org.alfresco.rest.framework.core.ResourceLocator;
|
import org.alfresco.rest.framework.core.ResourceLocator;
|
||||||
import org.alfresco.rest.framework.core.ResourceLookupDictionary;
|
import org.alfresco.rest.framework.core.ResourceLookupDictionary;
|
||||||
import org.alfresco.rest.framework.core.ResourceWithMetadata;
|
import org.alfresco.rest.framework.core.ResourceWithMetadata;
|
||||||
import org.alfresco.rest.framework.core.exceptions.DefaultExceptionResolver;
|
import org.alfresco.rest.framework.core.exceptions.*;
|
||||||
import org.alfresco.rest.framework.core.exceptions.ErrorResponse;
|
|
||||||
import org.alfresco.rest.framework.core.exceptions.SimpleMappingExceptionResolver;
|
|
||||||
import org.alfresco.rest.framework.jacksonextensions.ExecutionResult;
|
import org.alfresco.rest.framework.jacksonextensions.ExecutionResult;
|
||||||
import org.alfresco.rest.framework.resource.actions.ActionExecutor;
|
import org.alfresco.rest.framework.resource.actions.ActionExecutor;
|
||||||
import org.alfresco.rest.framework.resource.content.ContentInfo;
|
import org.alfresco.rest.framework.resource.content.ContentInfo;
|
||||||
@@ -321,8 +316,26 @@ public class ExecutionTests extends AbstractContextTest
|
|||||||
//System.out.println(errorMessage);
|
//System.out.println(errorMessage);
|
||||||
assertTrue(errorMessage.contains("\"errorKey\":\"framework.exception.ApiDefault\""));
|
assertTrue(errorMessage.contains("\"errorKey\":\"framework.exception.ApiDefault\""));
|
||||||
assertTrue(errorMessage.contains("\"statusCode\":500"));
|
assertTrue(errorMessage.contains("\"statusCode\":500"));
|
||||||
assertTrue(errorMessage.contains("\"stackTrace\":\" \""));
|
assertTrue(errorMessage.contains("\"stackTrace\":\""));
|
||||||
assertTrue(errorMessage.contains("\"descriptionURL\":\""+DefaultExceptionResolver.ERROR_URL+"\""));
|
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
|
private WebScriptResponse mockResponse() throws IOException
|
||||||
|
Reference in New Issue
Block a user