cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brice Dutheil <brice.duth...@gmail.com>
Subject Multipart values are not trimed
Date Mon, 05 Nov 2012 19:27:46 GMT
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) {
================================================

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. 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 ?

Cheers
-- Brice

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message