0

I am using jaxrs-ri-2.01 I would like to get in a parameter the binary data that is sent in the body of my HTTP PUT request.

I have found one annotation that should do the trick :

@FormDataParam

but it does not seem to be available for the jaxrs-ri-2.01

I would like to know:

  1. if there's a way I can do it with this jaxrs-ri version
  2. if it's mandatory to change jaxrs-ri version to a more recent one
  3. how to use this annotation

Thank you in advance for your answers!

1 Answers1

0
  1. if there's a way I can do it with this jaxrs-ri version

You need the jersey-media-multipart. This has the multipart support. If you are using Maven, add

<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-multipart</artifactId>
    <version>2.0.1</version> <!-- or whatever version
</dependency>                     you plan to use. -->

If you are not using Maven, you can find the download here. Scroll down and select the Jersey version you are using. Then click the Download (Jar) button to download. You will also need the mimepull jar that goes with it. To find it, scroll down and click version button that goes with mimepull.

  1. if it's mandatory to change jaxrs-ri version to a more recent one

Any 2.x version will have the multipart support in a different artifact, as mentioned above.

  1. how to use this annotation

First you will need to register the MultiPartFeature. See here for help. Then just do something like

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response post(@FormDataParam("file") InputStream file) {
   ...
}

See Also (for details and examples):

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
  • I'm on it, I downloaded jersey-media-multipart-2.0.1.jar and mimepull-1.8.jar. I added them to my project. I also added the @ Consumes and @ FormDataParam parameter. But now I have an error, both at launch of Tomcat and when sending the PUT request: WARNING: No injection source found for a parameter of type public javax.ws.rs.core.Response –  Nov 27 '15 at 14:14
  • Did you register the `MultiPartFeature`? – Paul Samsotha Nov 27 '15 at 14:20
  • If you mean that, the **@ Consumes(MediaType.MULTIPART_FORM_DATA)** is there and I also added **import javax.ws.rs.core.MediaType;** and also **import org.glassfish.jersey.media.multipart.FormDataParam;** . I see no errors in the "Problems" tab of Eclipse after compilation. –  Nov 27 '15 at 14:25
  • Please read the link I provided about registering the feature – Paul Samsotha Nov 27 '15 at 14:25
  • Indeed, I missed that link. So I added in my web.xml ** jersey.config.server.provider.classnames org.glassfish.jersey.media.multipart.MultiPartFeature ** and now, no more errors, I need to test further, but I would say it's OK now. –  Nov 27 '15 at 15:18
  • Thanks again **peeskillet** I think it's the second time you helped me successfully! –  Nov 27 '15 at 15:20