From 66e21fc3022848c50b1fa49bc97b7baf0a536c0e Mon Sep 17 00:00:00 2001 From: Ancuta Morarasu Date: Wed, 11 May 2016 11:38:01 +0000 Subject: [PATCH] Merged HEAD (5.2) to 5.2.N (5.2.1) 126482 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 122590 jkaabimofrad: RA-841: Fixed the status code for the large file upload. Also, added a new exception with 507 status code to be thrown, when "ContentQuotaException" occurs. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126826 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../rest-framework-messages.properties | 1 + config/alfresco/public-rest-context.xml | 1 + .../org/alfresco/rest/api/impl/NodesImpl.java | 5 ++- .../InsufficientStorageException.java | 45 +++++++++++++++++++ .../alfresco/rest/api/tests/NodeApiTest.java | 21 +++++++++ 5 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 source/java/org/alfresco/rest/framework/core/exceptions/InsufficientStorageException.java diff --git a/config/alfresco/messages/rest-framework-messages.properties b/config/alfresco/messages/rest-framework-messages.properties index 024740621f..0061d2c2a7 100644 --- a/config/alfresco/messages/rest-framework-messages.properties +++ b/config/alfresco/messages/rest-framework-messages.properties @@ -12,4 +12,5 @@ framework.exception.StaleEntity=Attempt to update a stale entity framework.exception.UnsupportedResourceOperation=The operation is unsupported framework.exception.DeletedResource=In this version of the API resource {0} has been deleted framework.exception.RequestEntityTooLarge=Request entity too large +framework.exception.InsufficientStorage=Content storage quota exceeded diff --git a/config/alfresco/public-rest-context.xml b/config/alfresco/public-rest-context.xml index ea0959a78d..7f5187378f 100644 --- a/config/alfresco/public-rest-context.xml +++ b/config/alfresco/public-rest-context.xml @@ -144,6 +144,7 @@ + diff --git a/source/java/org/alfresco/rest/api/impl/NodesImpl.java b/source/java/org/alfresco/rest/api/impl/NodesImpl.java index 96f5a5d615..30d5110bd3 100644 --- a/source/java/org/alfresco/rest/api/impl/NodesImpl.java +++ b/source/java/org/alfresco/rest/api/impl/NodesImpl.java @@ -64,6 +64,7 @@ import org.alfresco.rest.api.model.UserInfo; import org.alfresco.rest.framework.core.exceptions.ApiException; import org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException; import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; +import org.alfresco.rest.framework.core.exceptions.InsufficientStorageException; import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException; import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException; import org.alfresco.rest.framework.core.exceptions.RequestEntityTooLargeException; @@ -1715,11 +1716,11 @@ public class NodesImpl implements Nodes } catch (ContentQuotaException cqe) { - throw new RequestEntityTooLargeException(cqe.getMessage()); + throw new InsufficientStorageException(); } catch (ContentLimitViolationException clv) { - throw new ConstraintViolatedException(clv.getMessage()); + throw new RequestEntityTooLargeException(clv.getMessage()); } catch (Exception ex) { diff --git a/source/java/org/alfresco/rest/framework/core/exceptions/InsufficientStorageException.java b/source/java/org/alfresco/rest/framework/core/exceptions/InsufficientStorageException.java new file mode 100644 index 0000000000..bfb85e903e --- /dev/null +++ b/source/java/org/alfresco/rest/framework/core/exceptions/InsufficientStorageException.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2005-2016 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ + +package org.alfresco.rest.framework.core.exceptions; + +/** + * @author Jamal Kaabi-Mofrad + */ +public class InsufficientStorageException extends ApiException +{ + private static final long serialVersionUID = 4188371184446611887L; + + private static final String DEFAULT_MESSAGE_ID = "framework.exception.InsufficientStorage"; + + public InsufficientStorageException() + { + super(DEFAULT_MESSAGE_ID); + } + + public InsufficientStorageException(String msgId) + { + super(msgId); + } + + public InsufficientStorageException(String msgId, Object[] msgParams) + { + super(msgId, msgParams); + } +} diff --git a/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java b/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java index a4e47de3dc..1e08f6066e 100644 --- a/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java @@ -28,6 +28,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.alfresco.model.ContentModel; import org.alfresco.model.ForumModel; +import org.alfresco.repo.content.ContentLimitProvider.SimpleFixedLimitProvider; import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; @@ -867,6 +868,26 @@ public class NodeApiTest extends AbstractBaseApiTest .build(); post(getChildrenUrl(user1Home.getId()), user1, reqBody.getBody(), null, reqBody.getContentType(), 400); + // Test content size limit + final SimpleFixedLimitProvider limitProvider = applicationContext.getBean("defaultContentLimitProvider", SimpleFixedLimitProvider.class); + final long defaultSizeLimit = limitProvider.getSizeLimit(); + limitProvider.setSizeLimitString("20000"); //20 KB + + try + { + // quick.pdf size is about 23 KB + reqBody = MultiPartBuilder.create() + .setFileData(new FileData(fileName, file, MimetypeMap.MIMETYPE_PDF)) + .setAutoRename(true) + .build(); + + // Try to upload a file larger than the configured size limit + post(getChildrenUrl(Nodes.PATH_MY), user1, reqBody.getBody(), null, reqBody.getContentType(), 413); + } + finally + { + limitProvider.setSizeLimitString(Long.toString(defaultSizeLimit)); + } } /**