本文整理汇总了Java中org.springframework.web.client.HttpClientErrorException.getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientErrorException.getStatusCode方法的具体用法?Java HttpClientErrorException.getStatusCode怎么用?Java HttpClientErrorException.getStatusCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.client.HttpClientErrorException
的用法示例。
在下文中一共展示了HttpClientErrorException.getStatusCode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getActuatorVersion
import org.springframework.web.client.HttpClientErrorException; //导入方法依赖的package包/类
public ActuatorVersion getActuatorVersion(Application app) {
String url = app.endpoints().env();
try {
LOGGER.debug("HEAD {}", url);
HttpHeaders headers = headRestTemplate.headForHeaders(new URI(url));
return ActuatorVersion.parse(headers.getContentType());
} catch (RestClientException ex) {
if(ex instanceof HttpClientErrorException) {
HttpClientErrorException clientEx = ((HttpClientErrorException)ex);
// Spring Boot 1.3 does not allow HEAD method, so let's assume the app is up
if(clientEx.getStatusCode() == HttpStatus.METHOD_NOT_ALLOWED) {
return ActuatorVersion.V1;
}
}
throw RestTemplateErrorHandler.handle(app, url, ex);
} catch (URISyntaxException e) {
throw RestTemplateErrorHandler.handle(app, e);
}
}
示例2: getNamespaceId
import org.springframework.web.client.HttpClientErrorException; //导入方法依赖的package包/类
private long getNamespaceId(NamespaceIdentifier namespaceIdentifier) {
String appId = namespaceIdentifier.getAppId();
String clusterName = namespaceIdentifier.getClusterName();
String namespaceName = namespaceIdentifier.getNamespaceName();
Env env = namespaceIdentifier.getEnv();
NamespaceDTO namespaceDTO = null;
try {
namespaceDTO = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName);
} catch (HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
throw new BadRequestException(String.format(
"namespace not exist. appId:%s, env:%s, clusterName:%s, namespaceName:%s", appId, env, clusterName,
namespaceName));
}
}
return namespaceDTO.getId();
}
示例3: authenticateUsernamePasswordInternal
import org.springframework.web.client.HttpClientErrorException; //导入方法依赖的package包/类
@Override
protected HandlerResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential c, final String originalPassword)
throws GeneralSecurityException, PreventedException {
try {
final UsernamePasswordCredential creds = new UsernamePasswordCredential(c.getUsername(), c.getPassword());
final ResponseEntity<SimplePrincipal> authenticationResponse = api.authenticate(creds);
if (authenticationResponse.getStatusCode() == HttpStatus.OK) {
final SimplePrincipal principalFromRest = authenticationResponse.getBody();
if (principalFromRest == null || StringUtils.isBlank(principalFromRest.getId())) {
throw new FailedLoginException("Could not determine authentication response from rest endpoint for " + c.getUsername());
}
return createHandlerResult(c,
this.principalFactory.createPrincipal(principalFromRest.getId(), principalFromRest.getAttributes()),
new ArrayList<>());
}
} catch (final HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.FORBIDDEN) {
throw new AccountDisabledException("Could not authenticate forbidden account for " + c.getUsername());
}
if (e.getStatusCode() == HttpStatus.UNAUTHORIZED) {
throw new FailedLoginException("Could not authenticate account for " + c.getUsername());
}
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
throw new AccountNotFoundException("Could not locate account for " + c.getUsername());
}
if (e.getStatusCode() == HttpStatus.LOCKED) {
throw new AccountLockedException("Could not authenticate locked account for " + c.getUsername());
}
if (e.getStatusCode() == HttpStatus.PRECONDITION_REQUIRED) {
throw new AccountExpiredException("Could not authenticate expired account for " + c.getUsername());
}
throw new FailedLoginException("Rest endpoint returned an unknown status code "
+ e.getStatusCode() + " for " + c.getUsername());
}
throw new FailedLoginException("Rest endpoint returned an unknown response for " + c.getUsername());
}
示例4: fetch
import org.springframework.web.client.HttpClientErrorException; //导入方法依赖的package包/类
public String fetch(String slotName)
{
try
{
ResponseEntity<FetchResponse> responseEntity = this.restTemplate.getForEntity(baseUrl + "/api/buckets/{0}", FetchResponse.class, slotName);
if (!responseEntity.getStatusCode().is2xxSuccessful())
{
throw new RuntimeException("Fetch failed: " + responseEntity.getStatusCode());
}
return responseEntity.getBody().data;
}
catch (HttpClientErrorException ex)
{
if (ex.getStatusCode() == HttpStatus.NOT_FOUND)
{
return null;
}
else
{
throw new RuntimeException("Fetch failed: " + ex.getStatusCode());
}
}
}
示例5: getFlagStatus
import org.springframework.web.client.HttpClientErrorException; //导入方法依赖的package包/类
/**
* Gets the status of a feature flag by given ID.
*
* @param id
* - ID of the feature flag
* @return the feature flag status
*/
public FlagStatus getFlagStatus(final String id) {
// @formatter:off
URI url = UriComponentsBuilder
.fromUri(baseUri)
.path("/api/v1/evaluate/{id}")
.buildAndExpand(id).toUri();
// @formatter:on
FlagStatus status = FlagStatus.DISABLED;
try {
ResponseEntity<?> responseEntity = restOperations.getForEntity(url, Object.class);
if (responseEntity.getStatusCode() == HttpStatus.OK) {
status = FlagStatus.ENABLED;
}
} catch (HttpClientErrorException e) {
if (e.getStatusCode() != HttpStatus.NOT_FOUND) {
logger.error(ERROR_EVALUATION_MESSAGE, e);
status = FlagStatus.DISABLED;
} else {
status = FlagStatus.MISSING;
}
}
return status;
}
示例6: deleteZone
import org.springframework.web.client.HttpClientErrorException; //导入方法依赖的package包/类
/**
* Deletes desired Zone. Makes a client call that deletes the desired zone. This method should be use after the
* set of tests for that zone are finished.
*
* @param restTemplate
* @param zoneName
* @return HttpStatus
*/
public HttpStatus deleteZone(final RestTemplate restTemplate, final String zoneName) {
try {
restTemplate.delete(this.acsBaseUrl + ACS_ZONE_API_PATH + zoneName);
return HttpStatus.NO_CONTENT;
} catch (HttpClientErrorException httpException) {
return httpException.getStatusCode();
} catch (RestClientException e) {
return HttpStatus.INTERNAL_SERVER_ERROR;
}
}
示例7: getUpdatedDate
import org.springframework.web.client.HttpClientErrorException; //导入方法依赖的package包/类
public Date getUpdatedDate() {
try {
return restTemplate.getForObject(mirrorGateUrl + MIRROR_GATE_COLLECTOR_ENDPOINT, Date.class, appName);
}
catch (final HttpClientErrorException e) {
if(e.getStatusCode() == HttpStatus.NOT_FOUND) {
LOGGER.info("Not previous execution date found. Running from the very beginning so this could take a while");
return null;
} else {
LOGGER.error("Error requesting previous collector status", e);
throw e;
}
}
}