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