alibaba/spring-ai-alibaba · error · IllegalStateException

Empty HTTP entity

Error message

Empty HTTP entity

What it means

After a 200 response, sendMessageToServer reads the response body via response.getEntity(); if the entity is null it throws this IllegalStateException. A 200 without a body cannot be parsed into a JSON-RPC result, so the library fails fast.

Solutions

  1. Verify you're POSTing to the real JSON-RPC A2A endpoint, not a health/monitoring route that returns 200 with no body
  2. Fix the remote A2A server to always include a JSON-RPC response body on success
  3. Check proxies/gateways for body-stripping or buffering misconfiguration
  4. Add a caller-side try-catch to treat this as an upstream availability problem and retry

Example fix

// before
// remote handler: resp.setStatus(200); return; // no body
// after
// remote handler: write JSON-RPC result JSON to response output stream, then return
Defensive patterns

Strategy: retry

Validate before calling

// verify the endpoint returns a JSON body:
// POST a health JSON-RPC request and assert non-empty body before wiring the node

Try / catch

try {
    String resp = action.sendToServer(card, payload);
} catch (IllegalStateException e) {
    // treat as upstream availability problem; retry or fail the node gracefully
}

Prevention

When it happens

Trigger: The remote A2A endpoint answered 200 but Apache HttpClient provided no entity — typically with 204-like empty responses, HEAD-style gateways, or a misbehaving proxy that strips the body.

Common situations: Remote endpoint implemented incorrectly (returns 200 with empty body); server closed the connection after headers; intermediary (nginx/ALB) swallowing empty responses; wrong endpoint (health check route) that returns 200 with no body.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/e26eeffbfaf1df7c. 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:792

		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)