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)
127535 jkaabimofrad: Merged API-STRIKES-BACK (5.2.0) to HEAD (5.2) 125551 gjames: RA-652: Stack traces not returned, but in the log. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@127645 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
package org.alfresco.rest.framework.core.exceptions;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -35,12 +36,12 @@ import java.util.Map;
|
||||
*/
|
||||
public class ErrorResponse
|
||||
{
|
||||
private String errorKey;
|
||||
private int statusCode;
|
||||
private String briefSummary;
|
||||
private String stackTrace;
|
||||
private Map<String,Object> additionalState;
|
||||
private String descriptionURL;
|
||||
final private String errorKey;
|
||||
final private int statusCode;
|
||||
final private String briefSummary;
|
||||
final private String stackTrace;
|
||||
final private Map<String,Object> additionalState;
|
||||
final private String descriptionURL;
|
||||
|
||||
public ErrorResponse(String errorKey, int statusCode, String briefSummary,
|
||||
StackTraceElement[] stackTrace, Map<String,Object> additionalState)
|
||||
@@ -50,7 +51,20 @@ public class ErrorResponse
|
||||
this.statusCode = statusCode;
|
||||
this.briefSummary = briefSummary;
|
||||
this.stackTrace = Arrays.toString(stackTrace);
|
||||
this.additionalState = additionalState;
|
||||
this.additionalState = additionalState==null?null:Collections.unmodifiableMap(additionalState);
|
||||
this.descriptionURL = null;
|
||||
}
|
||||
|
||||
public ErrorResponse(String errorKey, int statusCode, String briefSummary,
|
||||
String descriptionURL, Map<String,Object> additionalState)
|
||||
{
|
||||
super();
|
||||
this.errorKey = errorKey;
|
||||
this.statusCode = statusCode;
|
||||
this.briefSummary = briefSummary;
|
||||
this.stackTrace = " ";
|
||||
this.additionalState = additionalState==null?null:Collections.unmodifiableMap(additionalState);
|
||||
this.descriptionURL = descriptionURL;
|
||||
}
|
||||
|
||||
public String getErrorKey()
|
||||
@@ -78,11 +92,6 @@ public class ErrorResponse
|
||||
return this.descriptionURL;
|
||||
}
|
||||
|
||||
public void setDescriptionURL(String descriptionURL)
|
||||
{
|
||||
this.descriptionURL = descriptionURL;
|
||||
}
|
||||
|
||||
public Map<String, Object> getAdditionalState()
|
||||
{
|
||||
return this.additionalState;
|
||||
|
@@ -40,8 +40,11 @@ import org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer;
|
||||
import org.alfresco.rest.framework.resource.content.ContentInfo;
|
||||
import org.alfresco.rest.framework.resource.content.ContentInfoImpl;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.apache.chemistry.opencmis.server.shared.ThresholdOutputStreamFactory;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.codehaus.jackson.JsonGenerationException;
|
||||
import org.codehaus.jackson.JsonGenerator;
|
||||
import org.codehaus.jackson.map.JsonMappingException;
|
||||
@@ -64,6 +67,7 @@ import org.springframework.extensions.webscripts.servlet.WebScriptServletRespons
|
||||
*/
|
||||
public abstract class ApiWebScript extends AbstractWebScript
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(ApiWebScript.class);
|
||||
protected JacksonHelper jsonHelper;
|
||||
ExceptionResolver<Exception> defaultResolver = new DefaultExceptionResolver();
|
||||
ExceptionResolver<Exception> resolver;
|
||||
@@ -208,15 +212,27 @@ public abstract class ApiWebScript extends AbstractWebScript
|
||||
* @param res web script response
|
||||
* @throws IOException
|
||||
*/
|
||||
public void renderErrorResponse(final ErrorResponse errorResponse, final WebScriptResponse res) throws IOException {
|
||||
public void renderErrorResponse(ErrorResponse errorResponse, final WebScriptResponse res) throws IOException {
|
||||
|
||||
errorResponse.setDescriptionURL(DefaultExceptionResolver.ERROR_URL);
|
||||
String errorKey = errorResponse.getErrorKey();
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
errorKey = GUID.generate();
|
||||
logger.debug(errorKey+" : ApiWebScript : "+errorResponse.getStackTrace());
|
||||
}
|
||||
|
||||
final ErrorResponse errorToWrite = new ErrorResponse(errorKey,
|
||||
errorResponse.getStatusCode(),
|
||||
errorResponse.getBriefSummary(),
|
||||
DefaultExceptionResolver.ERROR_URL,
|
||||
errorResponse.getAdditionalState());
|
||||
|
||||
setContentInfoOnResponse(res, DEFAULT_JSON_CONTENT);
|
||||
|
||||
// Status must be set before the response is written by Jackson (which will by default close and commit the response).
|
||||
// In a r/w txn, web script buffered responses ensure that it doesn't really matter but for r/o txns this is important.
|
||||
res.setStatus(errorResponse.getStatusCode());
|
||||
res.setStatus(errorToWrite.getStatusCode());
|
||||
|
||||
jsonHelper.withWriter(res.getOutputStream(), new Writer()
|
||||
{
|
||||
@@ -226,7 +242,7 @@ public abstract class ApiWebScript extends AbstractWebScript
|
||||
throws JsonGenerationException, JsonMappingException, IOException
|
||||
{
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("error", errorResponse);
|
||||
obj.put("error", errorToWrite);
|
||||
objectMapper.writeValue(generator, obj);
|
||||
}
|
||||
});
|
||||
|
@@ -321,7 +321,7 @@ 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\":\"[org.alfresco.rest.framework.tests.core.ExecutionTests.testRenderError("));
|
||||
assertTrue(errorMessage.contains("\"stackTrace\":\" \""));
|
||||
assertTrue(errorMessage.contains("\"descriptionURL\":\""+DefaultExceptionResolver.ERROR_URL+"\""));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user