quarkusmultipartform-dataresteasyquarkus-rest-client

Quarkus REST Client - 411 Length Required when uploading file to Fortinet appliance


I'm using Quarkus to POST a file to an external Fortinet appliance. However, the service enforces strict HTTP protocol constraints and returns:

411 Length Required

The Quarkus REST client interface:

@RegisterRestClient(configKey = "external-api")
@Path("upload")
public interface ExternalApi {
    @POST
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Produces(MediaType.APPLICATION_JSON)
    Response submitFile(ClientMultipartForm form);
}


@ApplicationScoped
public class SubmitFileHelper {

    @RestClient
    fortiNetApi fortiNetApi;

    public SubmitFileResponse submitFile(byte[] fileBytes, String originalFilename) {
        ClientMultipartForm form = createMultipartForm(fileBytes, originalFilename);
        return fortiNetApi.submitFile(form);
    }

    private ClientMultipartForm createMultipartForm(byte[] fileBytes, String originalFilename) {
        Buffer buffer = Buffer.buffer(fileBytes);

        return ClientMultipartForm.create()
                .binaryFileUpload("file", originalFilename, buffer, "application/octet-stream");
    }
}

When invoking submitFile(form), I consistently get a 411 Length Required from the Fortinet service. I do see that the Content-Length is being set in the debug logs..

I suspect the issue may be related to chunked transfer encoding, which Fortinet may be blocking due to its strict HTTP protocol constraints. I found something similar for Restlet where the solution was to disable chunking by buffering the request entity. Is there a Quarkus equivalent of this workaround?

Environment:

Quarkus 3.19.4 quarkus-rest-client-reactive Java 21

Any input from Quarkus/REST experts would be highly appreciated.

Solution given by geoand Change the max chunk size property to a value where you are confident it will be larger than the payload.


Solution

  • If the problem is that the server doesn't like chunks, then you need to make sure the REST Client doesn't chunk the input. This can be done by setting:

    quarkus.rest-client.max-chunk-size

    to a value larger than the expected payload.

    Note that this will change the max chunk size for all REST Clients, so you can also used:

    quarkus.rest-client."my-client".max-chunk-size to limit the scope of the change to specific clients.