Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2B08F9FC6 for ; Fri, 2 Mar 2012 12:59:11 +0000 (UTC) Received: (qmail 87331 invoked by uid 500); 2 Mar 2012 12:59:11 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 87285 invoked by uid 500); 2 Mar 2012 12:59:11 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 87273 invoked by uid 99); 2 Mar 2012 12:59:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Mar 2012 12:59:11 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Mar 2012 12:59:09 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 70866238889B; Fri, 2 Mar 2012 12:58:49 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1296183 - in /cxf/trunk: api/src/main/java/org/apache/cxf/attachment/ rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/ rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/ rt/transports/http/src/main/java/org/a... Date: Fri, 02 Mar 2012 12:58:49 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120302125849.70866238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sergeyb Date: Fri Mar 2 12:58:48 2012 New Revision: 1296183 URL: http://svn.apache.org/viewvc?rev=1296183&view=rev Log: [CXF-4142] Checking contextual properties for non-root parts Modified: cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentSchemaValidationHack.java cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartServer.java Modified: cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java?rev=1296183&r1=1296182&r2=1296183&view=diff ============================================================================== --- cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java (original) +++ cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java Fri Mar 2 12:58:48 2012 @@ -27,6 +27,7 @@ import javax.activation.DataSource; import org.apache.cxf.helpers.IOUtils; import org.apache.cxf.io.CachedOutputStream; +import org.apache.cxf.message.Message; public class AttachmentDataSource implements DataSource { @@ -43,9 +44,10 @@ public class AttachmentDataSource implem public boolean isCached() { return cache != null; } - public void cache() throws IOException { + public void cache(Message message) throws IOException { if (cache == null) { cache = new CachedOutputStream(); + AttachmentUtil.setStreamedAttachmentProperties(message, cache); IOUtils.copy(ins, cache); cache.lockOutputStream(); ins.close(); @@ -55,8 +57,8 @@ public class AttachmentDataSource implem } } } - public void hold() throws IOException { - cache(); + public void hold(Message message) throws IOException { + cache(message); cache.holdTempFile(); } public void release() { Modified: cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java?rev=1296183&r1=1296182&r2=1296183&view=diff ============================================================================== --- cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java (original) +++ cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java Fri Mar 2 12:58:48 2012 @@ -19,7 +19,6 @@ package org.apache.cxf.attachment; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.PushbackInputStream; @@ -168,37 +167,6 @@ public class AttachmentDeserializer { return m.find() ? "--" + m.group(1) : null; } - private void setStreamedAttachmentProperties(CachedOutputStream bos) throws IOException { - Object directory = message.getContextualProperty(ATTACHMENT_DIRECTORY); - if (directory != null) { - if (directory instanceof File) { - bos.setOutputDir((File)directory); - } else { - bos.setOutputDir(new File((String)directory)); - } - } - - Object threshold = message.getContextualProperty(ATTACHMENT_MEMORY_THRESHOLD); - if (threshold != null) { - if (threshold instanceof Long) { - bos.setThreshold((Long)threshold); - } else { - bos.setThreshold(Long.valueOf((String)threshold)); - } - } else { - bos.setThreshold(THRESHOLD); - } - - Object maxSize = message.getContextualProperty(ATTACHMENT_MAX_SIZE); - if (maxSize != null) { - if (maxSize instanceof Long) { - bos.setMaxSize((Long) maxSize); - } else { - bos.setMaxSize(Long.valueOf((String)maxSize)); - } - } - } - public AttachmentImpl readNext() throws IOException { // Cache any mime parts that are currently being streamed cacheStreamedAttachments(); @@ -237,7 +205,7 @@ public class AttachmentDeserializer { if (s instanceof AttachmentDataSource) { AttachmentDataSource ads = (AttachmentDataSource)s; if (!ads.isCached()) { - ads.cache(); + ads.cache(message); } } else if (s.getInputStream() instanceof DelegatingInputStream) { cache((DelegatingInputStream) s.getInputStream(), false); @@ -256,7 +224,7 @@ public class AttachmentDeserializer { InputStream origIn = input.getInputStream(); try { out = new CachedOutputStream(); - setStreamedAttachmentProperties(out); + AttachmentUtil.setStreamedAttachmentProperties(message, out); IOUtils.copy(input, out); input.setInputStream(out.getInputStream()); origIn.close(); Modified: cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java?rev=1296183&r1=1296182&r2=1296183&view=diff ============================================================================== --- cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java (original) +++ cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java Fri Mar 2 12:58:48 2012 @@ -47,7 +47,9 @@ import javax.mail.internet.InternetHeade import org.apache.cxf.helpers.HttpHeaderHelper; import org.apache.cxf.interceptor.Fault; +import org.apache.cxf.io.CachedOutputStream; import org.apache.cxf.message.Attachment; +import org.apache.cxf.message.Message; public final class AttachmentUtil { @@ -73,6 +75,38 @@ public final class AttachmentUtil { return COMMAND_MAP; } + public static void setStreamedAttachmentProperties(Message message, CachedOutputStream bos) + throws IOException { + Object directory = message.getContextualProperty(AttachmentDeserializer.ATTACHMENT_DIRECTORY); + if (directory != null) { + if (directory instanceof File) { + bos.setOutputDir((File)directory); + } else { + bos.setOutputDir(new File((String)directory)); + } + } + + Object threshold = message.getContextualProperty(AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD); + if (threshold != null) { + if (threshold instanceof Long) { + bos.setThreshold((Long)threshold); + } else { + bos.setThreshold(Long.valueOf((String)threshold)); + } + } else { + bos.setThreshold(AttachmentDeserializer.THRESHOLD); + } + + Object maxSize = message.getContextualProperty(AttachmentDeserializer.ATTACHMENT_MAX_SIZE); + if (maxSize != null) { + if (maxSize instanceof Long) { + bos.setMaxSize((Long) maxSize); + } else { + bos.setMaxSize(Long.valueOf((String)maxSize)); + } + } + } + /** * @param ns * @return Modified: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java?rev=1296183&r1=1296182&r2=1296183&view=diff ============================================================================== --- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java (original) +++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java Fri Mar 2 12:58:48 2012 @@ -199,7 +199,7 @@ public class SAAJInInterceptor extends A for (Attachment a : atts) { if (a.getDataHandler().getDataSource() instanceof AttachmentDataSource) { try { - ((AttachmentDataSource)a.getDataHandler().getDataSource()).cache(); + ((AttachmentDataSource)a.getDataHandler().getDataSource()).cache(message); } catch (IOException e) { throw new Fault(e); } Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentSchemaValidationHack.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentSchemaValidationHack.java?rev=1296183&r1=1296182&r2=1296183&view=diff ============================================================================== --- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentSchemaValidationHack.java (original) +++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentSchemaValidationHack.java Fri Mar 2 12:58:48 2012 @@ -53,7 +53,7 @@ public final class JAXBAttachmentSchemaV if (at.getDataHandler().getDataSource() instanceof AttachmentDataSource) { AttachmentDataSource ds = (AttachmentDataSource)at.getDataHandler().getDataSource(); try { - ds.hold(); + ds.hold(message); } catch (IOException e) { throw new Fault(e); } Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java?rev=1296183&r1=1296182&r2=1296183&view=diff ============================================================================== --- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java (original) +++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java Fri Mar 2 12:58:48 2012 @@ -451,7 +451,7 @@ public abstract class AbstractHTTPDestin for (Attachment a : atts) { if (a.getDataHandler().getDataSource() instanceof AttachmentDataSource) { try { - ((AttachmentDataSource)a.getDataHandler().getDataSource()).cache(); + ((AttachmentDataSource)a.getDataHandler().getDataSource()).cache(inMessage); } catch (IOException e) { throw new Fault(e); } Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java?rev=1296183&r1=1296182&r2=1296183&view=diff ============================================================================== --- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java (original) +++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java Fri Mar 2 12:58:48 2012 @@ -562,7 +562,31 @@ public class JAXRSMultipartTest extends post.setRequestHeader("Content-Type", ct); Part[] parts = new Part[1]; parts[0] = new FilePart("image", - new ByteArrayPartSource("testfile.png", new byte[1024 * 1024 * 15]), + new ByteArrayPartSource("testfile.png", new byte[1024 * 11]), + "image/png", null); + post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams())); + + HttpClient httpclient = new HttpClient(); + + try { + int result = httpclient.executeMethod(post); + assertEquals(413, result); + } finally { + // Release current connection to the connection pool once you are done + post.releaseConnection(); + } + } + @Test + public void testMultipartRequestTooLargeManyParts() throws Exception { + PostMethod post = new PostMethod("http://localhost:" + PORT + "/bookstore/books/image"); + String ct = "multipart/mixed"; + post.setRequestHeader("Content-Type", ct); + Part[] parts = new Part[2]; + parts[0] = new FilePart("image", + new ByteArrayPartSource("testfile.png", new byte[1024 * 9]), + "image/png", null); + parts[1] = new FilePart("image", + new ByteArrayPartSource("testfile2.png", new byte[1024 * 11]), "image/png", null); post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams())); Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartServer.java URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartServer.java?rev=1296183&r1=1296182&r2=1296183&view=diff ============================================================================== --- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartServer.java (original) +++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartServer.java Fri Mar 2 12:58:48 2012 @@ -34,7 +34,7 @@ public class MultipartServer extends Abs sf.setResourceClasses(MultipartStore.class); sf.setProperties(Collections.singletonMap( AttachmentDeserializer.ATTACHMENT_MAX_SIZE, - String.valueOf(1024 * 1024 * 10))); + String.valueOf(1024 * 10))); //default lifecycle is per-request, change it to singleton sf.setResourceProvider(MultipartStore.class, new SingletonResourceProvider(new MultipartStore()));