本文整理匯總了Java中org.springframework.web.client.HttpStatusCodeException類的典型用法代碼示例。如果您正苦於以下問題:Java HttpStatusCodeException類的具體用法?Java HttpStatusCodeException怎麽用?Java HttpStatusCodeException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HttpStatusCodeException類屬於org.springframework.web.client包,在下文中一共展示了HttpStatusCodeException類的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: getResourcesFromGet
import org.springframework.web.client.HttpStatusCodeException; //導入依賴的package包/類
@Override
protected List<JsonRole> getResourcesFromGet(final RestTemplate rt, final URI targetURI)
throws HttpStatusCodeException, UpdaterHttpException {
ResponseEntity<JsonRoles> resp = rt.getForEntity(targetURI, JsonRoles.class);
if (resp != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("response is not null: " + resp.getStatusCode());
}
if (resp.getStatusCode() == HttpStatus.OK) {
if (LOG.isDebugEnabled()) {
LOG.debug("response is OK");
}
return resp.getBody().getRoles();
} else {
throw new UpdaterHttpException(
"unable to collect roles - status code: " + resp.getStatusCode().toString());
}
} else {
throw new UpdaterHttpException("unable to collect roles - HTTP response was null");
}
}
示例3: getResourcesFromGet
import org.springframework.web.client.HttpStatusCodeException; //導入依賴的package包/類
@Override
protected List<JsonDomain> getResourcesFromGet(final RestTemplate rt, final URI targetURI)
throws HttpStatusCodeException, UpdaterHttpException {
ResponseEntity<JsonDomains> resp = rt.getForEntity(targetURI, JsonDomains.class);
if (resp != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("response is not null: " + resp.getStatusCode());
}
if (resp.getStatusCode() == HttpStatus.OK) {
if (LOG.isDebugEnabled()) {
LOG.debug("response is OK");
}
return resp.getBody().getDomains();
} else {
throw new UpdaterHttpException(
"unable to collect domains - status code: " + resp.getStatusCode().toString());
}
} else {
throw new UpdaterHttpException("unable to collect domains - HTTP response was null");
}
}
示例4: 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;
}
示例5: doRestExchange
import org.springframework.web.client.HttpStatusCodeException; //導入依賴的package包/類
RestResponse<Object> doRestExchange(RestExchangeProperties properties)
throws IOException, HttpStatusCodeException {
ResponseEntity<String> responseEntity = restTemplate.exchange(properties.getUrl(),
properties.getHttpMethod(), properties.getHttpEntity(),
new ParameterizedTypeReference<String>() {
}, properties.getUrlVariables());
ObjectMapper objectMapper = new ObjectMapper();
Object returnBody = null;
if (!StringHelper.isNullOrEmpty(responseEntity.getBody())) {
if (responseEntity.getBody().startsWith("[")) {
returnBody = objectMapper.readValue(responseEntity.getBody(),
objectMapper.getTypeFactory().constructCollectionType(List.class,
properties.getReturnType()));
} else {
returnBody = objectMapper.readValue(responseEntity.getBody(), properties.getReturnType());
}
}
RestResponse<Object> restResponse = new RestResponse<>(returnBody,
responseEntity.getHeaders(),
responseEntity.getStatusCode());
return restResponse;
}
示例6: 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);
}
}
示例7: doRead
import org.springframework.web.client.HttpStatusCodeException; //導入依賴的package包/類
private <T> T doRead(final String path, final Class<T> responseType) {
return doWithSession(new RestOperationsCallback<T>() {
@Override
public T doWithRestOperations(RestOperations restOperations) {
try {
return restOperations.getForObject(path, responseType);
} catch (HttpStatusCodeException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
return null;
}
throw VaultResponses.buildException(e, path);
}
}
});
}
示例8: all
import org.springframework.web.client.HttpStatusCodeException; //導入依賴的package包/類
public List<Map> all() {
try {
Map response = restTemplate.getForObject(endpoint, Map.class);
Map embedded = (Map) response.get("_embedded");
List<Map> messages = (List<Map>) embedded.get("messages");
return messages.stream()
.filter(message -> message.containsKey("_links"))
.map(message -> (Map) message.get("_links"))
.filter(links -> links.containsKey("self"))
.map(links -> (Map) links.get("self"))
.map(self -> (String) self.get("href"))
.map(href -> restTemplate.getForObject(href, Map.class))
.collect(Collectors.toList());
} catch (HttpStatusCodeException e) {
// Istio would've performed circuit breaking and retries
// but it doesn't handle bulkheads / returning default values on full failures.
log.error("Error from Guestbook Service, falling back", e);
return allFallback();
}
}
示例9: getResourcesFromGet
import org.springframework.web.client.HttpStatusCodeException; //導入依賴的package包/類
@Override
protected List<JsonRoleAssignment> getResourcesFromGet(final RestTemplate rt, final URI targetURI)
throws HttpStatusCodeException, UpdaterHttpException {
ResponseEntity<JsonRoleAssignments> resp = rt.getForEntity(targetURI, JsonRoleAssignments.class);
if (resp != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("response is not null: " + resp.getStatusCode());
}
if (resp.getStatusCode() == HttpStatus.OK) {
if (LOG.isDebugEnabled()) {
LOG.debug("response is OK");
}
return resp.getBody().getRoleAssignments();
} else {
throw new UpdaterHttpException(
"unable to collect roleAssigments - status code: " + resp.getStatusCode().toString());
}
} else {
throw new UpdaterHttpException("unable to collect roleAssignments - HTTP response was null");
}
}
示例10: getResourcesFromGet
import org.springframework.web.client.HttpStatusCodeException; //導入依賴的package包/類
@Override
protected List<JsonProject> getResourcesFromGet(final RestTemplate rt, final URI targetURI)
throws HttpStatusCodeException, UpdaterHttpException {
ResponseEntity<JsonProjects> resp = rt.getForEntity(targetURI, JsonProjects.class);
if (resp != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("response is not null: " + resp.getStatusCode());
}
if (resp.getStatusCode() == HttpStatus.OK) {
if (LOG.isDebugEnabled()) {
LOG.debug("response is OK");
}
return resp.getBody().getProjects();
} else {
throw new UpdaterHttpException(
"unable to collect projects - status code: " + resp.getStatusCode().toString());
}
} else {
throw new UpdaterHttpException("unable to collect projects - HTTP response was null");
}
}
示例11: getResourcesFromGet
import org.springframework.web.client.HttpStatusCodeException; //導入依賴的package包/類
@Override
protected List<JsonUser> getResourcesFromGet(final RestTemplate rt, final URI targetURI)
throws HttpStatusCodeException, UpdaterHttpException {
ResponseEntity<JsonUsers> resp = rt.getForEntity(targetURI, JsonUsers.class);
if (resp != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("response is not null: " + resp.getStatusCode());
}
if (resp.getStatusCode() == HttpStatus.OK) {
if (LOG.isDebugEnabled()) {
LOG.debug("response is OK");
}
return resp.getBody().getUsers();
} else {
throw new UpdaterHttpException(
"unable to collect users - status code: " + resp.getStatusCode().toString());
}
} else {
throw new UpdaterHttpException("unable to collect users - HTTP response was null");
}
}
示例12: testCreateFailed
import org.springframework.web.client.HttpStatusCodeException; //導入依賴的package包/類
@Test
@Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public void testCreateFailed() {
AppDTO dto = generateSampleDTOData();
when(adminService.createNewApp(any(App.class))).thenThrow(new RuntimeException("save failed"));
try {
restTemplate.postForEntity(getBaseAppUrl(), dto, AppDTO.class);
} catch (HttpStatusCodeException e) {
@SuppressWarnings("unchecked")
Map<String, String> attr = gson.fromJson(e.getResponseBodyAsString(), Map.class);
Assert.assertEquals("save failed", attr.get("message"));
}
App savedApp = appService.findOne(dto.getAppId());
Assert.assertNull(savedApp);
}
示例13: createTokenUsingTlsCertAuthentication
import org.springframework.web.client.HttpStatusCodeException; //導入依賴的package包/類
private VaultToken createTokenUsingTlsCertAuthentication(String path) {
try {
VaultResponse response = restOperations.postForObject("auth/{mount}/login",
Collections.emptyMap(), VaultResponse.class, path);
Assert.state(response.getAuth() != null, "Auth field must not be null");
logger.debug("Login successful using TLS certificates");
return LoginTokenUtil.from(response.getAuth());
}
catch (HttpStatusCodeException e) {
throw new VaultException(String.format(
"Cannot login using TLS certificates: %s",
VaultResponses.getError(e.getResponseBodyAsString())));
}
}
示例14: createTokenUsingAppId
import org.springframework.web.client.HttpStatusCodeException; //導入依賴的package包/類
private VaultToken createTokenUsingAppId() {
Map<String, String> login = getAppIdLogin(options.getAppId(), options
.getUserIdMechanism().createUserId());
try {
VaultResponse response = restOperations.postForObject("auth/{mount}/login",
login, VaultResponse.class, options.getPath());
Assert.state(response != null && response.getAuth() != null,
"Auth field must not be null");
logger.debug("Login successful using AppId authentication");
return LoginTokenUtil.from(response.getAuth());
}
catch (HttpStatusCodeException e) {
throw new VaultException(String.format("Cannot login using app-id: %s",
VaultResponses.getError(e.getResponseBodyAsString())));
}
}
示例15: lookupToken
import org.springframework.web.client.HttpStatusCodeException; //導入依賴的package包/類
@Nullable
private Map<String, Object> lookupToken() {
try {
ResponseEntity<VaultResponse> entity = restOperations.exchange(
options.getPath(), HttpMethod.GET,
new HttpEntity<>(VaultHttpHeaders.from(options.getInitialToken())),
VaultResponse.class);
Assert.state(entity.getBody() != null, "Auth response must not be null");
return entity.getBody().getData();
}
catch (HttpStatusCodeException e) {
throw new VaultException(String.format(
"Cannot retrieve Token from Cubbyhole: %s %s", e.getStatusCode(),
VaultResponses.getError(e.getResponseBodyAsString())));
}
}