Hi

On 29/09/15 20:28, Sandeep wrote:
I'm seeing an issue posting body with CXF-RS 3.1.0 HTTP POST, what happens is
that if I add an attachment with the same content-type (application/json) as
that of the body, both the entity body and the attachment content are
combined.

E.g. Entity body: TEST ME.

Attachment Content: This is an attachment.

Parameter value in the method below: *TEST ME.  HTTP Headers and then the
attachment content(This is an attachment). *Also, if I do not pass the body
but POST an attachment, the content of the attachment (application/json) is
passed into the parameter requestBody below. Looks like its bug.





@Path("/{someResource}")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
processRequest( String requestBody);


I'm assuming you have Consumes(multipart/form-data) or other multipart type when POSTing the attachments, in this case, all the request body is read into 'requestBody' as opposed to individual part(s) - this is JAX-RS 2.0 compliant. Try using @Multipart annotation or MultipartBody instead of String to read individual parts only


I'm ideally looking to ignore all attachments and throw some HTTP 4XX code,
is there way to do it?
  Below is a sample request, POSTed to the service, where the first part is
in request body while the second part in the request attachment.


The service received the body and message together as a string as below:
Note:

Sample: ------=_Part_27_985990731.1443486850771
Content-Type: application/json
Content-Transfer-Encoding: 8bit

This is a test to understand why message body and attachment are passed
together.
------=_Part_27_985990731.1443486850771
Content-Type: application/json; name=JSONTEST.txt
Content-Transfer-Encoding: binary
Content-ID: <apimessage>
Content-Disposition: attachment; name="JSONTEST.txt";
filename="JSONTEST.txt"

{
     "SomeRequest": {
         "requestType": {
             "aaId": "1",
             "bbtId": "6",
             "ccId": "8",
             "fname": "fname",
             "lname": "lname",
             "address": "address1",
             "country": "USA"
         }
     }
}

------=_Part_27_985990731.1443486850771--

You do not have a 'message' and a 'body', only a single multipart-formatted body with two parts, and as I said above it is read directly into String because you do not have any multipart-related instructions (Multipart annotations, or MultipartBody)

Cheers, Sergey






http://stackoverflow.com/questions/32827616/cxf-rs-combining-body-and-attachment



--
View this message in context: 
http://cxf.547215.n5.nabble.com/CXF-RS-3-1-0-combining-body-and-attachment-tp5761361.html
Sent from the cxf-user mailing list archive at Nabble.com.



--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Reply via email to