Author: sergeyb Date: Thu May 31 12:53:48 2012 New Revision: 1344694 URL: http://svn.apache.org/viewvc?rev=1344694&view=rev Log: Merged revisions 1344691 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.5.x-fixes
................ r1344691 | sergeyb | 2012-05-31 13:50:36 +0100 (Thu, 31 May 2012) | 9 lines Merged revisions 1344680 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1344680 | sergeyb | 2012-05-31 13:33:07 +0100 (Thu, 31 May 2012) | 1 line [CXF-4348] Fixing the way Content-Type is set for the root part of outbound attachments ........ ................ Modified: cxf/branches/2.4.x-fixes/ (props changed) cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AttachmentOutInterceptor.java cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java Propchange: cxf/branches/2.4.x-fixes/ ------------------------------------------------------------------------------ Merged /cxf/branches/2.5.x-fixes:r1344691 Merged /cxf/trunk:r1344680 Propchange: cxf/branches/2.4.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java?rev=1344694&r1=1344693&r2=1344694&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java (original) +++ cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java Thu May 31 12:53:48 2012 @@ -48,6 +48,7 @@ import javax.mail.internet.InternetHeade import org.apache.cxf.helpers.HttpHeaderHelper; import org.apache.cxf.interceptor.Fault; import org.apache.cxf.message.Attachment; +import org.apache.cxf.message.MessageUtils; public final class AttachmentUtil { @@ -72,6 +73,11 @@ public final class AttachmentUtil { public static CommandMap getCommandMap() { return COMMAND_MAP; } + + public static boolean isMtomEnabled(Message message) { + Object prop = message.getContextualProperty(org.apache.cxf.message.Message.MTOM_ENABLED); + return MessageUtils.isTrue(prop); + } /** * @param ns Modified: cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AttachmentOutInterceptor.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AttachmentOutInterceptor.java?rev=1344694&r1=1344693&r2=1344694&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AttachmentOutInterceptor.java (original) +++ cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AttachmentOutInterceptor.java Thu May 31 12:53:48 2012 @@ -27,6 +27,7 @@ import java.util.Map; import java.util.ResourceBundle; import org.apache.cxf.attachment.AttachmentSerializer; +import org.apache.cxf.attachment.AttachmentUtil; import org.apache.cxf.common.i18n.BundleUtils; import org.apache.cxf.message.Message; import org.apache.cxf.message.MessageUtils; @@ -49,8 +50,7 @@ public class AttachmentOutInterceptor ex // Make it possible to step into this process in spite of Eclipse // by declaring the Object. - Object prop = message.getContextualProperty(org.apache.cxf.message.Message.MTOM_ENABLED); - boolean mtomEnabled = MessageUtils.isTrue(prop); + boolean mtomEnabled = AttachmentUtil.isMtomEnabled(message); boolean writeAtts = MessageUtils.isTrue(message.getContextualProperty(WRITE_ATTACHMENTS)) || (message.getAttachments() != null && !message.getAttachments().isEmpty()); Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java?rev=1344694&r1=1344693&r2=1344694&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java (original) +++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java Thu May 31 12:53:48 2012 @@ -35,6 +35,7 @@ import javax.servlet.http.HttpServletRes import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Request; import javax.ws.rs.core.SecurityContext; import javax.ws.rs.core.UriInfo; @@ -49,6 +50,7 @@ import org.apache.cxf.interceptor.Attach import org.apache.cxf.io.CacheSizeExceededException; import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.MultipartBody; +import org.apache.cxf.jaxrs.impl.MetadataMap; import org.apache.cxf.jaxrs.impl.ProvidersImpl; import org.apache.cxf.jaxrs.interceptor.AttachmentInputInterceptor; import org.apache.cxf.jaxrs.interceptor.AttachmentOutputInterceptor; @@ -185,11 +187,22 @@ public class MessageContextImpl implemen outMessage.setAttachments(atts); outMessage.put(AttachmentOutInterceptor.WRITE_ATTACHMENTS, "true"); Attachment root = (Attachment)handlers.get(0); + + String rootContentType = root.getContentType().toString(); + MultivaluedMap<String, String> rootHeaders = new MetadataMap<String, String>(root.getHeaders()); + if (!AttachmentUtil.isMtomEnabled(outMessage)) { + rootHeaders.putSingle(Message.CONTENT_TYPE, rootContentType); + } + + String messageContentType = outMessage.get(Message.CONTENT_TYPE).toString(); + int index = messageContentType.indexOf(";type"); + if (index > 0) { + messageContentType = messageContentType.substring(0, index).trim(); + } AttachmentOutputInterceptor attInterceptor = - new AttachmentOutputInterceptor(outMessage.get(Message.CONTENT_TYPE).toString(), - root.getHeaders()); + new AttachmentOutputInterceptor(messageContentType, rootHeaders); - outMessage.put(Message.CONTENT_TYPE, root.getContentType().toString()); + outMessage.put(Message.CONTENT_TYPE, rootContentType); attInterceptor.handleMessage(outMessage); } 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=1344694&r1=1344693&r2=1344694&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 Thu May 31 12:53:48 2012 @@ -333,6 +333,7 @@ public class JAXRSMultipartTest extends conduit.getClient().setConnectionTimeout(1000000); client.type("multipart/related").accept("multipart/related"); + XopType xop = new XopType(); xop.setName("xopName"); InputStream is = @@ -419,7 +420,6 @@ public class JAXRSMultipartTest extends String address = "http://localhost:" + PORT; MultipartStore client = JAXRSClientFactory.create(address, MultipartStore.class); - Map<String, Book> map = client.getBookJaxbJson(); List<Book> result = new ArrayList<Book>(map.values()); Book jaxb = result.get(0); @@ -428,6 +428,31 @@ public class JAXRSMultipartTest extends Book json = result.get(1); assertEquals("json", json.getName()); assertEquals(2L, json.getId()); + + String contentType = + WebClient.client(client).getResponse().getMetadata().getFirst("Content-Type").toString(); + MediaType mt = MediaType.valueOf(contentType); + assertEquals("multipart", mt.getType()); + assertEquals("mixed", mt.getSubtype()); + } + + @Test + public void testGetBookJsonProxy() throws Exception { + String address = "http://localhost:" + PORT; + MultipartStore client = JAXRSClientFactory.create(address, MultipartStore.class); + + Map<String, Book> map = client.getBookJson(); + List<Book> result = new ArrayList<Book>(map.values()); + assertEquals(1, result.size()); + Book json = result.get(0); + assertEquals("json", json.getName()); + assertEquals(1L, json.getId()); + + String contentType = + WebClient.client(client).getResponse().getMetadata().getFirst("Content-Type").toString(); + MediaType mt = MediaType.valueOf(contentType); + assertEquals("multipart", mt.getType()); + assertEquals("mixed", mt.getSubtype()); } @Test Modified: cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java?rev=1344694&r1=1344693&r2=1344694&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java (original) +++ cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java Thu May 31 12:53:48 2012 @@ -208,6 +208,17 @@ public class MultipartStore { } @GET + @Path("/books/jaxbjsonimage/read2") + @Produces("multipart/mixed") + public Map<String, Book> getBookJson() throws Exception { + Book json = new Book("json", 1L); + Map<String, Book> objects = new LinkedHashMap<String, Book>(); + objects.put(MediaType.APPLICATION_JSON, json); + return objects; + + } + + @GET @Path("/books/jaxbjsonimage/read-object") @Produces("multipart/mixed") public Map<String, Object> getBookJaxbJsonObject() throws Exception {
