本文整理匯總了Java中org.springframework.web.client.HttpStatusCodeException.getStatusCode方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpStatusCodeException.getStatusCode方法的具體用法?Java HttpStatusCodeException.getStatusCode怎麽用?Java HttpStatusCodeException.getStatusCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.web.client.HttpStatusCodeException
的用法示例。
在下文中一共展示了HttpStatusCodeException.getStatusCode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: delete
import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
@Override
public void delete(final String path) {
Assert.hasText(path, "Path must not be empty");
try {
sessionTemplate.delete(path);
} catch (HttpStatusCodeException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
return;
}
throw VaultResponses.buildException(e, path);
}
}
示例2: getManifest
import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
@ShellMethod(key = "manifest get", value = "Get the manifest for a release")
public Object getManifest(
@ShellOption(help = "release name") @NotNull String releaseName,
@ShellOption(help = "specific release version.", defaultValue = NULL) Integer releaseVersion) {
String manifest;
try {
if (releaseVersion == null) {
manifest = this.skipperClient.manifest(releaseName);
}
else {
manifest = this.skipperClient.manifest(releaseName, releaseVersion);
}
}
catch (HttpStatusCodeException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
// 404 means release not found.
// TODO it'd be nice to rethrow ReleaseNotFoundException in
// SkipperClient but that exception is on server
return "Release with name '" + releaseName + "' not found";
}
// if something else, rethrow
throw e;
}
return manifest;
}
示例3: read
import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <T> VaultResponseSupport<T> read(final String path, final Class<T> responseType) {
final ParameterizedTypeReference<VaultResponseSupport<T>> ref = VaultResponses
.getTypeReference(responseType);
try {
ResponseEntity<VaultResponseSupport<T>> exchange = sessionTemplate.exchange(
path, HttpMethod.GET, null, ref);
return exchange.getBody();
} catch (HttpStatusCodeException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
return null;
}
throw VaultResponses.buildException(e, path);
}
}
示例4: read
import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> VaultResponseSupport<T> read(final String path, final Class<T> responseType) {
final ParameterizedTypeReference<VaultResponseSupport<T>> ref = VaultResponses
.getTypeReference(responseType);
try {
ResponseEntity<VaultResponseSupport<T>> exchange = sessionTemplate.exchange(
path, HttpMethod.GET, null, ref);
return exchange.getBody();
}
catch (HttpStatusCodeException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
return null;
}
throw VaultResponses.buildException(e, path);
}
}
示例5: delete
import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
@Override
public void delete(final String path) {
Assert.hasText(path, "Path must not be empty");
try {
sessionTemplate.delete(path);
}
catch (HttpStatusCodeException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
return;
}
throw VaultResponses.buildException(e, path);
}
}
示例6: findOne
import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
/**
* Return one object from Reference data service.
*
* @param id UUID of requesting object.
* @return Requesting reference data object.
*/
public T findOne(UUID id) {
String url = getServiceUrl() + getUrl() + id;
RestTemplate restTemplate = new RestTemplate();
try {
ResponseEntity<T> responseEntity = restTemplate.exchange(
buildUri(url), HttpMethod.GET, createEntity(obtainAccessToken()),
getResultClass());
return responseEntity.getBody();
} catch (HttpStatusCodeException ex) {
// rest template will handle 404 as an exception, instead of returning null
if (ex.getStatusCode() == HttpStatus.NOT_FOUND) {
logger.warn("{} with id {} does not exist. ", getResultClass().getSimpleName(), id);
return null;
} else {
throw buildDataRetrievalException(ex);
}
}
}
示例7: run
import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
@Override
public void run() {
while (running.get()) {
try {
readStream(twitter.getRestTemplate());
}
catch (HttpStatusCodeException sce) {
if (sce.getStatusCode() == HttpStatus.UNAUTHORIZED) {
logger.error("Twitter authentication failed: " + sce.getMessage());
running.set(false);
}
else if (sce.getStatusCode() == HttpStatus.TOO_MANY_REQUESTS) {
waitRateLimitBackoff();
}
else {
waitHttpErrorBackoff();
}
}
catch (Exception e) {
logger.warn("Exception while reading stream.", e);
waitLinearBackoff();
}
}
}
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-app-starters,代碼行數:25,代碼來源:AbstractTwitterInboundChannelAdapter.java
示例8: run
import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
@Override
protected Integer run() throws Exception {
try {
final Integer quantity = restOps.getForObject(url, Integer.class);
return quantity != null ? quantity.intValue() : getFallback();
} catch (HttpStatusCodeException e) {
// Returns 404 for non-existent stock count entry - otherwise we have an
// error
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
LOG.warn("Could not get stock quantity for product at {}", url);
return getFallback(); // Don't trip circuit breaker
} else {
LOG.error("Unexpected response while getting stock quantity for product at {} (status: {}, response body: '{}')", url, e.getStatusCode(),
e.getResponseBodyAsString());
throw e;
}
}
}
示例9: run
import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
@Override
protected Boolean run() throws Exception {
try {
restOps.postForObject(url, cart, String.class);
return true;
} catch (HttpStatusCodeException e) {
// Returns 409 for status errors, e.g. if not enough items were available
// anymore
if (e.getStatusCode() == HttpStatus.CONFLICT) {
LOG.warn("Could not place order at {}! Maybe there were not enough items on stock anymore?", url);
return getFallback(); // Don't trip circuit breaker
} else {
LOG.error("Unexpected response while placing order at {} (status: {}, response body: '{}')", url, e.getStatusCode(), e.getResponseBodyAsString());
throw e;
}
}
}
示例10: run
import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
@Override
protected Boolean run() throws Exception {
final PutProductsOnHoldRequest request = new PutProductsOnHoldRequest();
request.setProductIds(productIds);
request.setQuantities(quantities);
try {
restOps.postForObject(url, request, String.class);
return true;
} catch (HttpStatusCodeException e) {
// Returns 409 if there's insufficient stock for one of the ordered items
// - else we have an error
if (e.getStatusCode() == HttpStatus.CONFLICT) {
return getFallback(); // Don't trip circuit breaker
} else {
LOG.error("Unexpected response while putting a hold on products for order at {} (status: {}, response body: '{}')", url, e.getStatusCode(),
e.getResponseBodyAsString());
throw e;
}
}
}
示例11: getResource
import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
private static void getResource(final String url, final Optional<String> mediaType) {
final HttpHeaders headers = new HttpHeaders();
if (mediaType.isPresent()) {
headers.setAccept(asList(parseMediaType(mediaType.get())));
}
try {
final ResponseEntity<String> responseEntity = restTemplate.exchange(
url,
GET,
new HttpEntity<>("parameters", headers), String.class
);
content = responseEntity.getBody();
statusCode = responseEntity.getStatusCode();
} catch (HttpStatusCodeException e) {
content = e.getStatusText();
statusCode = e.getStatusCode();
}
}
示例12: fetch
import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
@Override
public String fetch(SchemaReference schemaReference) {
String path = String.format("/subjects/%s/versions/%d",
schemaReference.getSubject(), schemaReference.getVersion());
HttpHeaders headers = new HttpHeaders();
headers.put("Accept", ACCEPT_HEADERS);
headers.add("Content-Type", "application/vnd.schemaregistry.v1+json");
HttpEntity<String> request = new HttpEntity<>("", headers);
try {
ResponseEntity<Map> response = this.template.exchange(this.endpoint + path,
HttpMethod.GET, request, Map.class);
return (String) response.getBody().get("schema");
}
catch (HttpStatusCodeException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
throw new SchemaNotFoundException(String.format(
"Could not find schema for reference: %s", schemaReference));
}
else {
throw e;
}
}
}
示例13: performAction
import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
private void performAction(final String serverId, final JsonAction jsonAction) {
String resourcesUri = jsonEndpoint.getUrl() + "/" + getUriSuffix() + "s/" + serverId + "/action";
RestTemplate rt = getRestTemplate(jsonEndpoint.getProjectId());
try {
rt.postForEntity(resourcesUri, jsonAction, String.class);
} catch (HttpStatusCodeException ex) {
// check if it's a 401
if (ex.getStatusCode() == HttpStatus.UNAUTHORIZED) {
throw new AuthenticationFailureException(ex);
} else {
throw ex;
}
}
}
示例14: run
import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
/**
* This delagates actual execution to {@link #runWithUrl(String)} and handles any
* Spring Rest exceptions, wrapping them as necessary. Default behavior is to throw
* a {@link RetryableApiCommandException} for 5xx errors and timeouts, and {@link
* NonRetryableApiCommandException} for all others. If you need different behavior
* your best bet is to write your own {@link RemoteServiceCallback} and/or use
* the various flavors of {@link org.springframework.web.client.RestTemplate} that
* take let you provide {@link ResponseErrorHandler}.
* @param url The URL of the remote service.
* @return Result of the remote call, or potentially throws an exception if an
* error occurs calling the remote service.
*/
@Override
public T run(String url)
{
T response = null;
try
{
LOG.debug("Running command {} with URL {}", getContext().getCommandName(), url);
response = runWithUrl(url);
}
catch (HttpStatusCodeException hsce)
{
if (hsce.getStatusCode() == HttpStatus.REQUEST_TIMEOUT ||
hsce.getStatusCode().value() >= 500)
{
throw new RetryableApiCommandException("Remote server error: " + hsce.getMessage(), hsce);
}
else
{
throw new NonRetryableApiCommandException("Local client error: " + hsce.getMessage(), hsce);
}
}
catch(HttpMessageConversionException e)
{
throw new NonRetryableApiCommandException("Invalid response from server: " + e.getMessage(), e);
}
LOG.debug("Returning response {}", response);
return response;
}
示例15: run
import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
@Override
protected CatalogItem run() throws Exception {
try {
return restOps.getForObject(url, CatalogItem.class);
} catch (HttpStatusCodeException e) {
// Returns 404 if item could not be found - otherwise we have an error
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
return getFallback(); // Don't trip circuit breaker
} else {
LOG.error("Unexpected response while getting product at {} (status: {}, response body: '{}')", url, e.getStatusCode(), e.getResponseBodyAsString());
throw e;
}
}
}