You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2010/05/21 18:58:35 UTC
svn commit: r947071 - in /cxf/trunk:
rt/core/src/main/java/org/apache/cxf/attachment/
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/
systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Author: sergeyb
Date: Fri May 21 16:58:35 2010
New Revision: 947071
URL: http://svn.apache.org/viewvc?rev=947071&view=rev
Log:
Updating rt Attachment to save headers without converting them to lower case
Modified:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentImpl.java
cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.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/MultipartStore.java
Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentImpl.java?rev=947071&r1=947070&r2=947071&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentImpl.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentImpl.java Fri May 21 16:58:35 2010
@@ -58,11 +58,12 @@ public class AttachmentImpl implements A
}
public void setHeader(String name, String value) {
- headers.put(name.toLowerCase(), value);
+ headers.put(name, value);
}
public String getHeader(String name) {
- return headers.get(name.toLowerCase());
+ String value = headers.get(name);
+ return value == null ? headers.get(name.toLowerCase()) : value;
}
public Iterator<String> getHeaderNames() {
Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java?rev=947071&r1=947070&r2=947071&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java Fri May 21 16:58:35 2010
@@ -106,7 +106,7 @@ public class AttachmentSerializer {
.append(bodyBoundary)
.append("\"; ")
.append("start=\"<")
- .append(rootContentId)
+ .append(checkAngleBrackets(rootContentId))
.append(">\"; ")
.append("start-info=\"")
.append(bodyCt)
@@ -167,11 +167,8 @@ public class AttachmentSerializer {
writer.write("Content-Transfer-Encoding: binary\r\n");
if (attachmentId != null) {
+ attachmentId = checkAngleBrackets(attachmentId);
writer.write("Content-ID: <");
- if (attachmentId.charAt(0) == '<'
- && attachmentId.charAt(attachmentId.length() - 1) == '>') {
- attachmentId = attachmentId.substring(1, attachmentId.length() - 1);
- }
writer.write(URLDecoder.decode(attachmentId, "UTF-8"));
writer.write(">\r\n");
}
@@ -196,6 +193,13 @@ public class AttachmentSerializer {
writer.write("\r\n");
}
+ private static String checkAngleBrackets(String value) {
+ if (value.charAt(0) == '<' && value.charAt(value.length() - 1) == '>') {
+ return value.substring(1, value.length() - 1);
+ }
+ return value;
+ }
+
/**
* Write the end of the body boundary and any attachments included.
* @throws IOException
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java?rev=947071&r1=947070&r2=947071&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java Fri May 21 16:58:35 2010
@@ -120,7 +120,7 @@ public class Attachment {
}
public MultivaluedMap<String, String> getHeaders() {
- return new MetadataMap<String, String>(headers);
+ return new MetadataMap<String, String>(headers, false, true);
}
@Override
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=947071&r1=947070&r2=947071&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 May 21 16:58:35 2010
@@ -35,6 +35,7 @@ import javax.activation.DataHandler;
import javax.imageio.ImageIO;
import javax.mail.util.ByteArrayDataSource;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
@@ -49,6 +50,7 @@ import org.apache.cxf.jaxrs.client.WebCl
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
+import org.apache.cxf.jaxrs.impl.MetadataMap;
import org.apache.cxf.jaxrs.provider.JSONProvider;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.apache.cxf.transport.http.HTTPConduit;
@@ -323,7 +325,7 @@ public class JAXRSMultipartTest extends
InputStream is1 =
getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg");
List<Attachment> objects = new ArrayList<Attachment>();
- objects.add(new Attachment("theroot", MediaType.APPLICATION_XML, jaxb));
+ objects.add(new Attachment("<theroot>", MediaType.APPLICATION_XML, jaxb));
objects.add(new Attachment("thejson", MediaType.APPLICATION_JSON, json));
objects.add(new Attachment("theimage", MediaType.APPLICATION_OCTET_STREAM, is1));
Collection<? extends Attachment> coll = client.postAndGetCollection(objects, Attachment.class);
@@ -393,7 +395,12 @@ public class JAXRSMultipartTest extends
client.type("multipart/form-data").accept("multipart/form-data");
ContentDisposition cd = new ContentDisposition("attachment;filename=java.jpg");
- Attachment att = new Attachment("image", is1, cd);
+ MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
+ headers.putSingle("Content-ID", "image");
+ headers.putSingle("Content-Disposition", cd.toString());
+ headers.putSingle("Content-Location", "http://host/bar");
+ headers.putSingle("custom-header", "custom");
+ Attachment att = new Attachment(is1, headers);
MultipartBody body = new MultipartBody(att);
MultipartBody body2 = client.post(body, MultipartBody.class);
@@ -405,13 +412,14 @@ public class JAXRSMultipartTest extends
ContentDisposition cd2 = body2.getRootAttachment().getContentDisposition();
assertEquals("attachment;filename=java.jpg", cd2.toString());
assertEquals("java.jpg", cd2.getParameter("filename"));
+ assertEquals("http://host/location", body2.getRootAttachment().getHeader("Content-Location"));
}
@Test
public void testUploadImageFromForm2() throws Exception {
File file =
new File(getClass().getResource("/org/apache/cxf/systest/jaxrs/resources/java.jpg").getFile());
- String address = "http://localhost:9085/bookstore/books/formimage";
+ String address = "http://localhost:9085/bookstore/books/formimage2";
WebClient client = WebClient.create(address);
HTTPConduit conduit = WebClient.getConfig(client).getHttpConduit();
conduit.getClient().setReceiveTimeout(1000000);
Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java?rev=947071&r1=947070&r2=947071&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java Fri May 21 16:58:35 2010
@@ -89,11 +89,36 @@ public class MultipartStore {
@POST
+ @Path("/books/formimage2")
+ @Consumes("multipart/form-data")
+ @Produces("multipart/form-data")
+ public MultipartBody addBookFormImage2(MultipartBody image) throws Exception {
+ image.getAllAttachments();
+ return image;
+ }
+
+ @POST
@Path("/books/formimage")
@Consumes("multipart/form-data")
@Produces("multipart/form-data")
public MultipartBody addBookFormImage(MultipartBody image) throws Exception {
- return image;
+ List<Attachment> atts = image.getAllAttachments();
+ if (atts.size() != 1) {
+ throw new WebApplicationException();
+ }
+ List<Attachment> newAtts = new ArrayList<Attachment>();
+ Attachment at = atts.get(0);
+ MultivaluedMap<String, String> headers = at.getHeaders();
+ if (!"http://host/bar".equals(headers.getFirst("Content-Location"))) {
+ throw new WebApplicationException();
+ }
+ if (!"custom".equals(headers.getFirst("Custom-Header"))) {
+ throw new WebApplicationException();
+ }
+ headers.putSingle("Content-Location", "http://host/location");
+ newAtts.add(new Attachment(at.getContentId(), at.getDataHandler(), headers));
+
+ return new MultipartBody(newAtts);
}
@POST