Paul:Thanks for your mail. I did not resolve the previous issue,but I moved on to use "FormDataMultiPart" instead of Form.Here is the relevant portion of the pom.xml <dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
</dependency>
My class loader delegate is set to true :
<class-loader delegate="true"/>
The problem still persists.
Suresh
Hi Suresh,
I presume you resolved your issue you sent in a previous email? GF
v2.1.1 comes pre-installed with Jersey 1.0.3.1 and this causes a
conflict if a later version of Jersey is included in the war. So one
needs to either set class loader delegation to false or upgrade using
the update center.
Have you included the jersey multipart dependency? Note that Jersey
1.1.4 installed on GFv2.1.1 via the update center does not come with
jersey-multipart support so you need to include that yourself in the
war.
Paul.
On Mar 22, 2010, at 6:51 AM, Suresh Kumar wrote:
> This is my environment:
>
> Jersey: 1.1.4
> Glassfish: V2.1.1
> JDK : 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 a
> 415.
>
> 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 received
> 7
> >
> POST
> http://localhost:8080/force-rest-1.0/portal/campaign
> 7
> >
> content-length
> :
> 249
> 7
> >
> connection
> :
> keep-alive
> 7
> >
> host
> :
> localhost:8080
> 7
> >
> user-agent
> :
> Java/1.6.0_18
> 7
> >
> content-type
> :
> multipart/form-data;boundary=Boundary_1_18429817_1269230836954
> 7
> >
> accept
> :
> text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
> 7
> >
> mime-version
> :
> 1.0
> 7
> >
> --Boundary_1_18429817_1269230836954
> Content-Disposition: form-data;name="media"
> Content-Type: multipart/form-data
> GIF89a.................................
> --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 found
> 7
> <
> 415
> 7
> <
>