use of org.springframework.web.client.RestClientException in project nextprot-api by calipho-sib.
the class SparqlProxyEndpointImpl method sparqlInternal.
private ResponseEntity<String> sparqlInternal(String queryString) {
ResponseEntity<String> responseEntity;
String url = sparqlEndpoint.getUrl() + ((queryString != null) ? ("?" + queryString) : "");
try {
RestTemplate template = new RestTemplate();
responseEntity = template.getForEntity(new URI(url), String.class);
return responseEntity;
} catch (HttpServerErrorException | HttpClientErrorException e) {
throw new NextProtException(e.getResponseBodyAsString(), e);
} catch (RestClientException | URISyntaxException e) {
throw new NextProtException(e);
}
}
use of org.springframework.web.client.RestClientException in project spring-boot-admin by codecentric.
the class DefaultApplicationRegistratorTest method deregister_should_try_next_on_error.
@Test
public void deregister_should_try_next_on_error() {
ApplicationRegistrator registrator = new DefaultApplicationRegistrator(() -> this.application, this.registrationClient, new String[] { "http://sba:8080/instances", "http://sba2:8080/instances" }, true);
when(this.registrationClient.register(any(), eq(this.application))).thenReturn("-id-");
doThrow(new RestClientException("Error")).when(this.registrationClient).deregister("http://sba:8080/instances", "-id-");
registrator.register();
registrator.deregister();
assertThat(registrator.getRegisteredId()).isNull();
verify(this.registrationClient).deregister("http://sba:8080/instances", "-id-");
verify(this.registrationClient).deregister("http://sba2:8080/instances", "-id-");
}
use of org.springframework.web.client.RestClientException in project spring-boot-admin by codecentric.
the class DefaultApplicationRegistratorTest method register_should_try_next_on_error.
@Test
public void register_should_try_next_on_error() {
ApplicationRegistrator registrator = new DefaultApplicationRegistrator(() -> this.application, this.registrationClient, new String[] { "http://sba:8080/instances", "http://sba2:8080/instances" }, true);
when(this.registrationClient.register("http://sba:8080/instances", this.application)).thenThrow(new RestClientException("Error"));
when(this.registrationClient.register("http://sba2:8080/instances", this.application)).thenReturn("-id-");
assertThat(registrator.register()).isTrue();
assertThat(registrator.getRegisteredId()).isEqualTo("-id-");
}
use of org.springframework.web.client.RestClientException in project spring-security by spring-projects.
the class NimbusJwtDecoderTests method decodeWhenCacheIsConfiguredAndValueLoaderErrorsThenThrowsJwtException.
@Test
public void decodeWhenCacheIsConfiguredAndValueLoaderErrorsThenThrowsJwtException() {
Cache cache = new ConcurrentMapCache("test-jwk-set-cache");
RestOperations restOperations = mock(RestOperations.class);
given(restOperations.exchange(any(RequestEntity.class), eq(String.class))).willThrow(new RestClientException("Cannot retrieve JWK Set"));
// @formatter:off
NimbusJwtDecoder jwtDecoder = NimbusJwtDecoder.withJwkSetUri(JWK_SET_URI).restOperations(restOperations).cache(cache).build();
assertThatExceptionOfType(JwtException.class).isThrownBy(() -> jwtDecoder.decode(SIGNED_JWT)).isNotInstanceOf(BadJwtException.class).withMessageContaining("An error occurred while attempting to decode the Jwt");
// @formatter:on
}
use of org.springframework.web.client.RestClientException in project pinpoint by naver.
the class WebhookSenderImpl method sendWebhook.
@Override
public void sendWebhook(AlarmChecker<?> checker, int sequenceCount, StepExecution stepExecution) {
Rule rule = checker.getRule();
String userGroupId = rule.getUserGroupId();
List<UserMember> userMembers = userService.selectUserByUserGroupId(userGroupId).stream().map(WebhookSenderImpl::newUser).collect(Collectors.toList());
UserGroup userGroup = new UserGroup(userGroupId, userMembers);
WebhookPayload webhookPayload = webhookPayloadFactory.newPayload(checker, sequenceCount, userGroup);
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
List<Webhook> webhookSendInfoList = webhookService.selectWebhookByRuleId(rule.getRuleId());
for (Webhook webhook : webhookSendInfoList) {
try {
HttpEntity<WebhookPayload> httpEntity = new HttpEntity<>(webhookPayload, httpHeaders);
restTemplate.exchange(webhook.getUrl(), HttpMethod.POST, httpEntity, String.class);
logger.info("Successfully sent webhook : {}", webhook);
} catch (RestClientException e) {
logger.warn("Failed at sending webhook. Failed Webhook : {} for Rule : {}", webhook, rule, e);
}
}
logger.info("Finished sending webhooks for rule : {}", rule);
}
Aggregations