alibaba/spring-ai-alibaba · error · IllegalStateException

HTTP request failed, status:

Error message

HTTP request failed, status: 

What it means

sendMessageToServer requires HTTP 200 from the remote A2A endpoint; any other status raises IllegalStateException("HTTP request failed, status: " + statusCode). This is a strict success-only check that surfaces non-200 responses (4xx/5xx, redirects) as exceptions inside the node.

Solutions

  1. Read the status code in the exception and check the remote server logs for the corresponding error
  2. Correct the AgentCard.url path so it hits the JSON-RPC endpoint exactly
  3. Add required authentication headers if the endpoint returns 401/403
  4. Enable/follow the correct scheme (https) to avoid 3xx redirects the client doesn't follow

Example fix

// before
String baseUrl = "https://host/"; // returns 404 for JSON-RPC post
// after
String baseUrl = "https://host/a2a/v1"; // actual JSON-RPC endpoint
Defensive patterns

Strategy: retry

Validate before calling

// smoke-test the endpoint before agent runs:
// HttpResponse r = client.execute(new HttpPost(baseUrl)); accept only 200;

Try / catch

try {
    String resp = action.sendToServer(card, payload);
} catch (IllegalStateException e) {
    int status = Integer.parseInt(e.getMessage().replaceAll("\\D+", ""));
    // 5xx/timeout -> retry with backoff; 4xx -> fix URL/auth, don't retry
}

Prevention

When it happens

Trigger: The remote A2A server returns 404 (wrong path), 401/403 (auth required), 500 (server bug), 405 (wrong method), or 3xx redirect, while the client only accepts exactly 200.

Common situations: Endpoint path mismatch between the AgentCard.url and the actual JSON-RPC route; missing auth headers/tokens on the remote service; remote agent crashed; gateway returning 502/504; server behind a proxy that answers 301 for http->https redirect.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/1fc96edd93fdaa39. Report an issue: GitHub.

Appendix: source

Thrown at spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/a2a/A2aNodeActionWithConfig.java:788

	 * @return Response body as string
	 */
	private String sendMessageToServer(AgentCardWrapper agentCard, String requestPayload) throws Exception {
		String baseUrl = resolveAgentBaseUrl(agentCard);
		System.out.println(baseUrl);
		System.out.println(requestPayload);
		if (baseUrl == null || baseUrl.isBlank()) {
			throw new IllegalStateException("AgentCard.url is empty");
		}

		try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
			HttpPost post = new HttpPost(baseUrl);
			post.setHeader("Content-Type", "application/json");
			post.setEntity(new StringEntity(requestPayload, ContentType.APPLICATION_JSON));

			try (CloseableHttpResponse response = httpClient.execute(post)) {
				int statusCode = response.getStatusLine().getStatusCode();
				if (statusCode != 200) {
					throw new IllegalStateException("HTTP request failed, status: " + statusCode);
				}
				HttpEntity entity = response.getEntity();
				if (entity == null) {
					throw new IllegalStateException("Empty HTTP entity");
				}
				return EntityUtils.toString(entity, "UTF-8");
			}
		}
	}

	/**
	 * Resolve base URL from the AgentCard.
	 */
	private String resolveAgentBaseUrl(AgentCardWrapper agentCard) {
		return agentCard.url();
	}

}

View on GitHub (pinned to f82da0b50f)