javax.ws.rs.ProcessingException:RESTEASY004655:无法调用请求
javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request
作为 客户,我正在尝试使用 RestEasy 3.0 将 post zip 文件转换为 "Restservice"。 19。
这是代码:
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
我该如何解决这个问题?我查看了一些 posts,但代码与我的略有不同。
谢谢大家
您正在混合使用两个不同的 HTTP 客户端 RESTEasy and Apache HttpClient。这是仅使用 RESTEasy 的代码
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 才能运行:
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>
作为 客户,我正在尝试使用 RestEasy 3.0 将 post zip 文件转换为 "Restservice"。 19。 这是代码:
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
我该如何解决这个问题?我查看了一些 posts,但代码与我的略有不同。
谢谢大家
您正在混合使用两个不同的 HTTP 客户端 RESTEasy and Apache HttpClient。这是仅使用 RESTEasy 的代码
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 才能运行:
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>