users@jersey.java.net

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

From: Casper Bang <casper.bang_at_gmail.com>
Date: Tue, 29 Mar 2011 12:08:32 +0200

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
>