I am working on a project on which server-side I have used REST service for my APIS. If I use the REST service in the main function of a class, it is working fine. But when I calling it from a servlet that using Quarkus-resteasy, it throws exceptions. The exceptions are as follows.
javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request: javax.ws.rs.ProcessingException: RESTEASY003215: could not find writer for content-type multipart/form-data type: org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput
The main code of the servlet is as follows.
String httpURL = "REST api";
String filePath = "filePath";
ResteasyClient resteasyClient = null;
ResteasyWebTarget resteasyWebTarget = null;
MultipartFormDataOutput multipartFormDataOutput = null;
GenericEntity<MultipartFormDataOutput> genericEntity = null;
Response response = null;
try{
resteasyClient = new ResteasyClientBuilderImpl().build();
resteasyWebTarget = resteasyClient.target(httpURL);
resteasyWebTarget.property("Content-Type", MediaType.MULTIPART_FORM_DATA);
multipartFormDataOutput = new MultipartFormDataOutput();
multipartFormDataOutput.addFormData(
"file",
new FileInputStream(filePath),
MediaType.MULTIPART_FORM_DATA_TYPE,
"fileName");
genericEntity = new GenericEntity<MultipartFormDataOutput>(multipartFormDataOutput, MultipartFormDataOutput.class);
// invoke service
response = resteasyWebTarget
.request()
.post(Entity.entity(genericEntity, MediaType.MULTIPART_FORM_DATA));
The dependencies of the project are as follows.
implementation 'io.quarkus:quarkus-rest-client-jackson'
implementation 'io.quarkus:quarkus-rest-client'
implementation 'io.quarkus:quarkus-resteasy-multipart'
implementation 'io.quarkus:quarkus-resteasy'
implementation 'io.quarkus:quarkus-resteasy-jackson'
implementation 'io.quarkus:quarkus-arc'
testImplementation 'io.quarkus:quarkus-junit5'
testImplementation 'io.rest-assured:rest-assured'
The strange thing is that the same code in the main function of the class can run well. I have been troubled by this problem for a day, I would be grateful if you could help me.