users@jersey.java.net

Re: [Jersey] Message body reader not found - _at_Consumes( "multipart/form-data;boundary=\"foo\"" ) works but @Consumes( "multipart/form-data" ) does not

From: Martin Grotzke <martin.grotzke_at_freiheit.com>
Date: Thu, 31 Jul 2008 16:42:07 +0000

Hi Paul,

the difference for us is the c.type() of the client's webresource:

r.type("multipart/form-data;boundary=\"frontier\"")

  instead of

r.type("multipart/form-data")

Does the first type specification also work for you?

Our server side part looks like this:

    @POST
    @Path( "ugc" )
    @Consumes( "multipart/form-data" )
    public ProductList uploadContentForList(
            MultipartNameSource formData)


and

@Consumes( "multipart/form-data" )
@Provider
public class MimeMultipartReader implements
MessageBodyReader<MultipartNameSource>



Thanx && cheers,
Martin


On Thu, 2008-07-31 at 18:05 +0200, Paul Sandoz wrote:
> Hi Martin,
>
> The sample code at the end of the email works fine for me.
>
> What does the server-side code look like?
>
> Paul.
>
> public class App
> {
> public static class MyType {}
>
> @Consumes("multipart/form-data")
> @Provider
> public static class MimeMultipartReader implements
> MessageBodyReader<MyType> {
>
> public boolean isReadable(Class<?> arg0, Type arg1,
> Annotation[] arg2) {
> return MyType.class.isAssignableFrom(arg0);
> }
>
> public MyType readFrom(Class<MyType> arg0, Type arg1,
> Annotation[] arg2,
> MediaType arg3, MultivaluedMap<String, String> arg4,
> InputStream arg5) throws IOException, WebApplicationException {
> return new MyType();
> }
> }
>
> @Path("/helloworld")
> public static class HelloWorldResource {
>
> @POST
> @Produces("text/plain")
> @Consumes("multipart/form-data")
> public String getClichedMessage(MyType t) {
> // Return some cliched textual content
> return "Hello World";
> }
> }
>
> public static void client() {
> Client c = Client.create();
> WebResource r = c.resource("http://localhost:9998/helloworld");
> ClientResponse cr =
> r.type("multipart/form-data").post(ClientResponse.class, "1000");
> System.out.println(cr.getStatus());
> System.out.println(cr.getEntity(String.class));
> }
>
> public static void main( String[] args ) throws Exception {
> final String baseUri = "http://localhost:9998/";
> final Map<String, String> initParams = new HashMap<String,
> String>();
>
> initParams.put("com.sun.jersey.config.property.packages",
> "com.mycompany.mavenproject1");
>
> SelectorThread threadSelector =
> GrizzlyWebContainerFactory.create(baseUri, initParams);
> try {
> client();
> } catch (Exception e) {
> e.printStackTrace();
> } finally {
> threadSelector.stopEndpoint();
> System.exit(0);
>
> }
> }
> }
>
>
> Martin Grotzke wrote:
> > Hi,
> >
> > we're having issues with our MimeMultipartReader that - AFAIK - worked
> > before upgrading to the latest jersey (perhaps after the upgrade to
> > jsr311-0.9).
> >
> > When we run a test-case this fails with status 415 and this message in
> > the logs:
> >
> > Jul 31, 2008 3:33:35 PM com.sun.jersey.spi.container.ContainerRequest getEntity
> > SEVERE: A message body reader for Java type, interface com.app.proj.api.v1.commons.model.MultipartNameSource, and MIME media type, multipart/form-data;boundary=frontier, was not found
> >
> > The relevant part of the test-case looks like this:
> >
> > WebResource r = resource(path);
> > ClientResponse cr = r.type("multipart/form-data;boundary=\"frontier\"").post(ClientResponse.class, multipartRequest);
> > Assert.assertEquals(cr.getStatus(), Status.OK.getStatusCode());
> >
> > (This assertion fails)
> >
> > The MimeMultipartReader looks like this:
> >
> > @Consumes( "multipart/form-data" )
> > @Provider
> > public class MimeMultipartReader implements MessageBodyReader<MultipartNameSource> {
> > ...
> > }
> >
> >
> > Interestingly, if I change the value of @Consumes to
> >
> > @Consumes( "multipart/form-data;boundary=\"frontier\"" )
> >
> > the test goes through.
> >
> > Is this a bug or a feature?
> >
> > What would be the preferred solution for this?
> >
> > Thanx && cheers,
> > Martin
> >
> >