Skip to content

Custom multipart/form-data parser #53516

@piu130

Description

@piu130

Describe the bug

I have the following RestClient:

@RegisterRestClient
interface Adapter {
    @POST
    @Path("batch")
    @Consumes(MediaType.WILDCARD)
    @Produces(MediaType.MULTIPART_FORM_DATA)
    fun batch(body: File): Response
}

This prints the exception:

Caused by: org.jboss.resteasy.reactive.client.api.InvalidRestClientDefinitionException: Failed to generate client for class interface Adapter : Endpoints that produce a Multipart result cannot return 'jakarta.ws.rs.core.Response' - consider returning 'org.jboss.resteasy.reactive.RestResponse' instead.
Offending method is 'Adapter#jakarta.ws.rs.core.Response batch(java.io.File body)'
at org.jboss.resteasy.reactive.client.impl.ClientProxies.get(ClientProxies.java:31)
at org.jboss.resteasy.reactive.client.impl.WebTargetImpl.proxy(WebTargetImpl.java:465)

Changing Response to RestResponse<*> prints the exception:

Caused by: org.jboss.resteasy.reactive.client.api.InvalidRestClientDefinitionException: Failed to generate client for class interface Adapter : multipart responses can only be mapped to non-generic classes, got org.jboss.resteasy.reactive.RestResponse<?> of type: PARAMETERIZED_TYPE
at org.jboss.resteasy.reactive.client.impl.ClientProxies.get(ClientProxies.java:31)
at org.jboss.resteasy.reactive.client.impl.WebTargetImpl.proxy(WebTargetImpl.java:465)
at io.quarkus.rest.client.reactive.runtime.RestClientBuilderImpl.build(RestClientBuilderImpl.java:709)

Using InputStream:

Caused by: java.lang.ClassNotFoundException: java.io.InputStream$$MultipartData
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:537)
at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:526)
at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:537)
at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:526)

Expected behavior

One of the examples above should not throw an exception so I can write my own multipart/form-data parser.

Actual behavior

There is currently no way to write a custom multipart/form-data parser.

How to Reproduce?

I've created a small project here to demonstrate the problem. You can run the tests inside src/test/java/org/acme to see the different errors.

Output of uname -a or ver

No response

Output of java -version

OpenJDK Runtime Environment Zulu25.32+20-SA (build 25.0.2+10-LTS)

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.11

Additional information

I need to write a custom multipart/form-data parser, because I cannot access custom part headers in any way. Example:

--6c86abe4-f032-4db9-91ef-18a6a8ab93a8
Content-Disposition: form-data; name="pdf1"
Content-Type: application/pdf

[pdf1 content]
--6c86abe4-f032-4db9-91ef-18a6a8ab93a8
Content-Disposition: form-data; name="pdf2"
Content-Type: application/pdf
Content-Range: bytes 0-1023/146515

[pdf2 content]
--6c86abe4-f032-4db9-91ef-18a6a8ab93a8--

There is no way to access pdf2["Content-Range"] header.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions