My whole rest service stops working when I'm adding this code:
@PUT
@Path("upload/{id}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void addBlob(@PathParam("id") Integer id, @FormDataParam("file") InputStream uploadedInputStream) throws IOException {
TheTempClient entityToMerge = find(id);
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
int read = 0;
byte[] bytes = new byte[1024];
while ((read = uploadedInputStream.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
entityToMerge.setTestBlob(out.toByteArray());
super.edit(entityToMerge);
}
catch (IOException e) {
e.printStackTrace();
}
}
It doesn't really say why either, all I'm getting is:
Severe: WebModule[/MavenProjectTest]StandardWrapper.Throwable
org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.
And a bunch of errors saying " caused by previous errors "
I must have done something really wrong here, are there any proffessional JPA enthusiasts that can help me out a little bit here?
Edit: I'm using annotations instead of web.xml, is it possible to do this without a web.xml?
I had to add register(MultiPartFeature.class);
in the ApplicationConfig.java
class, like this:
@javax.ws.rs.ApplicationPath("api")
public class ApplicationConfig extends ResourceConfig {
public ApplicationConfig() {
packages("com.test.thepackage.service");
register(MultiPartFeature.class);
}
}
Now it works like a charm, without a web.xml file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With