flowable/flowable-engine · error · FlowableIllegalStateException

Cannot set both body and form parameters

Error message

Cannot set both body and form parameters

What it means

HttpRequest forbids combining a String body with form parameters. setBody throws FlowableIllegalStateException when formParameters is non-empty, since a request is either form-encoded or carries a raw body, not both.

Solutions

  1. Drop setBody and add the data as form parameters, or clear the form parameters before setting a body
  2. Use a fresh HttpRequest for the raw-body request
  3. Structure the builder code so a request picks exactly one payload mode (body | bodyBytes | form | multipart) up front

Example fix

// before
request.addFormParameter("a", "1");
request.setBody("raw"); // throws
// after
request.addFormParameter("a", "1"); // form mode only
// or: request.setBody("a=1&raw=..."); // encode manually in the body
Defensive patterns

Strategy: validation

Validate before calling

if (request.getFormParameters() != null && !request.getFormParameters().isEmpty()) {
    throw new IllegalStateException("Request is form-encoded; cannot also set a String body");
}
request.setBody(body);

Type guard

boolean canSetStringBody(HttpRequest r) {
    return r.getFormParameters() == null || r.getFormParameters().isEmpty();
}

Try / catch

try {
    request.setBody(body);
} catch (FlowableIllegalStateException e) {
    request = new HttpRequest();
    request.setBody(body); // form params dropped
}

Prevention

When it happens

Trigger: Calling request.setBody(text) after addFormParameter(...) populated form parameters on the same instance.

Common situations: Trying to send extra key/value fields plus a custom body on one request; reusing a request prepared for form submission in a raw-body context.

Related errors


AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11). Data as JSON: /api/errors/a96037437ec6760a. Report an issue: GitHub.

Appendix: source

Thrown at modules/flowable-http-common/src/main/java/org/flowable/http/common/api/HttpRequest.java:107

    public String getSecureHttpHeadersAsString() {
        return secureHttpHeaders != null ? secureHttpHeaders.formatAsString(true) : null;
    }

    public void setSecureHttpHeaders(HttpHeaders secureHttpHeaders) {
        this.secureHttpHeaders = secureHttpHeaders;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        if (bodyBytes != null) {
            throw new FlowableIllegalStateException("Cannot set both body and body bytes");
        } else if (multiValueParts != null && !multiValueParts.isEmpty()) {
            throw new FlowableIllegalStateException("Cannot set both body and multi value parts");
        } else if (formParameters != null && !formParameters.isEmpty()) {
            throw new FlowableIllegalStateException("Cannot set both body and form parameters");
        }
        this.body = body;
    }

    public String getBodyEncoding() {
        return bodyEncoding;
    }

    public void setBodyEncoding(String bodyEncoding) {
        this.bodyEncoding = bodyEncoding;
    }

    public byte[] getBodyBytes() {
        return bodyBytes;
    }

    public void setBodyBytes(byte[] bodyBytes) {
        if (body != null) {

View on GitHub (pinned to d6d39ce1c6)