{"record":{"id":"181056cbd358f708","repo":"quarkusio/quarkus","slug":"unsupported-media-type-or-encoding-format-conte","errorCode":null,"errorMessage":"Unsupported media type or encoding format: ${contentType}","messagePattern":"Unsupported media type or encoding format: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/smallrye-reactive-messaging-pulsar/runtime/src/main/java/io/quarkus/pulsar/runtime/graal/Substitutions.java","lineNumber":39,"sourceCode":"final class Target_com_scurrilous_circe_checksum_Crc32cIntChecksum {\n\n    @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias)\n    @Alias\n    private static IntHash CRC32C_HASH = new Java8IntHash();\n\n}\n\n@TargetClass(className = \"org.apache.pulsar.client.impl.auth.oauth2.ClientCredentialsFlow\")\nfinal class Target_org_apache_pulsaR_client_impl_auth_oauth2_ClientCredentialsFlow {\n\n    @Substitute\n    private static KeyFile loadPrivateKey(String privateKeyURL) throws IOException {\n        try {\n            URLConnection urlConnection = new org.apache.pulsar.client.api.url.URL(privateKeyURL).openConnection();\n            try {\n                String protocol = urlConnection.getURL().getProtocol();\n                if (\"data\".equals(protocol) && !\"application/json\".equals(urlConnection.getContentType())) {\n                    throw new IllegalArgumentException(\n                            \"Unsupported media type or encoding format: \" + urlConnection.getContentType());\n                }\n                KeyFile privateKey;\n                try (Reader r = new InputStreamReader(urlConnection.getInputStream(), StandardCharsets.UTF_8)) {\n                    privateKey = KeyFile.fromJson(r);\n                }\n                return privateKey;\n            } finally {\n                IOUtils.close(urlConnection);\n            }\n        } catch (URISyntaxException | InstantiationException | IllegalAccessException e) {\n            throw new IOException(\"Invalid privateKey format\", e);\n        }\n    }\n\n}\n","sourceCodeStart":21,"sourceCodeEnd":56,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/smallrye-reactive-messaging-pulsar/runtime/src/main/java/io/quarkus/pulsar/runtime/graal/Substitutions.java#L21-L56","documentation":"A Graal substitution replacing Pulsar's KeyFileLoader private-key loading for native compatibility. When the key URL uses the 'data:' protocol, the substitution only accepts application/json content type and throws IllegalArgumentException for any other media type, since data URIs must carry the JSON key file.","triggerScenarios":"Configuring a Pulsar client token/key pair with a data: URI whose media type is not application/json (e.g. data:text/plain;base64,...) for authPrivateKey/authPublicKey in native mode.","commonSituations":"Embedding base64 private keys in config using data:text/plain or data:application/x-pem-file URIs; hand-built data URIs missing the application/json type.","solutions":["Use data:application/json;base64,<base64-encoded JSON key file> for the key URI","Store the key in a file and reference it via file: URL instead of a data URI","Verify the data URI media type matches application/json exactly"],"exampleFix":"// before\nString key = \"data:text/plain;base64,\" + Base64.getEncoder().encodeToString(jsonKeyBytes);\n// after\nString key = \"data:application/json;base64,\" + Base64.getEncoder().encodeToString(jsonKeyBytes);","handlingStrategy":"validation","validationCode":"static String toValidKeyDataUri(Path jsonKeyFile) throws IOException {\n    byte[] bytes = Files.readAllBytes(jsonKeyFile);\n    return \"data:application/json;base64,\" + Base64.getEncoder().encodeToString(bytes);\n}\n// call before configuring the client: ensure the file parses as JSON\nnew String(bytes, StandardCharsets.UTF_8).trim().startsWith(\"{\");","typeGuard":"static boolean isValidJsonDataUri(String uri) {\n    return uri != null && uri.startsWith(\"data:application/json\");\n}","tryCatchPattern":"try {\n    client = PulsarClient.builder().serviceUrl(url)\n        .auth(AuthenticationFactory.token(...))\n        .authentication(AuthenticationTLS).build();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Unsupported media type\")) {\n        throw new ConfigurationException(\"Key data: URI must use media type application/json\", e);\n    }\n    throw e;\n}","preventionTips":["Always encode Pulsar key files as data:application/json;base64,...","Prefer file: URLs over data: URIs for key material","Validate the key file is Pulsar JSON format (not PEM) before configuring auth"],"tags":["pulsar","native-image","auth","media-type","config"],"backgroundTag":"unsupported-media-type","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}