From 69aa553a2ff03452f00cf0c34f594ba41ec7815d Mon Sep 17 00:00:00 2001 From: Jamal Kaabi-Mofrad Date: Thu, 2 Jun 2016 21:40:27 +0000 Subject: [PATCH] Merged API-STRIKES-BACK (5.2.0) to HEAD (5.2) 126282 gjames: RA-878:All api errors should return the standard error, fix 404s git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127573 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../api/PublicApiDeclarativeRegistry.java | 27 ++++++------------ .../alfresco/rest/api/tests/TestNetworks.java | 28 +++++++++++++++---- .../api/tests/client/PublicApiClient.java | 13 ++++++++- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/source/java/org/alfresco/rest/api/PublicApiDeclarativeRegistry.java b/source/java/org/alfresco/rest/api/PublicApiDeclarativeRegistry.java index f6d4d1ca64..b0828cbb7c 100644 --- a/source/java/org/alfresco/rest/api/PublicApiDeclarativeRegistry.java +++ b/source/java/org/alfresco/rest/api/PublicApiDeclarativeRegistry.java @@ -21,41 +21,28 @@ package org.alfresco.rest.api; import java.io.IOException; import java.io.InputStream; import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; -import java.util.ResourceBundle; -import java.util.Set; +import java.util.*; import org.alfresco.rest.api.authentications.AuthenticationTicketsEntityResource; import org.alfresco.rest.framework.Api; import org.alfresco.rest.framework.core.ResourceLocator; import org.alfresco.rest.framework.core.ResourceWithMetadata; +import org.alfresco.rest.framework.core.exceptions.NotFoundException; import org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction; import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceBinaryAction; import org.alfresco.rest.framework.resource.actions.interfaces.ResourceAction; import org.alfresco.rest.framework.tools.ApiAssistant; import org.apache.commons.lang.StringUtils; -import org.springframework.extensions.webscripts.ArgumentTypeDescription; -import org.springframework.extensions.webscripts.Container; -import org.springframework.extensions.webscripts.DeclarativeRegistry; -import org.springframework.extensions.webscripts.Description; +import org.springframework.extensions.webscripts.*; import org.springframework.extensions.webscripts.Description.FormatStyle; import org.springframework.extensions.webscripts.Description.RequiredAuthentication; import org.springframework.extensions.webscripts.Description.RequiredTransaction; import org.springframework.extensions.webscripts.Description.TransactionCapability; -import org.springframework.extensions.webscripts.DescriptionImpl; -import org.springframework.extensions.webscripts.Match; -import org.springframework.extensions.webscripts.NegotiatedFormat; -import org.springframework.extensions.webscripts.Path; -import org.springframework.extensions.webscripts.TransactionParameters; -import org.springframework.extensions.webscripts.TypeDescription; -import org.springframework.extensions.webscripts.URLModelFactory; -import org.springframework.extensions.webscripts.WebScript; -import org.springframework.extensions.webscripts.WebScriptRequest; -import org.springframework.extensions.webscripts.WebScriptResponse; import org.springframework.http.HttpMethod; +import javax.servlet.http.HttpServletResponse; + /** * * @author steveglover @@ -202,6 +189,10 @@ public class PublicApiDeclarativeRegistry extends DeclarativeRegistry match = super.findWebScript(method, uri); } + if (match == null) + { + throw new NotFoundException(NotFoundException.DEFAULT_MESSAGE_ID, new String[] {uri}); + } return match; } diff --git a/source/test-java/org/alfresco/rest/api/tests/TestNetworks.java b/source/test-java/org/alfresco/rest/api/tests/TestNetworks.java index 4ee91f5246..02d1df9e18 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestNetworks.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestNetworks.java @@ -1,9 +1,5 @@ package org.alfresco.rest.api.tests; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -14,6 +10,7 @@ import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork; import org.alfresco.rest.api.tests.RepoService.TestNetwork; import org.alfresco.rest.api.tests.RepoService.TestPerson; import org.alfresco.rest.api.tests.client.HttpResponse; +import org.alfresco.rest.api.tests.client.PublicApiClient; import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse; import org.alfresco.rest.api.tests.client.PublicApiClient.Paging; import org.alfresco.rest.api.tests.client.PublicApiClient.People; @@ -21,11 +18,15 @@ import org.alfresco.rest.api.tests.client.PublicApiException; import org.alfresco.rest.api.tests.client.RequestContext; import org.alfresco.rest.api.tests.client.data.Person; import org.alfresco.rest.api.tests.client.data.PersonNetwork; +import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.util.GUID; import org.apache.commons.httpclient.HttpStatus; import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.*; +import static org.junit.Assert.assertNotNull; + public class TestNetworks extends EnterpriseTestApi { private List people = new ArrayList(3); @@ -125,14 +126,29 @@ public class TestNetworks extends EnterpriseTestApi publicApiClient.setRequestContext(rc); HttpResponse response = publicApiClient.delete(null, null, null, null, null); + //url /null/alfresco/versions/1 does not map to a Web Script assertEquals(404, response.getStatusCode()); - + PublicApiClient.ExpectedErrorResponse errorResponse = RestApiUtil.parseErrorResponse(response.getJsonResponse()); + assertNotNull(errorResponse); + assertNotNull(errorResponse.getErrorKey()); + assertNotNull(errorResponse.getBriefSummary()); + + response = publicApiClient.put(null, null, null, null, null, null, null); assertEquals(404, response.getStatusCode()); + errorResponse = RestApiUtil.parseErrorResponse(response.getJsonResponse()); + assertNotNull(errorResponse); + assertNotNull(errorResponse.getErrorKey()); + assertNotNull(errorResponse.getBriefSummary()); + response = publicApiClient.post(null, null, null, null, null, null); assertEquals(404, response.getStatusCode()); - + errorResponse = RestApiUtil.parseErrorResponse(response.getJsonResponse()); + assertNotNull(errorResponse); + assertNotNull(errorResponse.getErrorKey()); + assertNotNull(errorResponse.getBriefSummary()); + List expectedNetworkMembers = person.getNetworkMemberships(); int expectedTotal = expectedNetworkMembers.size(); diff --git a/source/test-java/org/alfresco/rest/api/tests/client/PublicApiClient.java b/source/test-java/org/alfresco/rest/api/tests/client/PublicApiClient.java index 7412445f03..e81f0c4918 100644 --- a/source/test-java/org/alfresco/rest/api/tests/client/PublicApiClient.java +++ b/source/test-java/org/alfresco/rest/api/tests/client/PublicApiClient.java @@ -2069,13 +2069,14 @@ public class PublicApiClient private String stackTrace; private Map additionalState; private String descriptionURL; + private String logId; public ExpectedErrorResponse() { } public ExpectedErrorResponse(String errorKey, int statusCode, String briefSummary, StackTraceElement[] stackTrace, - Map additionalState) + Map additionalState, String logId) { super(); this.errorKey = errorKey; @@ -2083,6 +2084,7 @@ public class PublicApiClient this.briefSummary = briefSummary; this.stackTrace = Arrays.toString(stackTrace); this.additionalState = additionalState; + this.logId = logId; } public String getErrorKey() @@ -2118,6 +2120,14 @@ public class PublicApiClient return this; } + public String getLogId() { + return logId; + } + + public void setLogId(String logId) { + this.logId = logId; + } + public String getStackTrace() { return stackTrace; @@ -2158,6 +2168,7 @@ public class PublicApiClient sb.append("ExpectedErrorResponse [errorKey='").append(errorKey) .append(", statusCode=").append(statusCode) .append(", briefSummary='").append(briefSummary) + .append(", logId='").append(logId) .append(", stackTrace='").append(stackTrace) .append(", additionalState=").append(additionalState) .append(", descriptionURL='").append(descriptionURL)