diff --git a/common-rest/pom.xml b/common-rest/pom.xml index 1b1797c87..649924642 100644 --- a/common-rest/pom.xml +++ b/common-rest/pom.xml @@ -36,6 +36,14 @@ commons-fileupload + + com.sun.jersey + jersey-client + 1.12 + test + + + diff --git a/common-rest/src/main/java/org/duracloud/common/rest/RestUtil.java b/common-rest/src/main/java/org/duracloud/common/rest/RestUtil.java index 1e95b0089..cf3476a13 100644 --- a/common-rest/src/main/java/org/duracloud/common/rest/RestUtil.java +++ b/common-rest/src/main/java/org/duracloud/common/rest/RestUtil.java @@ -25,7 +25,7 @@ RestUtil.RequestContent getRequestContent(HttpServletRequest request, public class RequestContent { protected InputStream contentStream = null; protected String mimeType = null; - protected int size = 0; + protected long size = 0; /** * @return the contentStream @@ -44,7 +44,7 @@ public String getMimeType() { /** * @return the size */ - public int getSize() { + public long getSize() { return size; } } diff --git a/common-rest/src/main/java/org/duracloud/common/rest/RestUtilImpl.java b/common-rest/src/main/java/org/duracloud/common/rest/RestUtilImpl.java index 3f6e29286..90075e5d1 100644 --- a/common-rest/src/main/java/org/duracloud/common/rest/RestUtilImpl.java +++ b/common-rest/src/main/java/org/duracloud/common/rest/RestUtilImpl.java @@ -59,7 +59,7 @@ public RequestContent getRequestContent(HttpServletRequest request, String contentLength = itemHeaders.getHeader("Content-Length"); if(contentLength != null) { - rContent.size = Integer.parseInt(contentLength); + rContent.size = Long.parseLong(contentLength); } } @@ -89,7 +89,7 @@ public RequestContent getRequestContent(HttpServletRequest request, List lengthHeaders = headers.getRequestHeader("Content-Length"); if(lengthHeaders != null && lengthHeaders.size() > 0) { - rContent.size = Integer.parseInt(lengthHeaders.get(0)); + rContent.size = Long.parseLong(lengthHeaders.get(0)); } } } diff --git a/common-rest/src/test/java/org/duracloud/common/rest/RestUtilImplTest.java b/common-rest/src/test/java/org/duracloud/common/rest/RestUtilImplTest.java new file mode 100644 index 000000000..186c21204 --- /dev/null +++ b/common-rest/src/test/java/org/duracloud/common/rest/RestUtilImplTest.java @@ -0,0 +1,73 @@ +/* + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE and NOTICE files at the root of the source + * tree and available online at + * + * http://duracloud.org/license/ + */ +package org.duracloud.common.rest; + +import static org.easymock.EasyMock.*; +import static org.junit.Assert.*; + +import java.io.File; +import java.util.Arrays; +import java.util.List; + +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; + +import org.duracloud.common.rest.RestUtil.RequestContent; +import org.easymock.EasyMockRunner; +import org.easymock.EasyMockSupport; +import org.easymock.Mock; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(EasyMockRunner.class) +public class RestUtilImplTest extends EasyMockSupport { + + @Mock + private HttpServletRequest request; + + @Mock + private HttpHeaders headers; + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + verifyAll(); + } + + @Test + public void testDuracloud882() throws Exception{ + long contentSize = (long)Integer.MAX_VALUE + 1l; + + File file = File.createTempFile("temp", "txt"); + file.createNewFile(); + file.deleteOnExit(); + + ServletInputStream is = createMock(ServletInputStream.class); + expect(request.getMethod()).andReturn("post"); + expect(request.getContentType()).andReturn("text/plain"); + expect(request.getInputStream()).andReturn(is); + expect(request.getContentLength()).andReturn(-1); + + expect(headers.getMediaType()).andReturn(MediaType.TEXT_PLAIN_TYPE); + List contentLengthHeaders = Arrays.asList(new String[]{contentSize+""}); + expect(headers.getRequestHeader("Content-Length")).andReturn(contentLengthHeaders); + replayAll(); + RestUtilImpl util = new RestUtilImpl(); + RequestContent content = util.getRequestContent(request, headers); + assertEquals(contentSize, content.getSize()); + + } + +} diff --git a/durastore/src/main/java/org/duracloud/durastore/rest/ContentResource.java b/durastore/src/main/java/org/duracloud/durastore/rest/ContentResource.java index 302abcd7c..751932058 100644 --- a/durastore/src/main/java/org/duracloud/durastore/rest/ContentResource.java +++ b/durastore/src/main/java/org/duracloud/durastore/rest/ContentResource.java @@ -38,7 +38,7 @@ String addContent(String spaceID, InputStream content, String contentMimeType, Map userProperties, - int contentSize, + long contentSize, String checksum, String storeID) throws ResourceException, InvalidIdException; diff --git a/durastore/src/main/java/org/duracloud/durastore/rest/ContentResourceImpl.java b/durastore/src/main/java/org/duracloud/durastore/rest/ContentResourceImpl.java index 94b6b21b6..e04f9d685 100644 --- a/durastore/src/main/java/org/duracloud/durastore/rest/ContentResourceImpl.java +++ b/durastore/src/main/java/org/duracloud/durastore/rest/ContentResourceImpl.java @@ -153,7 +153,7 @@ public String addContent(String spaceID, InputStream content, String contentMimeType, Map userProperties, - int contentSize, + long contentSize, String checksum, String storeID) throws ResourceException, InvalidIdException { diff --git a/durastore/src/test/java/org/duracloud/durastore/rest/ContentRestTest.java b/durastore/src/test/java/org/duracloud/durastore/rest/ContentRestTest.java index f1417d17f..0208f2e9a 100644 --- a/durastore/src/test/java/org/duracloud/durastore/rest/ContentRestTest.java +++ b/durastore/src/test/java/org/duracloud/durastore/rest/ContentRestTest.java @@ -143,7 +143,7 @@ private void createCopyContentMocksError() throws Exception { RestUtil.RequestContent content = EasyMock.createMock("RequestContent", RestUtil.RequestContent.class); - EasyMock.expect(content.getSize()).andReturn(5).times(2); + EasyMock.expect(content.getSize()).andReturn(5l).times(2); EasyMock.replay(content); EasyMock.expect(restUtil.getRequestContent(request, httpHeaders))