Search in sources :

Example 11 with RestClientException

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);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) RestTemplate(org.springframework.web.client.RestTemplate) RestClientException(org.springframework.web.client.RestClientException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) HttpServerErrorException(org.springframework.web.client.HttpServerErrorException)

Example 12 with RestClientException

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-");
}
Also used : RestClientException(org.springframework.web.client.RestClientException) Test(org.junit.jupiter.api.Test)

Example 13 with RestClientException

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-");
}
Also used : RestClientException(org.springframework.web.client.RestClientException) Test(org.junit.jupiter.api.Test)

Example 14 with RestClientException

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
}
Also used : ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) RestClientException(org.springframework.web.client.RestClientException) RestOperations(org.springframework.web.client.RestOperations) RequestEntity(org.springframework.http.RequestEntity) ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) Cache(org.springframework.cache.Cache) Test(org.junit.jupiter.api.Test)

Example 15 with RestClientException

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);
}
Also used : UserMember(com.navercorp.pinpoint.batch.alarm.vo.sender.payload.UserMember) HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) WebhookPayload(com.navercorp.pinpoint.batch.alarm.vo.sender.payload.WebhookPayload) RestClientException(org.springframework.web.client.RestClientException) Webhook(com.navercorp.pinpoint.web.vo.Webhook) Rule(com.navercorp.pinpoint.web.alarm.vo.Rule) UserGroup(com.navercorp.pinpoint.batch.alarm.vo.sender.payload.UserGroup)

Aggregations

RestClientException (org.springframework.web.client.RestClientException)43 HttpHeaders (org.springframework.http.HttpHeaders)12 HttpEntity (org.springframework.http.HttpEntity)11 IOException (java.io.IOException)9 RestTemplate (org.springframework.web.client.RestTemplate)9 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)8 Test (org.junit.Test)5 JsonParseException (com.fasterxml.jackson.core.JsonParseException)4 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)4 HttpServerErrorException (org.springframework.web.client.HttpServerErrorException)4 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)4 URI (java.net.URI)3 List (java.util.List)3 Test (org.junit.jupiter.api.Test)3 JSONObject (com.alibaba.fastjson.JSONObject)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 RealNameAuthentication (com.itrus.portal.db.RealNameAuthentication)2 RealNameAuthenticationExample (com.itrus.portal.db.RealNameAuthenticationExample)2 GitHubDTO (com.nixmash.blog.jpa.dto.GitHubDTO)2