org.springframework.http.ResponseEntity#hasBody ( )源码实例Demo

下面列出了org.springframework.http.ResponseEntity#hasBody ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private LightminClientApplicationStatus getStatus(final LightminClientApplication lightminClientApplication) {
    LightminClientApplicationStatus lightminClientApplicationStatus;
    try {
        @SuppressWarnings("unchecked") final ResponseEntity<Map<String, Object>> response =
                this.restTemplate.getForEntity(lightminClientApplication.getHealthUrl(), (Class<Map<String, Object>>) (Class<?>) Map.class);

        if (response.hasBody() && response.getBody().get(STATUS_RESPONSE_KEY) instanceof String) {
            lightminClientApplicationStatus = LightminClientApplicationStatus.valueOf((String) response.getBody().get(STATUS_RESPONSE_KEY));
        } else if (response.getStatusCode().is2xxSuccessful()) {
            lightminClientApplicationStatus = LightminClientApplicationStatus.ofUp();
        } else {
            lightminClientApplicationStatus = LightminClientApplicationStatus.ofOffline();
        }

    } catch (final Exception ex) {
        if (LightminClientApplicationStatus.ofOffline().getStatus().equals(lightminClientApplication
                .getLightminClientApplicationStatus().getStatus())) {
            log.debug("Error while getting status for {}", lightminClientApplication, ex);
        } else {
            log.warn("Error while getting status for {}", lightminClientApplication, ex);
        }
        lightminClientApplicationStatus = LightminClientApplicationStatus.ofOffline();
    }
    return lightminClientApplicationStatus;
}
 
@Override
public EurekaHttpResponse<InstanceInfo> sendHeartBeat(String appName, String id,
		InstanceInfo info, InstanceStatus overriddenStatus) {
	String urlPath = serviceUrl + "apps/" + appName + '/' + id + "?status="
			+ info.getStatus().toString() + "&lastDirtyTimestamp="
			+ info.getLastDirtyTimestamp().toString() + (overriddenStatus != null
					? "&overriddenstatus=" + overriddenStatus.name() : "");

	ResponseEntity<InstanceInfo> response = restTemplate.exchange(urlPath,
			HttpMethod.PUT, null, InstanceInfo.class);

	EurekaHttpResponseBuilder<InstanceInfo> eurekaResponseBuilder = anEurekaHttpResponse(
			response.getStatusCodeValue(), InstanceInfo.class)
					.headers(headersOf(response));

	if (response.hasBody()) {
		eurekaResponseBuilder.entity(response.getBody());
	}

	return eurekaResponseBuilder.build();
}
 
源代码3 项目: multiapps-controller   文件: UAAClient.java
public Map<String, Object> readTokenKey() {
    String tokenKeyURL = uaaUrl.toString() + TOKEN_KEY_ENDPOINT;
    ResponseEntity<String> tokenKeyResponse = restTemplate.getForEntity(tokenKeyURL, String.class);
    if (!tokenKeyResponse.hasBody()) {
        throw new IllegalStateException(MessageFormat.format("Invalid response returned from /token_key: {0}",
                                                             tokenKeyResponse.getBody()));
    }

    return JsonUtil.convertJsonToMap(tokenKeyResponse.getBody());
}
 
private Links discoverLinks(ResponseEntity<String> response) {
	Links links = new Links();
	if (!response.getStatusCode().isError()
			&& response.hasBody()
			&& !StringUtils.isEmpty(response.getBody())) {
		MediaType mediaType = Optional.ofNullable(response.getHeaders().getContentType())
				.orElse(MediaTypes.HAL_JSON_UTF8);
		links = createLinksFrom(response.getBody(), mediaType);
	}
	return links;
}
 
@Override
public LockStatus getLockStatus(final Path filePath) throws ResourceNotFoundException {
    try {
        ResponseEntity<String> lockStatusResponse = doGet(filePath, GET_LOCK_STATUS);
        if (lockStatusResponse.hasBody()) {
            return LockStatus.valueOf(lockStatusResponse.getBody());
        }
    } catch (Exception e) {
        handleResourceException(filePath, e);
    }

    return LockStatus.UNLOCKED;
}
 
@Override
public EurekaHttpResponse<Application> getApplication(String appName) {
	String urlPath = serviceUrl + "apps/" + appName;

	ResponseEntity<Application> response = restTemplate.exchange(urlPath,
			HttpMethod.GET, null, Application.class);

	Application application = response.getStatusCodeValue() == HttpStatus.OK.value()
			&& response.hasBody() ? response.getBody() : null;

	return anEurekaHttpResponse(response.getStatusCodeValue(), application)
			.headers(headersOf(response)).build();
}