I think it would be easier to commit a test case.

The function I posted above works when I set up a multipart request with
commons-httpclient like this:

 HttpClient client = createClient();
        PostMethod method = new PostMethod(createUrl("gazetteer/new"));
        StringPart part = new StringPart("gazetteer", GAZ_TO_ADD);
        part.setContentType("application/json");
        Part[] parts = {part };
        method.setRequestEntity(new MultipartRequestEntity(parts,
method.getParams()));
        int status = client.executeMethod(method);
        assertEquals(HttpStatus.SC_OK, status);

This will not be urlencoded. There's another way to use the
commons-httpclient api to get that.
GAZ_TO_ADD is the json string.

On Sun, Oct 11, 2009 at 2:06 PM, Sergey Beryozkin <[email protected]
> wrote:

>
> By the way, Benson, can you please post a sample request, as seen on the
> wire
> ?
> I'd like to see if the JSON sequence is actually form-urlencoded ?
> cheers, Sergey
>
>
> Sergey Beryozkin wrote:
> >
> > Hi Benson
> >
> > AFAIK multipart/form-data is mainly used to submit files from the forms
> > [1], though individual parts may contain
> > "application/x-www-form-urlencoded" data, this is my interpretation at
> > least and this is how I implemented the way multipart/form-data is
> > handled. So it should really be :
> >     @Consumes("multipart/form-data")
> >     public Response addGazetteer(@FormParam("gazetter")  String
> gazetteer)
> > {
> >     }
> >
> > in other words CXF FormProvider will not delegate to other providers
> > (JAXB/JSON, etc) when dealing with "multipart/form-data"; perhaps it
> > should ?
> >
> > It is MultipartProvider which deals with multipart/related,
> > multipart/mixed, etc, which will delegate. It is this provider which will
> > notice @Multipart(type = "application/json").
> >
> > There's a couple of options. If you can actually afford specifying say
> > multipart/mixed then it will work as expected. Another option is to
> > register a simple RequestFilter impl which will change
> multipart/form-data
> > to say multipart/mixed. Finally you can do
> >
> > @Consumes("multipart/form-data")
> >     public Response addGazetteer(@FormParam("gazetter")  Gazetter
> > gazetteer) {
> >     }
> >
> > and register a ParameterHandler<Gazetter> which will use a JSONProvider
> to
> > convert a JSON sequence into Gazetter
> >
> > cheers, Sergey
> >
> > [1]http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2
> >
> >
> > bimargulies wrote:
> >>
> >> Oct 10, 2009 5:08:59 PM org.apache.cxf.jaxrs.utils.JAXRSUtils
> >> readFromMessageBody
> >> WARNING: .No message body reader found for request class : Gazetteer,
> >> ContentType :
> >> multipart/form-data;boundary=hxz8idwzzxgwwr7p0v1vregmn2wxnajqg0f_bxk6.
> >> Oct 10, 2009 5:08:59 PM
> >> org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
> >> WARNING: WebApplicationException has been caught : no cause is available
> >>
> >> And my function is:
> >>
> >>     @POST
> >>     @Path("/gazetteer/new")
> >>     @Consumes("multipart/form-data")
> >>     public Response addGazetteer(@Multipart(type = "application/json")
> >> Gazetteer gazetteer) {
> >>         try {
> >>             configDb.addGazetteer(gazetteer);
> >>         } catch (Exception e) {
> >>             return Response.status(500).build();
> >>         }
> >>         return Response.ok().build();
> >>     }
> >>
> >> The client sends a multipart form posting with JSON in the one and only
> >> part, and I expect it to get mapped. What am I missing?
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/JAX-RS-form-reading%2C-I%27m-stumped-tp25838462p25846016.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
>

Reply via email to