diff --git a/config/alfresco/public-rest-context.xml b/config/alfresco/public-rest-context.xml index 087344e713..4d2e997302 100644 --- a/config/alfresco/public-rest-context.xml +++ b/config/alfresco/public-rest-context.xml @@ -146,6 +146,7 @@ + diff --git a/source/java/org/alfresco/rest/api/impl/NodesImpl.java b/source/java/org/alfresco/rest/api/impl/NodesImpl.java index f909907454..30deac3c8b 100644 --- a/source/java/org/alfresco/rest/api/impl/NodesImpl.java +++ b/source/java/org/alfresco/rest/api/impl/NodesImpl.java @@ -79,6 +79,7 @@ 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; +import org.alfresco.rest.framework.core.exceptions.UnsupportedMediaTypeException; import org.alfresco.rest.framework.resource.content.BasicContentInfo; import org.alfresco.rest.framework.resource.content.BinaryResource; import org.alfresco.rest.framework.resource.content.ContentInfoImpl; @@ -1803,6 +1804,11 @@ public class NodesImpl implements Nodes @Override public Node updateContent(String fileNodeId, BasicContentInfo contentInfo, InputStream stream, Parameters parameters) { + if (contentInfo.getMimeType().toLowerCase().startsWith("multipart")) + { + throw new UnsupportedMediaTypeException("Cannot update using "+contentInfo.getMimeType()); + } + final NodeRef nodeRef = validateNode(fileNodeId); if (! nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null, false)) diff --git a/source/java/org/alfresco/rest/framework/core/exceptions/UnsupportedMediaTypeException.java b/source/java/org/alfresco/rest/framework/core/exceptions/UnsupportedMediaTypeException.java new file mode 100644 index 0000000000..b50429ca4f --- /dev/null +++ b/source/java/org/alfresco/rest/framework/core/exceptions/UnsupportedMediaTypeException.java @@ -0,0 +1,26 @@ +package org.alfresco.rest.framework.core.exceptions; + +/** + * The media type is unsupported. + * + * @author janv + */ +public class UnsupportedMediaTypeException extends ApiException +{ + public static String DEFAULT_MESSAGE_ID = "framework.exception.UnsupportedMediaType"; + + public UnsupportedMediaTypeException() + { + super(DEFAULT_MESSAGE_ID); + } + + public UnsupportedMediaTypeException(String msgId) + { + super(msgId); + } + + public UnsupportedMediaTypeException(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 35f394d8ec..4a4dc15c01 100644 --- a/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java @@ -2558,6 +2558,10 @@ public class NodeApiTest extends AbstractBaseApiTest // Download the file response = getSingle(url, user1, null, 200); assertNotNull(content, response.getResponse()); + + // -ve - try to update content using multi-part form data + payload = new BinaryPayload(txtFile, "multipart/form-data", null); + putBinary(url, user1, payload, null, null, 415); } /**