JPA attempt stops working when trying to load blob

All my rest service stops working when I add 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, all I get 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 mistakes saying "because of previous mistakes"

I must have done something really wrong, are there any professional JPA juniors that can help me a bit here?

Edit: I use annotations instead of web.xml, can this be done without web.xml?

+5
source share
1 answer

I had to add register(MultiPartFeature.class);

in the ApplicationConfig.java class, for example:

 @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.

+3
source

Source: https://habr.com/ru/post/1240693/


All Articles