Search code examples
multipartform-dataresteasyjboss-eap-7java-ee-8

Use resteasy multipart provider jboss module in a maven application


I am developing maven web application, in which I include the Java EE 8 standard API

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>8.0.1</version>
        <scope>provided</scope>
    </dependency>

I am deploying to JBoss EAP 7.2.9

In my application, I want to upload files to a JAX-RS Endpoint.

@POST
@Path("{id}/file-upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void uploadFile(@PathParam("id") Long id, @MultipartForm FileMetaData metaData) {}

FileMetaData

public class FileMetaData{
  @FormParam("name")
  private String name;
  
  @FormParam("type")
  private String type;

  @FormParam("file")
  @PartType("application/octet-stream")
  byte[] file;
}

The problem is @MultipartForm is not part of the standard JavaEE 8 API. To use it, I must include the resteasy multipart provider in my pom

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-multipart-provider</artifactId>
        <version>3.6.1.Final</version>
        <scope>provided</scope>
    </dependency>

I used the version provided by WildFly 14.0.0 which is the community counterpart of JBoss EAP 7.2.9. However, I am not sure whether this is the correct practice. JBoss EAP uses its own implementation of the module "resteasy-multipart-provider-3.6.1.SP9-redhat-00001.jar", which is located in a private maven repository.

In addition, I am still using the default implementations provided by JBoss for the Java EE APIs (including non-multipart JAX-RS endpoints), as I am not including any other specific dependencies in my pom.

  • could including the dependency above be a source of conflicts?
  • is there a way to depend on the module provided by JBoss without being bound to a specific JBoss version?

Solution

  • After more investigations, I found the following: to use a container module (e.g. jboss resteasy) in your application, add the dependency in your pom with scope provided, which means that this dependency will be provided at runtime by the container. Then you will notice that resteasy is not included in your WAR file.

    The version implemented by your container is the one used at runtime and not the version you provide in your pom.xml (here 3.6.1.SP9-redhat-00001 and not 3.6.1.Final).

    However, your code compiles against the version in pom, which should be less than or equal to the container provided version (assuming that higher versions from the container should always be backward compatible).