本文介绍了javax.ws.rs.ProcessingException:RESTEASY004655:无法调用请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试作为客户端使用 RestEasy 3.0.19 将zip文件发布到"Restservice".这是代码:
I'm trying, as a client, to post a zip file to a "Restservice", using RestEasy 3.0.19.This is the code:
public void postFileMethod(String URL) {
Response response = null;
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(URL);
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
FileBody fileBody = new FileBody(new File("C:/sample/sample.zip"),
ContentType.MULTIPART_FORM_DATA);
entityBuilder.addPart("my_file", fileBody);
response = target.request().post(Entity.entity(entityBuilder,
MediaType.MULTIPART_FORM_DATA));
}
我得到的错误是这个:
javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request
....
Caused by: javax.ws.rs.ProcessingException: RESTEASY003215: could not
find writer for content-type multipart/form-data type:
org.apache.http.entity.mime.MultipartEntityBuilder
我该如何解决这个问题?我查看了一些帖子,但是代码与我的代码略有不同.
How can I solve this problem? I looked into some posts, but the code is slightly different from mine.
谢谢你们.
推荐答案
您正在混合使用两个不同的HTTP客户端 RESTEasy 和 Apache HttpClient .这是仅使用RESTEasy的代码
You are mixing two different HTTP clients RESTEasy and Apache HttpClient. Here is the code which uses RESTEasy only
public void postFileMethod(String URL) throws FileNotFoundException {
Response response = null;
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(URL);
MultipartFormDataOutput mdo = new MultipartFormDataOutput();
mdo.addFormData("my_file", new FileInputStream(new File("C:/sample/sample.zip")), MediaType.APPLICATION_OCTET_STREAM_TYPE);
GenericEntity<MultipartFormDataOutput> entity = new GenericEntity<MultipartFormDataOutput>(mdo) { };
response = target.request().post(Entity.entity(entity,
MediaType.MULTIPART_FORM_DATA));
}
您需要具有resteasy-multipart-provider才能使其正常工作:
You need to have resteasy-multipart-provider to have it working:
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>
这篇关于javax.ws.rs.ProcessingException:RESTEASY004655:无法调用请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!