简体   繁体   中英

org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=multipart/form-data

I am writing Client-side code in the Jersey framework where I need to send a YAML file that will have configuration details. I am continuously having exception

MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=multipart/form-data.

I am not sure where the exact issue lies. Here is the snippet of my code. In the headerParam, I am having auth token which I need to submit.

Invocation.Builder invocationBuilder =  null;
WebTarget target = _client.target(url);
invocationBuilder = target.request(MediaType.MULTIPART_FORM_DATA_TYPE);
if(headerParam.size()!=0){
    MultivaluedMap<String, Object> multivaluedMap = new MultivaluedHashMap<>(headerParam);
    invocationBuilder.headers(multivaluedMap);
}
MultiPart multiPart = new MultiPart();
log.info(methodName+"Hello");
FileDataBodyPart fileDataBodypart = new FileDataBodyPart("file",new File(path));
multiPart.bodyPart(fileDataBodypart);
    
Response response = invocationBuilder.post(Entity.entity(multiPart,MediaType.MULTIPART_FORM_DATA_TYPE ));
log.info(methodName+"so reponse is : "+response);

I have added pom dependency in pom file also.

<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-multipart</artifactId>
    <version>2.22</version>
</dependency>

Can someone help why this issue is coming. Is there an issue with versioning or something else.

You have the multipart dependency, but you still need to register the MultiPartFeature with either the Client or the WebTarget

_client.register(MultiPartFeature.class);
// or
target.register(MultiPartFeature.class);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM