users@glassfish.java.net

(JAX-RS) How to correctly recieve multipart message using _at_Post ?

From: <glassfish_at_javadesktop.org>
Date: Tue, 25 Nov 2008 05:43:47 PST

Hello!

I just can't find the right solution:
I want to send data to a RESTlet using POST request.
How to declare the RESTlet's method header, which annotations are needed?
I want to send multiple parts using one request, so I use a multipart entity from apache-commons-http-client package.

Client contains following code:

        HttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(new URI(address));
        MultipartEntity multipartEntity = new MultipartEntity();
        multipartEntity.addPart("part1", new StringBody("value1"));
        multipartEntity.addPart("part2", new StringBody("value2"));
        httpPost.setEntity(new MultipartEntity());

How to annotate the RESTlet?

        @Path("/test")
        @POST
        @Consumes(MediaType.MULTIPART_FORM_DATA)
        public Response Test(String in1,String in2){ ... }

or is it not just "String in1" but "@FormParam String in1" ?
or is it "MediaType.APPLICATION_FORM_URLENCODED" ?
or is it not String but byte[]? Or InputStream?

I tried every possible combination.
Either I get wrong HTTP error 415 (unsupported media type),
or I get plain representation of all the multipart data inside the first string
(wich all those --BbC04yblablabla).

I'm using integrated Jersey and JAX-RS implementations of the latest Netbeans build.
[Message sent by forum member 'ivan_g_s' (ivan_g_s)]

http://forums.java.net/jive/thread.jspa?messageID=318634