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

126609 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)
      125121 gjames: RA-675: Fixed the descriptionURL in error response


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126954 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ancuta Morarasu
2016-05-11 12:20:33 +00:00
parent 366ed0fce0
commit 31766e2d9e
3 changed files with 28 additions and 2 deletions

View File

@@ -34,6 +34,7 @@ import javax.servlet.http.HttpServletResponse;
*/
public class DefaultExceptionResolver implements ExceptionResolver<Exception>
{
public static final String ERROR_URL = "api-explorer.alfresco.com";
public static final String DEFAULT_MESSAGE_ID = "framework.exception.ApiDefault";
@Override

View File

@@ -210,7 +210,7 @@ public abstract class ApiWebScript extends AbstractWebScript
*/
public void renderErrorResponse(final ErrorResponse errorResponse, final WebScriptResponse res) throws IOException {
errorResponse.setDescriptionURL("http://developer.alfresco.com/ErrorsExplained.html#"+errorResponse.getErrorKey());
errorResponse.setDescriptionURL(DefaultExceptionResolver.ERROR_URL);
setContentInfoOnResponse(res, DEFAULT_JSON_CONTENT);

View File

@@ -3,6 +3,7 @@ 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.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
@@ -15,6 +16,8 @@ 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.jacksonextensions.ExecutionResult;
import org.alfresco.rest.framework.resource.actions.ActionExecutor;
@@ -278,10 +281,32 @@ public class ExecutionTests extends AbstractContextTest
verify(response, times(1)).setStatus(HttpServletResponse.SC_NOT_FOUND);
}
@Test
public void testRenderError() throws IOException
{
AbstractResourceWebScript executor = (AbstractResourceWebScript) applicationContext.getBean("executorOfGets");
executor.setResolver(simpleMappingExceptionResolver);
executor.setJsonHelper(jsonHelper);
ErrorResponse defaultError = new DefaultExceptionResolver().resolveException(new NullPointerException());
ByteArrayOutputStream out = new ByteArrayOutputStream();
executor.renderErrorResponse(defaultError, mockResponse(out));
String errorMessage = out.toString();
//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("\"descriptionURL\":\""+DefaultExceptionResolver.ERROR_URL+"\""));
}
private WebScriptResponse mockResponse() throws IOException
{
return mockResponse(new ByteArrayOutputStream());
}
private WebScriptResponse mockResponse(ByteArrayOutputStream byteArrayOutputStream) throws IOException
{
WebScriptResponse res = mock(WebScriptResponse.class);
when(res.getOutputStream()).thenReturn(new ByteArrayOutputStream());
when(res.getOutputStream()).thenReturn(byteArrayOutputStream);
return res;
}