当前位置: 首页>>代码示例>>Java>>正文


Java HttpClientErrorException.getStatusCode方法代码示例

本文整理汇总了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);
	}

}
 
开发者ID:vianneyfaivre,项目名称:Persephone,代码行数:27,代码来源:EnvironmentService.java

示例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();
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:18,代码来源:ItemService.java

示例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());
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:40,代码来源:RestAuthenticationHandler.java

示例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());
		}
	}
}
 
开发者ID:tmply,项目名称:tmply,代码行数:25,代码来源:TmplyClient.java

示例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;
}
 
开发者ID:SAP,项目名称:cloud-cf-feature-flags-sample,代码行数:35,代码来源:FeatureFlagsService.java

示例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;
    }
}
 
开发者ID:eclipse,项目名称:keti,代码行数:19,代码来源:ZoneFactory.java

示例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;
        }
    }
}
 
开发者ID:BBVA,项目名称:mirrorgate-jira-stories-collector,代码行数:15,代码来源:CollectorService.java


注:本文中的org.springframework.web.client.HttpClientErrorException.getStatusCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。