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


Java HttpStatusCodeException.getStatusCode方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:JetBrains,项目名称:teamcity-hashicorp-vault-plugin,代码行数:17,代码来源:VaultTemplate.java

示例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;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:26,代码来源:ManifestCommands.java

示例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);
    }
}
 
开发者ID:JetBrains,项目名称:teamcity-hashicorp-vault-plugin,代码行数:22,代码来源:VaultTemplate.java

示例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);
	}
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:24,代码来源:VaultTemplate.java

示例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);
	}
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:18,代码来源:VaultTemplate.java

示例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);
    }
  }
}
 
开发者ID:OpenLMIS,项目名称:openlmis-stockmanagement,代码行数:27,代码来源:BaseReferenceDataService.java

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

示例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;
    }
  }
}
 
开发者ID:achwie,项目名称:hystrix-demo,代码行数:18,代码来源:PlaceOrderCommand.java

示例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;
    }
  }
}
 
开发者ID:achwie,项目名称:hystrix-demo,代码行数:22,代码来源:PlaceHoldOnItemsCommand.java

示例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();
    }
}
 
开发者ID:otto-de,项目名称:edison-microservice,代码行数:19,代码来源:HealthApi.java

示例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;
		}
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:24,代码来源:ConfluentSchemaRegistryClient.java

示例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;
        }
    }
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:16,代码来源:NovaServersImpl.java

示例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;
}
 
开发者ID:HomeAdvisor,项目名称:Robusto,代码行数:43,代码来源:SpringInstanceCallback.java

示例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;
    }
  }
}
 
开发者ID:achwie,项目名称:hystrix-demo,代码行数:15,代码来源:GetCatalogItemCommand.java


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