spring-projects/spring-boot · error · ReportableException

Invalid content received from server ({})

Error message

Invalid content received from server ({})

What it means

Thrown by InitializrService.parseJsonMetadata when the server's HTTP 200 body cannot be parsed into InitializrServiceMetadata (a JSONException escapes). The server returned a successful status but the body was not valid JSON metadata or did not match the expected schema.

Source

Thrown at cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitializrService.java:140

	Object loadServiceCapabilities(String serviceUrl) throws IOException {
		HttpGet request = new HttpGet(serviceUrl);
		request.setHeader(new BasicHeader(HttpHeaders.ACCEPT, ACCEPT_SERVICE_CAPABILITIES));
		ClassicHttpResponse httpResponse = execute(request, URI.create(serviceUrl), "retrieve help");
		validateResponse(httpResponse, serviceUrl);
		HttpEntity httpEntity = httpResponse.getEntity();
		ContentType contentType = ContentType.create(httpEntity.getContentType());
		if (contentType.getMimeType().equals("text/plain")) {
			return getContent(httpEntity);
		}
		return parseJsonMetadata(httpEntity);
	}

	private InitializrServiceMetadata parseJsonMetadata(HttpEntity httpEntity) throws IOException {
		try {
			return new InitializrServiceMetadata(getContentAsJson(httpEntity));
		}
		catch (JSONException ex) {
			throw new ReportableException("Invalid content received from server (" + ex.getMessage() + ")", ex);
		}
	}

	private void validateResponse(ClassicHttpResponse httpResponse, String serviceUrl) {
		if (httpResponse.getEntity() == null) {
			throw new ReportableException("No content received from server '" + serviceUrl + "'");
		}
		if (httpResponse.getCode() != 200) {
			throw createException(serviceUrl, httpResponse);
		}
	}

	private ProjectGenerationResponse createResponse(ClassicHttpResponse httpResponse, HttpEntity httpEntity)
			throws IOException {
		ProjectGenerationResponse response = new ProjectGenerationResponse(
				ContentType.create(httpEntity.getContentType()));
		response.setContent(FileCopyUtils.copyToByteArray(httpEntity.getContent()));
		String fileName = extractFileName(httpResponse.getFirstHeader("Content-Disposition"));

View on GitHub (pinned to 270dfe353f)

Solutions

  1. Verify the --target URL is a real Spring Initializr service by opening it in a browser
  2. Check for proxy or captive-portal interception of the request
  3. Upgrade spring-boot-cli to match the server version
  4. Point --target at https://start.spring.io to confirm

Example fix

// before
$ spring init --target https://example.com foo
// after
$ spring init --target https://start.spring.io foo
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight: confirm the endpoint serves JSON metadata before generating.
// `spring init --list --target <url>` exercises the same parse path cheaply.
// In code, fetch the URL and assert content-type is application/json or
// the body parses as a org.json.JSONObject before handing off to InitializrService.

Try / catch

try {
    InitializrServiceMetadata metadata = service.loadMetadata(serviceUrl);
} catch (ReportableException ex) {
    if (ex.getMessage().startsWith("Invalid content received from server")) {
        Log.error("Not a valid Initializr endpoint: " + serviceUrl);
    }
    throw ex;
}

Prevention

When it happens

Trigger: The metadata URL (--target) points at a non-Initializr endpoint that returns 200 with HTML or malformed JSON; a proxy or captive portal injects a non-JSON page; the server emits JSON the CLI's metadata parser rejects.

Common situations: Wrong --target URL pointing at a plain web page; captive-portal or corporate proxy interception; an outdated CLI talking to a server with a changed metadata schema.

Related errors


AI-assisted analysis of spring-projects/spring-boot@270dfe353f (2026-08-11). Data as JSON: /api/errors/56b79a9f4077b35b. Report an issue: GitHub.