Author: sergeyb Date: Sun Nov 27 18:47:55 2011 New Revision: 1206803 URL: http://svn.apache.org/viewvc?rev=1206803&view=rev Log: Merged revisions 1206800 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk
........ r1206800 | sergeyb | 2011-11-27 18:39:42 +0000 (Sun, 27 Nov 2011) | 1 line [CXF-3936] Renabling the test Benson added, thanks ........ Modified: cxf/branches/2.4.x-fixes/ (props changed) cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java Propchange: cxf/branches/2.4.x-fixes/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Sun Nov 27 18:47:55 2011 @@ -1 +1 @@ -/cxf/trunk:1205786,1205830,1205996-1205997 +/cxf/trunk:1205786,1205830,1205996-1205997,1206800 Propchange: cxf/branches/2.4.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java?rev=1206803&r1=1206802&r2=1206803&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java (original) +++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java Sun Nov 27 18:47:55 2011 @@ -43,7 +43,7 @@ public @interface Multipart { * How to handle a missing part. By default, if no part matches, * the {@link org.apache.cxf.jaxrs.provider.MultipartProvider} * throws a {@link javax.ws.rs.WebApplicationException} - * with status 404. If this option is set to <strong>false</strong>, + * with status 400. If this option is set to <strong>false</strong>, * the parameter is set to <strong>null</strong>. */ boolean errorIfMissing() default true; Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java?rev=1206803&r1=1206802&r2=1206803&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java (original) +++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java Sun Nov 27 18:47:55 2011 @@ -99,7 +99,7 @@ public class FormEncodingProvider implem } MultivaluedMap<String, String> params = createMap(clazz); - populateMap(params, is, mt, + populateMap(params, annotations, is, mt, AnnotationUtils.getAnnotation(annotations, Encoded.class) == null); validateMap(params); @@ -140,11 +140,14 @@ public class FormEncodingProvider implem * @return a Map of parameters. */ protected void populateMap(MultivaluedMap<String, String> params, - InputStream is, MediaType mt, boolean decode) { + Annotation[] anns, + InputStream is, + MediaType mt, + boolean decode) { if (mt.isCompatible(MediaType.MULTIPART_FORM_DATA_TYPE)) { MultipartBody body = AttachmentUtils.getMultipartBody(mc, attachmentDir, attachmentThreshold, attachmentMaxSize); - FormUtils.populateMapFromMultipart(params, body, decode); + FormUtils.populateMapFromMultipart(params, anns, body, decode); } else { String enc = HttpUtils.getEncoding(mt, "UTF-8"); FormUtils.populateMapFromString(params, Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java?rev=1206803&r1=1206802&r2=1206803&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java (original) +++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java Sun Nov 27 18:47:55 2011 @@ -163,11 +163,19 @@ public class MultipartProvider extends A return new MultipartBody(infos); } - Attachment multipart = AttachmentUtils.getMultipart(c, anns, mt, infos); + Multipart id = AnnotationUtils.getAnnotation(anns, Multipart.class); + Attachment multipart = AttachmentUtils.getMultipart(c, id, mt, infos); if (multipart != null) { return fromAttachment(multipart, c, t, anns); + } else if (id != null && !id.errorIfMissing()) { + /* + * If user asked for a null, give them a null. + */ + return null; } + throw new WebApplicationException(400); + } private Class<?> getActualType(Type type, int pos) { Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java?rev=1206803&r1=1206802&r2=1206803&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java (original) +++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java Sun Nov 27 18:47:55 2011 @@ -23,6 +23,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.annotation.Annotation; import java.util.Arrays; import java.util.Enumeration; import java.util.Iterator; @@ -40,6 +41,7 @@ import org.apache.cxf.helpers.IOUtils; import org.apache.cxf.interceptor.LoggingInInterceptor; import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition; +import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.apache.cxf.jaxrs.ext.multipart.MultipartBody; import org.apache.cxf.phase.PhaseInterceptorChain; @@ -138,6 +140,7 @@ public final class FormUtils { } public static void populateMapFromMultipart(MultivaluedMap<String, String> params, + Annotation[] anns, MultipartBody body, boolean decode) { List<Attachment> atts = body.getAllAttachments(); @@ -145,7 +148,13 @@ public final class FormUtils { ContentDisposition cd = a.getContentDisposition(); if (cd == null || !MULTIPART_FORM_DATA_TYPE.equalsIgnoreCase(cd.getType()) || cd.getParameter("name") == null) { - throw new WebApplicationException(415); + Multipart id = AnnotationUtils.getAnnotation(anns, Multipart.class); + + if (id == null || id.errorIfMissing()) { + throw new WebApplicationException(400); + } else { + return; + } } String name = cd.getParameter("name").replace("\"", "").replace("'", ""); try { Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1206803&r1=1206802&r2=1206803&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original) +++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Sun Nov 27 18:47:55 2011 @@ -745,7 +745,7 @@ public final class JAXRSUtils { if (mt != null && "multipart".equalsIgnoreCase(mt.getType()) && MediaType.MULTIPART_FORM_DATA_TYPE.isCompatible(mt)) { MultipartBody body = AttachmentUtils.getMultipartBody(mc); - FormUtils.populateMapFromMultipart(params, body, decode); + FormUtils.populateMapFromMultipart(params, paramAnns, body, decode); } else { org.apache.cxf.common.i18n.Message errorMsg = new org.apache.cxf.common.i18n.Message("WRONG_FORM_MEDIA_TYPE", Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java?rev=1206803&r1=1206802&r2=1206803&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java (original) +++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java Sun Nov 27 18:47:55 2011 @@ -40,7 +40,6 @@ import org.apache.cxf.jaxrs.ext.multipar import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.apache.cxf.jaxrs.ext.multipart.MultipartBody; import org.apache.cxf.jaxrs.impl.MetadataMap; -import org.apache.cxf.jaxrs.utils.AnnotationUtils; import org.apache.cxf.jaxrs.utils.FormUtils; import org.apache.cxf.jaxrs.utils.JAXRSUtils; @@ -98,9 +97,11 @@ public final class AttachmentUtils { attachmentMaxSize).getAllAttachments(); } - public static Attachment getMultipart(Class<Object> c, Annotation[] anns, - MediaType mt, List<Attachment> infos) throws IOException { - Multipart id = AnnotationUtils.getAnnotation(anns, Multipart.class); + public static Attachment getMultipart(Class<Object> c, + Multipart id, + MediaType mt, + List<Attachment> infos) throws IOException { + if (id != null) { for (Attachment a : infos) { if (matchAttachmentId(a, id, mt)) { @@ -108,20 +109,16 @@ public final class AttachmentUtils { return a; } } - if (!id.errorIfMissing()) { - /* - * If user asked for a null, give them a null. - */ - return null; + if (id.errorIfMissing()) { + org.apache.cxf.common.i18n.Message errorMsg = + new org.apache.cxf.common.i18n.Message("MULTTIPART_ID_NOT_FOUND", + BUNDLE, + id.value(), + mt.toString()); + LOG.warning(errorMsg.toString()); + throw new WebApplicationException( + new MultipartReadException(id.value(), id.type(), errorMsg.toString())); } - org.apache.cxf.common.i18n.Message errorMsg = - new org.apache.cxf.common.i18n.Message("MULTTIPART_ID_NOT_FOUND", - BUNDLE, - id.value(), - mt.toString()); - LOG.warning(errorMsg.toString()); - throw new WebApplicationException( - new MultipartReadException(id.value(), id.type(), errorMsg.toString())); } return infos.size() > 0 ? infos.get(0) : null; @@ -139,15 +136,19 @@ public final class AttachmentUtils { } @SuppressWarnings("unchecked") - public static <T> MultivaluedMap<String, T> populateFormMap(MessageContext mc, Class<T> cls) { + public static <T> MultivaluedMap<String, T> populateFormMap(MessageContext mc, + Class<T> cls, + boolean errorIfMissing) { MultivaluedMap<String, T> data = new MetadataMap<String, T>(); - FormUtils.populateMapFromMultipart((MultivaluedMap)data, - AttachmentUtils.getMultipartBody(mc), true); + FormUtils.populateMapFromMultipart((MultivaluedMap)data, + new Annotation[]{}, + AttachmentUtils.getMultipartBody(mc), + true); return data; } public static MultivaluedMap<String, String> populateFormMap(MessageContext mc) { - return populateFormMap(mc, String.class); + return populateFormMap(mc, String.class, true); } private static Map<String, Attachment> fromListToMap(List<Attachment> atts) { Modified: cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java?rev=1206803&r1=1206802&r2=1206803&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java (original) +++ cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java Sun Nov 27 18:47:55 2011 @@ -335,17 +335,17 @@ public class JAXRSMultipartTest extends return ImageIO.read(getClass().getResource(name)); } - @org.junit.Ignore @Test public void testNullableParams() throws Exception { - String address = "http://localhost:" + PORT + "/books/testnullpart"; + String address = "http://localhost:" + PORT + "/bookstore/books/testnullpart"; WebClient client = WebClient.create(address); + WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(10000000); client.type("multipart/form-data").accept("text/plain"); List<Attachment> atts = new LinkedList<Attachment>(); atts.add(new Attachment("somepart", "text/plain", "hello there")); Response r = client.postCollection(atts, Attachment.class); assertEquals(Response.Status.OK.getStatusCode(), r.getStatus()); - assertEquals("nobody home", r.getEntity()); + assertEquals("nobody home", IOUtils.readStringFromStream((InputStream)r.getEntity())); } @Test