quarkusio/quarkus · error · NotAcceptableException

The accept header value did not match the value in @Produces

Error message

The accept header value did not match the value in @Produces

What it means

RESTEasy Reactive throws this NotAcceptableException (HTTP 406) when the client's Accept header is valid but none of its media types are compatible with the @Produces media types of the target resource method. validateProduces iterates all Accept headers, and if at least one parsed successfully (sawParseableAccept true) but hasAtLeastOneMatch stayed false, it throws this exception per the JAX-RS spec's content negotiation rules.

Source

Thrown at independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/HandlerMediaTypeUtil.java:73

                boolean hasAtLeastOneMatch = false;
                boolean sawParseableAccept = false;
                for (int i = 0; i < accepts.size(); i++) {
                    try {
                        boolean matches = acceptHeaderMatches(target, accepts.get(i));
                        sawParseableAccept = true;
                        if (matches) {
                            hasAtLeastOneMatch = true;
                            break;
                        }
                    } catch (IllegalArgumentException ignored) {
                        // the provided header contained no parseable media type tokens
                    }
                }
                if (!hasAtLeastOneMatch) {
                    if (!sawParseableAccept) {
                        throw new BadRequestException(MALFORMED_ACCEPT_HEADER_MESSAGE);
                    }
                    throw new NotAcceptableException(INVALID_ACCEPT_HEADER_MESSAGE);
                }
            }

            requestContext.setProducesChecked(true);
        }
    }

    /**
     * @return {@code true} if the provided string matches one of the {@code @Produces} values of the resource method
     * @throws IllegalArgumentException if the provided string contains no parseable media type tokens
     */
    private static boolean acceptHeaderMatches(RequestMapper.RequestMatch<RuntimeResource> target, String accepts) {
        if ((accepts != null) && !accepts.equals(MediaType.WILDCARD)) {
            int commaIndex = accepts.indexOf(',');
            boolean multipleAcceptsValues = commaIndex >= 0;
            MediaType[] producesMediaTypes = target.value.getProduces().getSortedOriginalMediaTypes();
            if (!multipleAcceptsValues && (producesMediaTypes.length == 1)) {
                // the point of this branch is to eliminate any list creation or string indexing as none is needed

View on GitHub (pinned to e1c734241f)

Solutions

  1. Change the client's Accept header to include a media type the endpoint produces, e.g. 'Accept: application/json'.
  2. Add the requested media type to the server's @Produces and add a corresponding message body writer.
  3. Use 'Accept: */*' to accept any response media type the endpoint offers.

Example fix

// before (client)
GET /api/users  Accept: application/xml
// after
GET /api/users  Accept: application/json
Defensive patterns

Strategy: validation

Validate before calling

// ensure requested type is in the endpoint's @Produces set before calling
java.util.Set<String> produces = java.util.Set.of("application/json");
if (!produces.contains(requestedAccept)) {
    requestedAccept = "application/json"; // fall back to a produced type
}

Try / catch

try {
    return client.get();
} catch (NotAcceptableException e) {
    // HTTP 406: retry with Accept: */* or the documented produced type
    return client.accept("*/*").get();
}

Prevention

When it happens

Trigger: A request to a method with @Produces whose Accept header parses but matches nothing — e.g. 'Accept: application/xml' against @Produces(MediaType.APPLICATION_JSON), or 'Accept: text/csv' against an endpoint that only produces JSON.

Common situations: Browser sending 'Accept: text/html' to a JSON API endpoint; clients requesting a format (XML, CSV) the endpoint never implemented; API version changes that dropped a media type; misconfigured REST client content negotiators.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/c30a452d7a731354. Report an issue: GitHub.