RestUtilImpl implements RestUtil { @Override public RequestContent getRequestContent(HttpServletRequest request, HttpHeaders headers) throws Exception { RequestContent rContent = null; if (ServletFileUpload.isMultipartContent(request)) { ServletFileUpload upload = new ServletFileUpload(); FileItemIterator iter = upload.getItemIterator(request); while (iter.hasNext()) { FileItemStream item = iter.next(); if (!item.isFormField()) { rContent = new RequestContent(); rContent.contentStream = item.openStream(); rContent.mimeType = item.getContentType(); FileItemHeaders itemHeaders = item.getHeaders(); if (itemHeaders != null) { String contentLength = itemHeaders.getHeader("Content-Length"); if (contentLength != null) { rContent.size = Long.parseLong(contentLength); } } break; } } } else { rContent = new RequestContent(); rContent.contentStream = request.getInputStream(); if (request.getContentLength() >= 0) { rContent.size = request.getContentLength(); } } if (rContent != null) { if (rContent.mimeType == null) { MediaType mediaType = headers.getMediaType(); if (mediaType != null) { rContent.mimeType = mediaType.toString(); } } if (rContent.size == 0) { List<String> lengthHeaders = headers.getRequestHeader("Content-Length"); if (lengthHeaders != null && lengthHeaders.size() > 0) { rContent.size = Long.parseLong(lengthHeaders.get(0)); } } } return rContent; }  @Override RequestContent getRequestContent(HttpServletRequest request,
                                            HttpHeaders headers);  }
@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()); }