use of org.springframework.web.client.HttpClientErrorException in project brave by openzipkin.
the class ClientHttpResponseWrapperTest method statusCode_fromHttpStatusCodeException.
@Test
public void statusCode_fromHttpStatusCodeException() {
HttpClientErrorException ex = new HttpClientErrorException(HttpStatus.BAD_REQUEST);
assertThat(new ClientHttpResponseWrapper(request, null, ex).statusCode()).isEqualTo(400);
}
use of org.springframework.web.client.HttpClientErrorException in project open-kilda by telstra.
the class FlowSteps method eachFlowCanNotBeReadFromNorthbound.
@And("^each flow can not be read from Northbound$")
public void eachFlowCanNotBeReadFromNorthbound() {
for (FlowPayload flow : flows) {
FlowPayload result = null;
try {
result = Failsafe.with(retryPolicy().abortWhen(null).handleResultIf(Objects::nonNull)).get(() -> northboundService.getFlow(flow.getId()));
} catch (HttpClientErrorException ex) {
log.info(format("The flow '%s' doesn't exist. It is expected.", flow.getId()));
}
assertNull(format("The flow '%s' exists.", flow.getId()), result);
}
}
use of org.springframework.web.client.HttpClientErrorException in project zeppelin by apache.
the class BaseLivyInterprereter method callRestAPI.
private String callRestAPI(String targetURL, String method, String jsonData) throws LivyException {
targetURL = livyURL + targetURL;
LOGGER.debug("Call rest api in {}, method: {}, jsonData: {}", targetURL, method, jsonData);
RestTemplate restTemplate = getRestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json");
headers.add("X-Requested-By", "zeppelin");
ResponseEntity<String> response = null;
try {
if (method.equals("POST")) {
HttpEntity<String> entity = new HttpEntity<>(jsonData, headers);
response = restTemplate.exchange(targetURL, HttpMethod.POST, entity, String.class);
} else if (method.equals("GET")) {
HttpEntity<String> entity = new HttpEntity<>(headers);
response = restTemplate.exchange(targetURL, HttpMethod.GET, entity, String.class);
} else if (method.equals("DELETE")) {
HttpEntity<String> entity = new HttpEntity<>(headers);
response = restTemplate.exchange(targetURL, HttpMethod.DELETE, entity, String.class);
}
} catch (HttpClientErrorException e) {
response = new ResponseEntity(e.getResponseBodyAsString(), e.getStatusCode());
LOGGER.error(String.format("Error with %s StatusCode: %s", response.getStatusCode().value(), e.getResponseBodyAsString()));
} catch (RestClientException e) {
// Exception happens when kerberos is enabled.
if (e.getCause() instanceof HttpClientErrorException) {
HttpClientErrorException cause = (HttpClientErrorException) e.getCause();
if (cause.getResponseBodyAsString().matches(SESSION_NOT_FOUND_PATTERN)) {
throw new SessionNotFoundException(cause.getResponseBodyAsString());
}
}
throw new LivyException(e);
}
if (response == null) {
throw new LivyException("No http response returned");
}
LOGGER.debug("Get response, StatusCode: {}, responseBody: {}", response.getStatusCode(), response.getBody());
if (response.getStatusCode().value() == 200 || response.getStatusCode().value() == 201) {
return response.getBody();
} else if (response.getStatusCode().value() == 404) {
if (response.getBody().matches(SESSION_NOT_FOUND_PATTERN)) {
throw new SessionNotFoundException(response.getBody());
} else {
throw new APINotFoundException("No rest api found for " + targetURL + ", " + response.getStatusCode());
}
} else {
String responseString = response.getBody();
if (responseString.contains("CreateInteractiveRequest[\\\"master\\\"]")) {
return responseString;
}
throw new LivyException(String.format("Error with %s StatusCode: %s", response.getStatusCode().value(), responseString));
}
}
use of org.springframework.web.client.HttpClientErrorException in project spring-framework by spring-projects.
the class SimpleUrlHandlerMappingIntegrationTests method testHandlerNotFound.
@Test
public void testHandlerNotFound() throws Exception {
URI url = new URI("http://localhost:" + this.port + "/oops");
RequestEntity<Void> request = RequestEntity.get(url).build();
try {
new RestTemplate().exchange(request, byte[].class);
} catch (HttpClientErrorException ex) {
assertEquals(HttpStatus.NOT_FOUND, ex.getStatusCode());
}
}
use of org.springframework.web.client.HttpClientErrorException in project spring-boot by spring-projects.
the class CloudFoundrySecurityService method getAccessLevel.
/**
* Return the access level that should be granted to the given token.
* @param token the token
* @param applicationId the cloud foundry application ID
* @return the access level that should be granted
* @throws CloudFoundryAuthorizationException if the token is not authorized
*/
public AccessLevel getAccessLevel(String token, String applicationId) throws CloudFoundryAuthorizationException {
try {
URI uri = getPermissionsUri(applicationId);
RequestEntity<?> request = RequestEntity.get(uri).header("Authorization", "bearer " + token).build();
Map<?, ?> body = this.restTemplate.exchange(request, Map.class).getBody();
if (Boolean.TRUE.equals(body.get("read_sensitive_data"))) {
return AccessLevel.FULL;
}
return AccessLevel.RESTRICTED;
} catch (HttpClientErrorException ex) {
if (ex.getStatusCode().equals(HttpStatus.FORBIDDEN)) {
throw new CloudFoundryAuthorizationException(Reason.ACCESS_DENIED, "Access denied");
}
throw new CloudFoundryAuthorizationException(Reason.INVALID_TOKEN, "Invalid token", ex);
} catch (HttpServerErrorException ex) {
throw new CloudFoundryAuthorizationException(Reason.SERVICE_UNAVAILABLE, "Cloud controller not reachable");
}
}
Aggregations