I am using Jersey based restful Service implementation strategy to build a service which will be used to upload files. My service class name is : UploadFileService.java (See
Register MultiPartFeature. In web.xml add to the Jersey servlet:
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
</init-param>
I had the same problem when I tried to upload the file. I spent a lot of time until I found a solution to the problem.
1.If you changed version of your JARs files you may have a version conflicts!
Clean up your artifacts/libs and rebuild project.
2.You need to register your UploadFileService class too:
register(MultiPartFeature.class);
register(UploadFileService.class);
Hope it will help someone and save your time.
If someone is using @FormDataParam
with @ApiOperation
swagger annotation, it won't work(as per swagger latest version at this time) as mentioned here:
https://github.com/swagger-api/swagger-ui/issues/169
I too got the same exception.I did the following changes in web.xml
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.filter.LoggingFilter;org.glassfish.jersey.moxy.json.MoxyFeature;org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
</init-param>
and changed jersey 2.7 to 2.9 .I do not know what change of this 2 has solved the issue.
Get rid of jersey-multipart-1.18.jar
. That is for Jersey 1.x. Add these two
For Maven you would use the following dependency (you don't need to explicitly add the mimepull
dependency, as this one will pull it in).
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.17</version> <!-- Make sure the Jersey version matches
the one you are currently using -->
</dependency>
Then you need to register the MultiPartFeature
. If you are using a ResourceConfig
for configuration, you can simply do
register(MultiPartFeature.class);
If you are using web.xml, then you can add the class as an <init-param>
to the Jersey servlet
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
</init-param>
Note that if you have multiple providers that you want to register, then you can delimit each provider class with a comma or semicolon. You cannot use this same param-name
twice. See Suarabh's answer
UPDATE
Also, once you get rid of jersey-multipart-1.18.jar
you will have compile errors for the missing imported classes. For the most part, the class names are still the same, just the packages have changed, i.e.
If you're using Dropwizard, instead of adding the jersey-media-multipart
, they document for your to add dropwizard-forms
instead. And instead of registering the MultiPartFeature
, you should register the MultiPartBundle
@Override
public void initialize(Bootstrap<ExampleConfiguration> bootstrap) {
bootstrap.addBundle(new MultiPartBundle());
}
Really doesn't make much difference though as all the Dropwizard bundle does is register the MultiPartFeature
with the ResourceConfig.
If you are here for a different ModelValidationException
, here are some links for information on other causes of the exception.
Yet another possible cause for this very generic error is that Jersey only searches for factories associated with the last annotation when multiple ones are declared on a param. (See bug report)
Until this is fixed, if you are using any other annotations besides @FormDataParam
, it has to come last.
This works:
@NotEmpty @FormDataParam("myParam") String myParam
This does not:
@FormDataParam("myParam") @NotEmpty String myParam