diff --git a/source/java/org/alfresco/rest/api/PublicApiDeclarativeRegistry.java b/source/java/org/alfresco/rest/api/PublicApiDeclarativeRegistry.java index e2138add7b..07f5c2848f 100644 --- a/source/java/org/alfresco/rest/api/PublicApiDeclarativeRegistry.java +++ b/source/java/org/alfresco/rest/api/PublicApiDeclarativeRegistry.java @@ -28,41 +28,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 @@ -209,6 +196,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 cee249ae22..2c88df28b9 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestNetworks.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestNetworks.java @@ -25,10 +25,6 @@ */ 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; @@ -39,6 +35,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; @@ -46,11 +43,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); @@ -150,14 +151,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 84fba252d3..4f1f069741 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 @@ -2076,13 +2076,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; @@ -2090,6 +2091,7 @@ public class PublicApiClient this.briefSummary = briefSummary; this.stackTrace = Arrays.toString(stackTrace); this.additionalState = additionalState; + this.logId = logId; } public String getErrorKey() @@ -2125,6 +2127,14 @@ public class PublicApiClient return this; } + public String getLogId() { + return logId; + } + + public void setLogId(String logId) { + this.logId = logId; + } + public String getStackTrace() { return stackTrace; @@ -2165,6 +2175,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)