Topic
3 replies Latest Post - ‏2013-04-04T13:57:08Z by SystemAdmin
SystemAdmin
SystemAdmin
590 Posts
ACCEPTED ANSWER

Pinned topic Multipart form data on liberty profile with jaxrs

‏2013-03-26T20:01:02Z |
I have tried several different ways to do the multipart form consumer using wiztools rest client to post data.
Tried this way with either BufferedInMultiPart or InMultiPart: I get a unsupported media type
http://pic.dhe.ibm.com/infocenter/wasinfo/v8r5/index.jsp?topic=%2Fcom.ibm.websphere.nd.doc%2Fae%2Ftwbs_jaxrs_multipart_formdata_from_html.html

And this way using cxf: If i use more than 1 parameters coming in, i get a 404. If i only have one @Multipart, then all the values go into that one, even though I specify the name i'm wanting to get. I get the content disp, type, tranfer-end and the data, then the next, and next, all into the first string value. How do I seperate this? Would of thought it would decode automatically.
http://stackoverflow.com/questions/15271573/consuming-a-multipart-form-data-via-restful-cxf

Tried a few of these too. All give me the unsupported media type.
http://cxf.apache.org/docs/jax-rs-multiparts.html

FormParam works, but I want it to be variable files. I am trying to send one xml document and anywhere from 0-6 image files.

I AM specifying the media type as "multipart/data-form". And my consumes is set to @Consumes(MediaType.MULTIPART_FORM_DATA)

@POST
@Path("/multi")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response multi(@Multipart(value="xml", type="text/xml", required=true) String xml) {
...
}

Any Ideas?
  • Jacek_Laskowski
    Jacek_Laskowski
    133 Posts
    ACCEPTED ANSWER

    Re: Multipart form data on liberty profile with jaxrs

    ‏2013-03-31T22:38:32Z  in response to SystemAdmin
    Hi,

    What about the following resource method?
    
    @POST @Path(
    "/multi") @Consumes(MediaType.MULTIPART_FORM_DATA) 
    
    public Response completeHandleMultipart( @FormParam(
    "xml") String theXml, @FormParam(
    "file") List<File> files) 
    { System.out.println(
    "theXML: " + theXml + 
    " and files: " + files.size()); 
    
    return Response.ok().build(); 
    }
    

    It worked fine for me with WizTools.org RESTClient (that I'd never used before so thanks for the pointer).

    Jacek
    Japila :: verba docent, exempla trahunt
  • Jacek_Laskowski
    Jacek_Laskowski
    133 Posts
    ACCEPTED ANSWER

    Re: Multipart form data on liberty profile with jaxrs

    ‏2013-04-01T20:33:58Z  in response to SystemAdmin
    Hi,

    As a more complete response I wrote an article Implementing RESTful services with JAX-RS and WebSphere 8.5 Liberty Profile that "aims at providing a complete environment with two sample RESTful service resources - HelloResource and MultipartResource - based upon JAX-RS with @GET, @POST, @Consumes with MediaType.MULTIPART_FORM_DATA and @FormParam annotations."

    Thanks for encouraging me to finally cross the item off from the TODO list of mine!

    Jacek
    Japila :: verba docent, exempla trahunt
    • SystemAdmin
      SystemAdmin
      590 Posts
      ACCEPTED ANSWER

      Re: Multipart form data on liberty profile with jaxrs

      ‏2013-04-04T13:57:08Z  in response to Jacek_Laskowski
      That is a help. I ended up going to BufferedInMultiPart. I needed the actual "name" field of each file from the form. So I could tell the difference between the desired files. There seems to be a wink bug with this method though. New question in new post.