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)
126536 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 123214 gjames: RA-812: Changed http 400 to 404 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126880 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -32,7 +32,6 @@ import java.util.Map;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.alfresco.rest.framework.Api;
|
import org.alfresco.rest.framework.Api;
|
||||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
|
||||||
import org.alfresco.rest.framework.core.exceptions.NotFoundException;
|
import org.alfresco.rest.framework.core.exceptions.NotFoundException;
|
||||||
import org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException;
|
import org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
@@ -53,20 +52,20 @@ public class ResourceLookupDictionary implements ResourceLocator
|
|||||||
private ResourceDictionary dictionary;
|
private ResourceDictionary dictionary;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceWithMetadata locateEntityResource(Api api, String entityResource, HttpMethod httpMethod) throws InvalidArgumentException, UnsupportedResourceOperationException
|
public ResourceWithMetadata locateEntityResource(Api api, String entityResource, HttpMethod httpMethod) throws NotFoundException, UnsupportedResourceOperationException
|
||||||
{
|
{
|
||||||
return locateRelationResource(api, entityResource, (String)null, httpMethod);
|
return locateRelationResource(api, entityResource, (String)null, httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceWithMetadata locateRelationPropertyResource(Api api, String entityResource, String relationResource, String property, HttpMethod httpMethod) throws InvalidArgumentException,UnsupportedResourceOperationException
|
public ResourceWithMetadata locateRelationPropertyResource(Api api, String entityResource, String relationResource, String property, HttpMethod httpMethod) throws NotFoundException,UnsupportedResourceOperationException
|
||||||
{
|
{
|
||||||
String resourceKey = ResourceDictionary.resourceKey(entityResource, relationResource);
|
String resourceKey = ResourceDictionary.resourceKey(entityResource, relationResource);
|
||||||
String propertyResourceKey = ResourceDictionary.propertyResourceKey(resourceKey, property);
|
String propertyResourceKey = ResourceDictionary.propertyResourceKey(resourceKey, property);
|
||||||
Map<String, ResourceWithMetadata> apiResources = dictionary.getAllResources().get(api);
|
Map<String, ResourceWithMetadata> apiResources = dictionary.getAllResources().get(api);
|
||||||
if (apiResources == null)
|
if (apiResources == null)
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_INVALID_API);
|
throw new NotFoundException(NotFoundException.DEFAULT_MESSAGE_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceWithMetadata resource = apiResources.get(propertyResourceKey);
|
ResourceWithMetadata resource = apiResources.get(propertyResourceKey);
|
||||||
@@ -78,12 +77,12 @@ public class ResourceLookupDictionary implements ResourceLocator
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.warn("Unable to locate resource resource for :"+entityResource+" "+relationResource==null?"":relationResource+" "+property==null?"":property);
|
logger.warn("Unable to locate resource resource for :"+entityResource+" "+relationResource==null?"":relationResource+" "+property==null?"":property);
|
||||||
throw new InvalidArgumentException("Unable to locate resource resource for :"+entityResource+" "+(relationResource==null?"":relationResource+" "+property==null?"":property));
|
throw new NotFoundException("Unable to locate resource resource for :"+entityResource+" "+(relationResource==null?"":relationResource+" "+property==null?"":property));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceWithMetadata locateRelationResource(Api api, String entityResource, String relationResource, HttpMethod httpMethod) throws InvalidArgumentException,UnsupportedResourceOperationException
|
public ResourceWithMetadata locateRelationResource(Api api, String entityResource, String relationResource, HttpMethod httpMethod) throws NotFoundException,UnsupportedResourceOperationException
|
||||||
{
|
{
|
||||||
String resourceKey = ResourceDictionary.resourceKey(entityResource, relationResource);
|
String resourceKey = ResourceDictionary.resourceKey(entityResource, relationResource);
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
@@ -93,7 +92,7 @@ public class ResourceLookupDictionary implements ResourceLocator
|
|||||||
Map<String, ResourceWithMetadata> apiResources = dictionary.getAllResources().get(api);
|
Map<String, ResourceWithMetadata> apiResources = dictionary.getAllResources().get(api);
|
||||||
if (apiResources == null)
|
if (apiResources == null)
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_INVALID_API);
|
throw new NotFoundException(NotFoundException.DEFAULT_MESSAGE_ID);
|
||||||
}
|
}
|
||||||
ResourceWithMetadata resource = apiResources.get(resourceKey);
|
ResourceWithMetadata resource = apiResources.get(resourceKey);
|
||||||
if (resource == null)
|
if (resource == null)
|
||||||
@@ -111,7 +110,7 @@ public class ResourceLookupDictionary implements ResourceLocator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.warn("Unable to locate resource resource for :"+entityResource+" "+relationResource==null?"":relationResource);
|
logger.warn("Unable to locate resource resource for :"+entityResource+" "+relationResource==null?"":relationResource);
|
||||||
throw new InvalidArgumentException("Unable to locate resource resource for :"+entityResource+" "+(relationResource==null?"":relationResource));
|
throw new NotFoundException("Unable to locate resource resource for :"+entityResource+" "+(relationResource==null?"":relationResource));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -259,6 +259,25 @@ public class ExecutionTests extends AbstractContextTest
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInvalidUrls() throws IOException
|
||||||
|
{
|
||||||
|
AbstractResourceWebScript executor = (AbstractResourceWebScript) applicationContext.getBean("executorOfGets");
|
||||||
|
executor.setLocator(locator);
|
||||||
|
executor.setResolver(simpleMappingExceptionResolver);
|
||||||
|
executor.setJsonHelper(jsonHelper);
|
||||||
|
Map<String, String> templateVars = new HashMap();
|
||||||
|
templateVars.put("apiScope", "private");
|
||||||
|
templateVars.put("apiVersion", "1");
|
||||||
|
templateVars.put("apiName", "alfrescomock");
|
||||||
|
|
||||||
|
WebScriptResponse response = mockResponse();
|
||||||
|
templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "blah:");
|
||||||
|
executor.execute(api, mockRequest(templateVars, new HashMap<String, List<String>>(1)), response);
|
||||||
|
//Can't find it so a 404
|
||||||
|
verify(response, times(1)).setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
private WebScriptResponse mockResponse() throws IOException
|
private WebScriptResponse mockResponse() throws IOException
|
||||||
{
|
{
|
||||||
WebScriptResponse res = mock(WebScriptResponse.class);
|
WebScriptResponse res = mock(WebScriptResponse.class);
|
||||||
|
@@ -47,6 +47,7 @@ import org.alfresco.rest.framework.core.ResourceMetadata;
|
|||||||
import org.alfresco.rest.framework.core.ResourceOperation;
|
import org.alfresco.rest.framework.core.ResourceOperation;
|
||||||
import org.alfresco.rest.framework.core.ResourceWithMetadata;
|
import org.alfresco.rest.framework.core.ResourceWithMetadata;
|
||||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||||
|
import org.alfresco.rest.framework.core.exceptions.NotFoundException;
|
||||||
import org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException;
|
import org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException;
|
||||||
import org.alfresco.rest.framework.resource.EntityResource;
|
import org.alfresco.rest.framework.resource.EntityResource;
|
||||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||||
@@ -276,9 +277,9 @@ public class ResourceLocatorTests
|
|||||||
{
|
{
|
||||||
//Tests by passing invalid propery
|
//Tests by passing invalid propery
|
||||||
collResource = locator.locateResource(api, templateVars, HttpMethod.GET);
|
collResource = locator.locateResource(api, templateVars, HttpMethod.GET);
|
||||||
fail("Should throw an InvalidArgumentException");
|
fail("Should throw an NotFoundException");
|
||||||
}
|
}
|
||||||
catch (InvalidArgumentException error)
|
catch (NotFoundException error)
|
||||||
{
|
{
|
||||||
//this is correct
|
//this is correct
|
||||||
}
|
}
|
||||||
@@ -353,9 +354,9 @@ public class ResourceLocatorTests
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
entityResource = locator.locateEntityResource(Api.valueOf("alfrescomock", "public", "1"),"sheep", HttpMethod.GET);
|
entityResource = locator.locateEntityResource(Api.valueOf("alfrescomock", "public", "1"),"sheep", HttpMethod.GET);
|
||||||
fail("Should throw an InvalidArgumentException");
|
fail("Should throw an NotFoundException");
|
||||||
}
|
}
|
||||||
catch (InvalidArgumentException error)
|
catch (NotFoundException error)
|
||||||
{
|
{
|
||||||
//this is correct
|
//this is correct
|
||||||
}
|
}
|
||||||
@@ -363,9 +364,9 @@ public class ResourceLocatorTests
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
entityResource = locator.locateEntityResource(Api.valueOf("alfrescomock", "public", "999"),"sheep", HttpMethod.GET);
|
entityResource = locator.locateEntityResource(Api.valueOf("alfrescomock", "public", "999"),"sheep", HttpMethod.GET);
|
||||||
fail("Should throw an InvalidArgumentException");
|
fail("Should throw an NotFoundException");
|
||||||
}
|
}
|
||||||
catch (InvalidArgumentException error)
|
catch (NotFoundException error)
|
||||||
{
|
{
|
||||||
//this is correct
|
//this is correct
|
||||||
}
|
}
|
||||||
@@ -383,9 +384,9 @@ public class ResourceLocatorTests
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
aResource = locator.locateEntityResource(api, "sheepnoaction", HttpMethod.GET);
|
aResource = locator.locateEntityResource(api, "sheepnoaction", HttpMethod.GET);
|
||||||
fail("Should throw an InvalidArgumentException");
|
fail("Should throw an NotFoundException");
|
||||||
}
|
}
|
||||||
catch (InvalidArgumentException error)
|
catch (NotFoundException error)
|
||||||
{
|
{
|
||||||
//this is correct
|
//this is correct
|
||||||
}
|
}
|
||||||
@@ -405,7 +406,7 @@ public class ResourceLocatorTests
|
|||||||
aResource = locator.locateRelationResource(api, "sheepnoaction","v3isaresource", HttpMethod.GET);
|
aResource = locator.locateRelationResource(api, "sheepnoaction","v3isaresource", HttpMethod.GET);
|
||||||
fail("Only available in v3");
|
fail("Only available in v3");
|
||||||
}
|
}
|
||||||
catch (InvalidArgumentException error)
|
catch (NotFoundException error)
|
||||||
{
|
{
|
||||||
//this is correct
|
//this is correct
|
||||||
}
|
}
|
||||||
@@ -416,7 +417,7 @@ public class ResourceLocatorTests
|
|||||||
aResource = locator.locateRelationResource(v2, "sheepnoaction","v3isaresource", HttpMethod.GET);
|
aResource = locator.locateRelationResource(v2, "sheepnoaction","v3isaresource", HttpMethod.GET);
|
||||||
fail("Only available in v3");
|
fail("Only available in v3");
|
||||||
}
|
}
|
||||||
catch (InvalidArgumentException error)
|
catch (NotFoundException error)
|
||||||
{
|
{
|
||||||
//this is correct
|
//this is correct
|
||||||
}
|
}
|
||||||
@@ -474,7 +475,7 @@ public class ResourceLocatorTests
|
|||||||
assertEquals ("sheepnoaction", name);
|
assertEquals ("sheepnoaction", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=org.alfresco.rest.framework.core.exceptions.InvalidArgumentException.class)
|
@Test(expected=org.alfresco.rest.framework.core.exceptions.NotFoundException.class)
|
||||||
public void testLocateRelationResource()
|
public void testLocateRelationResource()
|
||||||
{
|
{
|
||||||
Collection<String> relKeys = Arrays.asList("blacksheep","baaahh");
|
Collection<String> relKeys = Arrays.asList("blacksheep","baaahh");
|
||||||
|
Reference in New Issue
Block a user