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


Java HttpStatusCodeException类代码示例

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

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

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

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

示例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;
}
 
开发者ID:mental-party,项目名称:meparty,代码行数:28,代码来源:RestApiProxyInvocationHandler.java

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

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

示例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();
  }
}
 
开发者ID:saturnism,项目名称:istio-by-example-java,代码行数:22,代码来源:GuestbookService.java

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

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

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

示例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);
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:18,代码来源:ControllerIntegrationExceptionTest.java

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

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

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


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