{"record":{"id":"474e00116eec0167","repo":"apache/pulsar","slug":"unsupported-media-type-or-encoding-format","errorCode":null,"errorMessage":"Unsupported media type or encoding format: ","messagePattern":"Unsupported media type or encoding format: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-client-auth-athenz/src/main/java/org/apache/pulsar/client/impl/auth/AuthenticationAthenz.java","lineNumber":322,"sourceCode":"        try {\n            java.net.URL url = new URL(urlString).openConnection().getURL();\n            checkArgument(\"file\".equals(url.getProtocol()), \"Unsupported protocol: %s\", url.getProtocol());\n            Path path = Paths.get(url.getPath());\n            return path.isAbsolute() ? path.toString() : path.toAbsolutePath().toString();\n        } catch (URISyntaxException e) {\n            throw new IllegalArgumentException(\"Invalid URL format\", e);\n        } catch (InstantiationException | IllegalAccessException | IOException e) {\n            throw new IllegalArgumentException(\"Cannnot get absolute path from specified URL\", e);\n        }\n    }\n\n    private static PrivateKey loadPrivateKey(String privateKeyURL) {\n        PrivateKey privateKey = null;\n        try {\n            URLConnection urlConnection = new URL(privateKeyURL).openConnection();\n            String protocol = urlConnection.getURL().getProtocol();\n            if (\"data\".equals(protocol) && !APPLICATION_X_PEM_FILE.equals(urlConnection.getContentType())) {\n                throw new IllegalArgumentException(\n                        \"Unsupported media type or encoding format: \" + urlConnection.getContentType());\n            }\n            String keyData = CharStreams.toString(new InputStreamReader((InputStream) urlConnection.getContent(),\n                    Charset.defaultCharset()));\n            privateKey = Crypto.loadPrivateKey(keyData);\n        } catch (URISyntaxException e) {\n            throw new IllegalArgumentException(\"Invalid privateKey format\", e);\n        } catch (CryptoException | InstantiationException | IllegalAccessException | IOException e) {\n            privateKey = null;\n        }\n        return privateKey;\n    }\n}\n","sourceCodeStart":304,"sourceCodeEnd":336,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-auth-athenz/src/main/java/org/apache/pulsar/client/impl/auth/AuthenticationAthenz.java#L304-L336","documentation":"loadPrivateKey accepts data: URIs only when their content type is exactly 'data:application/x-pem-file' (APPLICATION_X_PEM_FILE). Any other media type or encoding in the data URI causes IllegalArgumentException('Unsupported media type or encoding format: <contentType>').","triggerScenarios":"Passing a privateKey value like 'data:application/octet-stream;base64,...' or 'data:text/plain;base64,...' (wrong MIME type) to configure(); also firing when the data URI omits or misspells the media type.","commonSituations":"Users base64-encoding their PEM key but labeling it with the wrong content type, or omitting the ';base64' indicator; older docs/configs showing a different MIME label.","solutions":["Format the key as 'data:application/x-pem-file;base64,<base64 of PEM>'","If you have the raw PEM text, use the unencoded form 'data:application/x-pem-file,<pem text>' or a file:// privateKeyPath URL instead","Re-encode: base64 -w0 key.pem and paste with the exact media type shown above"],"exampleFix":"// before\n\"privateKey\":\"data:application/octet-stream;base64,LS0tLS1CRUdJTg==\"\n// after\n\"privateKey\":\"data:application/x-pem-file;base64,LS0tLS1CRUdJTg==\"","handlingStrategy":"validation","validationCode":"if (privateKeyValue.startsWith(\"data:\")) {\n    String meta = privateKeyValue.substring(5, privateKeyValue.indexOf(','));\n    if (!meta.startsWith(\"application/x-pem-file\")) {\n        throw new IllegalArgumentException(\"data URI must use media type application/x-pem-file, got: \" + meta);\n    }\n}","typeGuard":"boolean isPemDataUri(String s) {\n    return s != null && s.startsWith(\"data:application/x-pem-file,\");\n}","tryCatchPattern":"try {\n    authentication.configure(authParamsJson);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Unsupported media type\")) {\n        log.error(\"Re-encode the key as data:application/x-pem-file;base64,...\");\n    }\n    throw e;\n}","preventionTips":["Always label base64 keys with data:application/x-pem-file;base64,","Generate the URI programmatically (base64 -w0 key.pem) instead of hand-writing it","Never use generic types like application/octet-stream or text/plain for the key URI"],"tags":["java","athenz","pem","data-uri","auth-config"],"backgroundTag":"unsupported-media-type","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}