users@jersey.java.net

MULTIPART_FORM_DATA and error 415

From: Suresh Kumar <yesbkay_at_yahoo.com>
Date: Sun, 21 Mar 2010 22:51:03 -0700 (PDT)

This is my environment:
Jersey: 1.1.4Glassfish: V2.1.1JDK : 1.0.6_18
I am getting a "A message body reader for Java type, class com.sun.jersey.multipart.FormDataMultiPart, and MIME media type, multipart/form-data;boundary=Boundary_1_2943240_1269235622354, was not found" message and a415.
Should I implement a reader?
Any pointers would be really appreciated. I have attached the client code, server code and Jersey output.
Thanks,Suresh

Client Code:
private static void postImageAgain() throws Exception {        String url = "http://localhost:8080/image";        WebResource webResource = client.resource(url);        File file = new File("src/main/resources/rest/collapse.gif");        InputStream inputStream = new FileInputStream(file);        FormDataMultiPart fdmp = new FormDataMultiPart();        FormDataBodyPart fdp = new FormDataBodyPart("media", file, MediaType.MULTIPART_FORM_DATA_TYPE);        fdmp.bodyPart(fdp);
        ClientResponse response =            webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class,                fdmp);        System.out.println("POST New Campaign Response Status : " + response.getStatus());        System.out.println("POST New Campaign Response Content Type : " + response.getHeaders().get("Content-Type"));        String entity = response.getEntity(String.class);        System.out.println("POST New Campaign Entity : " + entity);    }
Server Code:
    @POST    @Path("/campaign")    @Consumes(MediaType.MULTIPART_FORM_DATA)    @Produces("application/json")    public Response createCampaign(FormDataMultiPart formData) throws IOException {        FormDataBodyPart imageFormData = formData.getField("media");        InputStream image = imageFormData.getValueAs(InputStream.class);        FormDataContentDisposition imageFdCD = formData.getField("media").getValueAs(FormDataContentDisposition.class);        ByteArrayOutputStream baos = new ByteArrayOutputStream();        int read = 0;        byte[] buf = new byte[4096];        while ((read = image.read(buf)) != -1) {            baos.write(buf, 0, read);        }        String s = new String(baos.toByteArray());        System.out.println("form-data file name: " + imageFdCD.getFileName());        System.out.println("form-data file contents as string: " + s);      
  ResponseBuilder builder = Response.status(Status.OK);        builder.type(MediaType.APPLICATION_JSON);        builder.entity("this is great!");        return builder.build();
Jersey Log:
7* In-bound request received7> POSThttp://localhost:8080/force-rest-1.0/portal/campaign7> content-length: 2497> connection: keep-alive7> host: localhost:80807> user-agent: Java/1.6.0_187> content-type: multipart/form-data;boundary=Boundary_1_18429817_12692308369547> accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.27> mime-version: 1.07> --Boundary_1_18429817_1269230836954Content-Disposition: form-data;name="media"Content-Type: multipart/form-dataGIF89a.................................--Boundary_1_18429817_1269230836954--A message body reader for Java type, class com.sun.jersey.multipart.FormDataMultiPart, and MIME media type, multipart/form-data;boundary=Boundary_1_18429817_1269230836954, was not found7< 4157<