當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。