iflytek/astron-agent · error · RuntimeException
assemble requestUrl error:
Error message
assemble requestUrl error:
What it means
assembleAuthURL builds a percent-encoded query string from request parameters using URLEncoder. If encoding any key/value throws (e.g. an unsupported charset name at runtime), the lambda wraps it in a RuntimeException with the message 'assemble requestUrl error:'. It is a defensive catch-all; under normal UTF-8 setup it should never fire.
Solutions
- Verify the JVM supports the UTF-8 charset (standard JVMs do; a custom/minimal JRE may not)
- Prefer the overload URLEncoder.encode(value, StandardCharsets.UTF_8) (Java 10+) so no charset-name lookup happens
- Improve the wrapper to preserve the cause: new RuntimeException(e) instead of only e.getMessage()
- Log the offending key/value type to pinpoint which entry failed encoding
Example fix
// before URLEncoder.encode(entry.getKey(), String.valueOf(StandardCharsets.UTF_8)) // after URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8)
Defensive patterns
Strategy: try-catch
Validate before calling
if (params == null || params.isEmpty()) throw new IllegalArgumentException("auth params required"); Try / catch
try { String url = AuthStringUtil.assembleAuthURL(baseUrl, params); } catch (RuntimeException e) { log.error("auth URL assembly failed: {}", e.getMessage(), e); throw new ServiceException("Unable to build auth URL"); } Prevention
- Use the Charset-object URLEncoder overload (Java 10+) to avoid charset-name lookup failures
- Run on a standard JVM that guarantees UTF-8 support
- Log the full cause, not just getMessage(), when wrapping exceptions
When it happens
Trigger: Calling AuthStringUtil.assembleAuthURL with a parameter map whose key or value fails URLEncoder.encode — practically only when String.valueOf(StandardCharsets.UTF_8) cannot resolve to a supported charset in a stripped/restricted JVM environment.
Common situations: Running on a minimal JRE without the UTF-8 charset provider; exotic custom security policies blocking charset lookup; repackaging the utility into an environment with a broken java.nio.charset setup.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/b0b65d3990226370.
Report an issue: GitHub.
Appendix: source
Thrown at console/backend/commons/src/main/java/com/iflytek/astron/console/commons/util/AuthStringUtil.java:80
String authParam = String.format("hmac-auth api_key=\"%s\", algorithm=\"%s\", headers=\"%s\", signature=\"%s\"",
apiKey, "hmac-sha256", "host date request-line digest", sha);
String authorization = Base64.getEncoder().encodeToString(authParam.getBytes(charset));
Map<String, String> header = new HashMap<>();
header.put("authorization", authorization);
header.put("host", host);
header.put("date", date);
header.put("digest", digest);
// Get authentication parameters
return uri + "?" + header.entrySet()
.stream()
.map(entry -> {
try {
return URLEncoder.encode(entry.getKey(), String.valueOf(StandardCharsets.UTF_8)) + "=" +
URLEncoder.encode(entry.getValue(), String.valueOf(StandardCharsets.UTF_8));
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
})
.collect(Collectors.joining("&"));
}
/**
* Generate URL for authentication
*/
public static String assembleRequestUrl(String requestUrl, String method, String apiKey, String apiSecret) {
URL url;
String httpRequestUrl = requestUrl.replace("ws://", "http://").replace("wss://", "https://");
try {
url = new URL(httpRequestUrl);
SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
String date = format.format(new Date());
String host = url.getHost();
String builder = "host: " + host + "\n" +View on GitHub (pinned to 5e758547a8)