users@jersey.java.net

[Jersey] Re: Example of consuming raw binary content?

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Tue, 29 Mar 2011 13:37:55 +0200

To be clear - you have troubles with sending request using
jersey-client? Can you user LoggingFilter and compare request with
curl-produced request? And what exactly happened? Do you have stack
trace/error report?

This should work, we do have similar tests (see EntityTypesTest in
jersey-tests module).

Pavel

On 3/29/11 12:08 PM, Casper Bang wrote:
> Ok, seems like a raw curl command confirms the issue is with how my
> test produce the POST, not the actual rest service.
>
> /Casper
>
> On Tue, Mar 29, 2011 at 11:04 AM, Casper Bang<casper.bang_at_gmail.com> wrote:
>> This seems like a silly trivial question, but I have been unable to
>> consume a binary stream of data as entity in a POST. I have tried with
>> a byte array, an InputSteam as well as accessing the entity though the
>> HttpServletRequest.
>>
>> @POST
>> @Consumes(MediaType.APPLICATION_OCTET_STREAM)
>> public Response post(byte[] payload){
>> System.out.println("Payload: " + new String(payload));
>> return Response.ok().build();
>> }
>>
>> There isn't too much info about binary entities in the wiki or
>> mailinglist, but my gut feeling tells me the above should be ok. So I
>> guess the problem then lies with my producer:
>>
>> @Test
>> public void testPost() {
>>
>> byte[] payload = "This is just a dumb text used for testing
>> binary data".getBytes();
>>
>> ClientResponse response = resource()
>> .path("/")
>> .entity(payload, MediaType.APPLICATION_OCTET_STREAM)
>> .post(ClientResponse.class);
>>
>> assertEquals(200, response.getStatus());
>> }
>>
>> I have tried many combinations of doing a POST, as well as trying to
>> set Content-Length etc. Before consulting an alternative HTTPClient,
>> can anyone spot a problem with the above code or point to an example
>> where Jersey retrieves raw binary data?
>>
>> Thanks in advance,
>>
>> /Casper
>>