mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
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
This commit is contained in:
@@ -21,41 +21,28 @@ package org.alfresco.rest.api;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.ResourceBundle;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.alfresco.rest.api.authentications.AuthenticationTicketsEntityResource;
|
import org.alfresco.rest.api.authentications.AuthenticationTicketsEntityResource;
|
||||||
import org.alfresco.rest.framework.Api;
|
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.ResourceWithMetadata;
|
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.BinaryResourceAction;
|
||||||
import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction;
|
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.RelationshipResourceBinaryAction;
|
||||||
import org.alfresco.rest.framework.resource.actions.interfaces.ResourceAction;
|
import org.alfresco.rest.framework.resource.actions.interfaces.ResourceAction;
|
||||||
import org.alfresco.rest.framework.tools.ApiAssistant;
|
import org.alfresco.rest.framework.tools.ApiAssistant;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.extensions.webscripts.ArgumentTypeDescription;
|
import org.springframework.extensions.webscripts.*;
|
||||||
import org.springframework.extensions.webscripts.Container;
|
|
||||||
import org.springframework.extensions.webscripts.DeclarativeRegistry;
|
|
||||||
import org.springframework.extensions.webscripts.Description;
|
|
||||||
import org.springframework.extensions.webscripts.Description.FormatStyle;
|
import org.springframework.extensions.webscripts.Description.FormatStyle;
|
||||||
import org.springframework.extensions.webscripts.Description.RequiredAuthentication;
|
import org.springframework.extensions.webscripts.Description.RequiredAuthentication;
|
||||||
import org.springframework.extensions.webscripts.Description.RequiredTransaction;
|
import org.springframework.extensions.webscripts.Description.RequiredTransaction;
|
||||||
import org.springframework.extensions.webscripts.Description.TransactionCapability;
|
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 org.springframework.http.HttpMethod;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author steveglover
|
* @author steveglover
|
||||||
@@ -202,6 +189,10 @@ public class PublicApiDeclarativeRegistry extends DeclarativeRegistry
|
|||||||
match = super.findWebScript(method, uri);
|
match = super.findWebScript(method, uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (match == null)
|
||||||
|
{
|
||||||
|
throw new NotFoundException(NotFoundException.DEFAULT_MESSAGE_ID, new String[] {uri});
|
||||||
|
}
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,9 +1,5 @@
|
|||||||
package org.alfresco.rest.api.tests;
|
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.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
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.TestNetwork;
|
||||||
import org.alfresco.rest.api.tests.RepoService.TestPerson;
|
import org.alfresco.rest.api.tests.RepoService.TestPerson;
|
||||||
import org.alfresco.rest.api.tests.client.HttpResponse;
|
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.ListResponse;
|
||||||
import org.alfresco.rest.api.tests.client.PublicApiClient.Paging;
|
import org.alfresco.rest.api.tests.client.PublicApiClient.Paging;
|
||||||
import org.alfresco.rest.api.tests.client.PublicApiClient.People;
|
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.RequestContext;
|
||||||
import org.alfresco.rest.api.tests.client.data.Person;
|
import org.alfresco.rest.api.tests.client.data.Person;
|
||||||
import org.alfresco.rest.api.tests.client.data.PersonNetwork;
|
import org.alfresco.rest.api.tests.client.data.PersonNetwork;
|
||||||
|
import org.alfresco.rest.api.tests.util.RestApiUtil;
|
||||||
import org.alfresco.util.GUID;
|
import org.alfresco.util.GUID;
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
public class TestNetworks extends EnterpriseTestApi
|
public class TestNetworks extends EnterpriseTestApi
|
||||||
{
|
{
|
||||||
private List<TestPerson> people = new ArrayList<TestPerson>(3);
|
private List<TestPerson> people = new ArrayList<TestPerson>(3);
|
||||||
@@ -125,14 +126,29 @@ public class TestNetworks extends EnterpriseTestApi
|
|||||||
publicApiClient.setRequestContext(rc);
|
publicApiClient.setRequestContext(rc);
|
||||||
|
|
||||||
HttpResponse response = publicApiClient.delete(null, null, null, null, null);
|
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());
|
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);
|
response = publicApiClient.put(null, null, null, null, null, null, null);
|
||||||
assertEquals(404, response.getStatusCode());
|
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);
|
response = publicApiClient.post(null, null, null, null, null, null);
|
||||||
assertEquals(404, response.getStatusCode());
|
assertEquals(404, response.getStatusCode());
|
||||||
|
errorResponse = RestApiUtil.parseErrorResponse(response.getJsonResponse());
|
||||||
|
assertNotNull(errorResponse);
|
||||||
|
assertNotNull(errorResponse.getErrorKey());
|
||||||
|
assertNotNull(errorResponse.getBriefSummary());
|
||||||
|
|
||||||
List<PersonNetwork> expectedNetworkMembers = person.getNetworkMemberships();
|
List<PersonNetwork> expectedNetworkMembers = person.getNetworkMemberships();
|
||||||
|
|
||||||
int expectedTotal = expectedNetworkMembers.size();
|
int expectedTotal = expectedNetworkMembers.size();
|
||||||
|
@@ -2069,13 +2069,14 @@ public class PublicApiClient
|
|||||||
private String stackTrace;
|
private String stackTrace;
|
||||||
private Map<String, Object> additionalState;
|
private Map<String, Object> additionalState;
|
||||||
private String descriptionURL;
|
private String descriptionURL;
|
||||||
|
private String logId;
|
||||||
|
|
||||||
public ExpectedErrorResponse()
|
public ExpectedErrorResponse()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExpectedErrorResponse(String errorKey, int statusCode, String briefSummary, StackTraceElement[] stackTrace,
|
public ExpectedErrorResponse(String errorKey, int statusCode, String briefSummary, StackTraceElement[] stackTrace,
|
||||||
Map<String, Object> additionalState)
|
Map<String, Object> additionalState, String logId)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
this.errorKey = errorKey;
|
this.errorKey = errorKey;
|
||||||
@@ -2083,6 +2084,7 @@ public class PublicApiClient
|
|||||||
this.briefSummary = briefSummary;
|
this.briefSummary = briefSummary;
|
||||||
this.stackTrace = Arrays.toString(stackTrace);
|
this.stackTrace = Arrays.toString(stackTrace);
|
||||||
this.additionalState = additionalState;
|
this.additionalState = additionalState;
|
||||||
|
this.logId = logId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getErrorKey()
|
public String getErrorKey()
|
||||||
@@ -2118,6 +2120,14 @@ public class PublicApiClient
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getLogId() {
|
||||||
|
return logId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLogId(String logId) {
|
||||||
|
this.logId = logId;
|
||||||
|
}
|
||||||
|
|
||||||
public String getStackTrace()
|
public String getStackTrace()
|
||||||
{
|
{
|
||||||
return stackTrace;
|
return stackTrace;
|
||||||
@@ -2158,6 +2168,7 @@ public class PublicApiClient
|
|||||||
sb.append("ExpectedErrorResponse [errorKey='").append(errorKey)
|
sb.append("ExpectedErrorResponse [errorKey='").append(errorKey)
|
||||||
.append(", statusCode=").append(statusCode)
|
.append(", statusCode=").append(statusCode)
|
||||||
.append(", briefSummary='").append(briefSummary)
|
.append(", briefSummary='").append(briefSummary)
|
||||||
|
.append(", logId='").append(logId)
|
||||||
.append(", stackTrace='").append(stackTrace)
|
.append(", stackTrace='").append(stackTrace)
|
||||||
.append(", additionalState=").append(additionalState)
|
.append(", additionalState=").append(additionalState)
|
||||||
.append(", descriptionURL='").append(descriptionURL)
|
.append(", descriptionURL='").append(descriptionURL)
|
||||||
|
Reference in New Issue
Block a user