Jaxrs multipart

前端 未结 3 1625
你的背包
你的背包 2021-02-20 16:39

I\'m trying to perform a request to a jaxrs service which has media type set to multipart/form-data. This request contains a list of entities(xml) and an image(png,

相关标签:
3条回答
  • 2021-02-20 17:11

    Indeed I find it hard to understand why the JAX-RS spec doesn't standardize a support for this (I've just created https://java.net/jira/browse/JAX_RS_SPEC-413 to address this).

    However it is nevertheless possible to support multi-part forms in an implementation independent fashion. Either you write your own MessageBodyReader for MultiPart form or you use a library like Apache Clerezza jaxrs.utils which provide a MultiPartBody object which respective MessageBodyReader. This library has no implementation specification dependency so your application will run on any jax-rs implementation.

    For an example on how Clerezza jaxrs.utils is used see line 105 in http://svn.apache.org/viewvc/stanbol/trunk/development/archetypes/stateless-webmodule/src/main/resources/archetype-resources/src/main/java/MultiEnhancer.java?revision=1465777&view=markup. If you're not using OSGi (with white-board registration of resources) you will have to add to org.apache.clerezza.jaxrs.utils.form.MultiPartFormMessageBodyReader to your Application.

    0 讨论(0)
  • 2021-02-20 17:24

    I do not wish to include any libraries from apache.cxf, resteasy or anything of the sort. All I want to rely on is the jaxrs api

    You can't "rely on" the API, since it contains only interfaces. Classes that implement that interfaces come from RESTeasy, or Jersey, or CXF.

    and a 415 when I run the request towards an embedded openejb

    415 means "Method not supported", which happens when you send GET request to a PUT-expecting resource.

    I would recommend to use POST instead of PUT in this case. I suspect that @FormParam is not suitable to work with PUT, in your particular case.

    0 讨论(0)
  • 2021-02-20 17:34

    I have implemented this in Glassfish 4 without coupling with Jersey. @See this post for details

    0 讨论(0)
提交回复
热议问题