Apparently this is a very well know bug, see https://issues.jboss.org/browse/RESTEASY-954. I am hoping it will be indeed fixed by the next release in the new year
File upload no longer works after upgrading from RESTEasy 2.4.3 to 3.0.1
Question
After upgrading from Resteasy 2.4 to 3.0.5. my file upload is no longer working. Here are the relevant bits.
The interface:
@POST
@ClientResponseType(entityType = JAXBModule.class)
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_XML)
public Response upload(@MultipartForm FileUploadForm form);
The FileUploadForm class
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;
}
The client:
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);
The error message:
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
….
I have resteasy-multipart-provider-3.0.5.Final.jar in the class path. I am using Java 7 and Tomcat 7.0.42
La solution 2
Autres conseils
Do you have jaxrs-api-3.0.5.Final.jar in the class path?
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow