Tomee MultipartProvider didn't consider body as readable

63 Views Asked by At

During my java migration (8 to 17), I experienced some problems with Tomee plus 8.0.15 (inderectly Apache CXF, cxf shade 3.5.5).

In my application, I use multipart/form-data in some requests, because some forms send classic values (like String, Long) and a file. The main problem is that Tomee don't use the class MultipartProvider which is in charge to split the form-data body and provide the correct values in parameters. Instead of that, it fill the first variable with the all content of the request.

Example of my resource, using the recommended way by Apache CXF.

// imports ...

@Path("/test")
@Stateless
public class MyResource {
  // ...

  @POST
  @Path("/{id}")
  @Consumes("multipart/form-data")
  public Response edit(
    @PathParam("id") Long id, 
    @Multipart("name") String name,
    @Multipart("file") Attachment image
  ) {

    // DOING some stuff with name

    return Response.ok().build();
  }

  // ...
}

After some hours of debugging, I found the reason. The method MultipartProvider#isSupported is clearly called but the result is false. It is essentially due to AnnotationUtils.getAnnotation(anns, Multipart.class) that returns false.

When I inpect Annotation[] anns variable, it is not really a table of Annotation but rather Java Proxy. So when getAnnotation checks type of the annotation, the result is false.

So my questions are :

  1. What can i do to have all things work without changing my method signature ?
  2. Why Annotation are Proxy ?
  3. Is it a configuration, compilation or library problem ?

Thanks for reading and hope you understood me.

NB : I knew the solution with MultivaluedMap or MultipartBody.

Informations about environnement:

JDK used : openjdk
Java version : 17
Gradle version : 7.3.3
Tomee version : 8.0.15 (Plus version)
Gradle dependencies : Nothing about apache cxf that can be entered in conflict with Tomee.
0

There are 0 best solutions below