从Resteasy 2.4升级到3.0.5后。我的文件上传不再有效。以下是相关内容。
界面:
@POST
@ClientResponseType(entityType = JAXBModule.class)
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_XML)
public Response upload(@MultipartForm FileUploadForm form);
FileUploadForm类
public class FileUploadForm {
@FormParam("file")
@PartType(MediaType.APPLICATION_OCTET_STREAM)
private InputStream data;
@FormParam("user")
@PartType(MediaType.TEXT_PLAIN)
private String user;
@FormParam("password")
@PartType(MediaType.TEXT_PLAIN)
private String password;
@FormParam("filename")
@PartType(MediaType.TEXT_PLAIN)
private String filename;
public FileUploadForm() {
}
public InputStream getData() {
return data;
}
public void setData(InputStream data) {
this.data = data;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
客户:
ResteasyClientBuilder rsb = new ResteasyClientBuilder();
ResteasyClient rsc = rsb.build();
ResteasyWebTarget target = rsc.target(BASEURL);
ModuleArchiveService client target.proxy(ModuleArchiveService.class);
FileUploadForm upload = new FileUploadForm();
upload.setUser("joe");
upload.setPassword("pwd");
upload.setFilename("image.jpg");
String fileToUpload = "testdata/image.jpg";
upload.setData(new FileInputStream(fileToUpload));
Response response = client.upload(upload);
错误消息:
javax.ws.rs.ProcessingException: Unable to invoke request
at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:249)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:407)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:102)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:62)
at com.sun.proxy.$Proxy26.upload(Unknown Source)
at nz.org.riskscape.archive.rest.LiveModuleArchiveServiceTest.testUploadFile(LiveModuleArchiveServiceTest.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: javax.ws.rs.ProcessingException: could not find writer for content-type multipart/form-data type: nz.org.riskscape.archive.rest.domain.FileUploadForm
….
我在类路径中有resteasy-multipart-provider-3.0.5.Final.jar。我使用的是Java 7和Tomcat 7.0.42
答案 0 :(得分:0)
你是否在类路径中有jaxrs-api-3.0.5.Final.jar?
答案 1 :(得分:0)
显然这是一个非常了解的错误,请参阅https://issues.jboss.org/browse/RESTEASY-954。我希望它能在新的一年的下一个版本中得到解决