Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… when the max file size is greater than max java integer value
  • Loading branch information
dbernstein committed Oct 30, 2014
1 parent 976171c commit 7bea7e0
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 7 deletions.
8 changes: 8 additions & 0 deletions common-rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
<artifactId>commons-fileupload</artifactId>
</dependency>

<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.12</version>
<scope>test</scope>
</dependency>


</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,7 +44,7 @@ public String getMimeType() {
/**
* @return the size
*/
public int getSize() {
public long getSize() {
return size;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -89,7 +89,7 @@ public RequestContent getRequestContent(HttpServletRequest request,
List<String> 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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> 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());

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ String addContent(String spaceID,
InputStream content,
String contentMimeType,
Map<String, String> userProperties,
int contentSize,
long contentSize,
String checksum,
String storeID)
throws ResourceException, InvalidIdException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public String addContent(String spaceID,
InputStream content,
String contentMimeType,
Map<String, String> userProperties,
int contentSize,
long contentSize,
String checksum,
String storeID)
throws ResourceException, InvalidIdException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 7bea7e0

Please sign in to comment.