Hi On 05/11/12 19:27, Brice Dutheil wrote:
Hi,I'm crafting a resource that should accept multipart POST request. Here's the method : ================================================ @POST @Produces({MediaType.APPLICATION_JSON}) @Consumes(MediaType.MULTIPART_FORM_DATA) public MetaData archive(@FormParam("title") String title, @FormParam("revision") String revision, @Multipart("archive") TemporaryBinaryFile temporaryBinaryFile) { ================================================ Also I tried with @Multipart instead of @FormParam ================================================ @POST @Produces({MediaType.APPLICATION_JSON}) @Consumes(MediaType.MULTIPART_FORM_DATA) public DocumentMetaData archive(@Multipart(value = "title", required = false) @FormParam("title") String title, @Multipart(value = "revision", required = false) String revision, @Multipart("archive") TemporaryBinaryFile temporaryBinaryFile) {
You have @FormParam and @Multipart attached to 'title', drop @FormParam, I think it only works because 'title' is a simple parameter.
================================================ And here is the raw request : ================================================ Address: http://localhost:8080/api/v1.0/document/archive Encoding: ISO-8859-1 Http-Method: POST Content-Type: multipart/form-data;boundary=partie Headers: {Accept=[*/*], accept-charset=[ISO-8859-1,utf-8;q=0.7,*;q=0.3], accept-encoding=[gzip,deflate,sdch], Content-Length=[301], content-type=[multipart/form-data;boundary=partie]} Payload: --partie Content-Disposition: form-data; name="title" Content-ID: title the.title --partie Content-Disposition: form-data; name="revision" Content-ID: revision some.revision --partie Content-Disposition: form-data; name="archive"; filename="file.txt" Content-Type: text/plain I've got a woman, way over town... --partie ================================================ However the title and revision values are incorrect because they are ended by a new line char '\n'. Hence these parameters are not validated by my validator (which is using Message.getContent), I don't think this is a normal behavior, but I might be wrong, maybe about the specs, or my request. Note that I had to add the Content-ID when using the Multipart annotation.
What CXF version is it ? Content-Disposition 'name' is definitely checked too.
Maybe there is something I should do ? I have a workaround for that, I've made an interceptor whose role is to trim strings. But I find it rather inelegant to do that. Or am I missing something ?
I don't have the immediate answer to it, we have few tests were simple parts are transmitted and no new line/return characters make it into the representation.
Can you please experiment with Content-Transfer-Encoding header ? Cheers, Sergey
Cheers -- Brice
