From c1d0acaa24c09b328faa92ca3e6065de40039949 Mon Sep 17 00:00:00 2001 From: Tomasz Nurkiewicz Date: Sun, 21 Dec 2014 13:48:35 +0100 Subject: [PATCH] Unwrapping ExecutionException when executed synchronously. Fixes #139 --- .../common/response/executor/RestExecutor.groovy | 8 +++++++- .../response/executor/RestExecutorTest.groovy | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/micro-infra-spring-base/src/main/groovy/com/ofg/infrastructure/web/resttemplate/fluent/common/response/executor/RestExecutor.groovy b/micro-infra-spring-base/src/main/groovy/com/ofg/infrastructure/web/resttemplate/fluent/common/response/executor/RestExecutor.groovy index b218b314..b4cf7bfa 100644 --- a/micro-infra-spring-base/src/main/groovy/com/ofg/infrastructure/web/resttemplate/fluent/common/response/executor/RestExecutor.groovy +++ b/micro-infra-spring-base/src/main/groovy/com/ofg/infrastructure/web/resttemplate/fluent/common/response/executor/RestExecutor.groovy @@ -12,6 +12,8 @@ import org.springframework.http.HttpMethod import org.springframework.http.ResponseEntity import org.springframework.web.client.RestOperations +import java.util.concurrent.ExecutionException + import static com.ofg.infrastructure.web.resttemplate.fluent.common.response.executor.UrlParsingUtils.appendPathToHost /** @@ -28,7 +30,11 @@ final class RestExecutor { } ResponseEntity exchange(HttpMethod httpMethod, Map params, Class responseType) { - return exchangeInternal(params, httpMethod, responseType).get() + try { + return exchangeInternal(params, httpMethod, responseType).get() + } catch (ExecutionException e) { + throw e.cause + } } ListenableFuture> exchangeAsync(HttpMethod httpMethod, Map params, Class responseType) { diff --git a/micro-infra-spring-base/src/test/groovy/com/ofg/infrastructure/web/resttemplate/fluent/common/response/executor/RestExecutorTest.groovy b/micro-infra-spring-base/src/test/groovy/com/ofg/infrastructure/web/resttemplate/fluent/common/response/executor/RestExecutorTest.groovy index f283f02d..535c84ce 100644 --- a/micro-infra-spring-base/src/test/groovy/com/ofg/infrastructure/web/resttemplate/fluent/common/response/executor/RestExecutorTest.groovy +++ b/micro-infra-spring-base/src/test/groovy/com/ofg/infrastructure/web/resttemplate/fluent/common/response/executor/RestExecutorTest.groovy @@ -3,6 +3,7 @@ package com.ofg.infrastructure.web.resttemplate.fluent.common.response.executor import com.nurkiewicz.asyncretry.SyncRetryExecutor import com.ofg.infrastructure.web.resttemplate.custom.RestTemplate import org.springframework.http.HttpMethod +import org.springframework.web.client.ResourceAccessException import spock.lang.Specification class RestExecutorTest extends Specification { @@ -19,4 +20,16 @@ class RestExecutorTest extends Specification { e.message.contains("retryUsing") } + def 'should propagate original RestTemplate exception'() { + given: + RestExecutor executor = new RestExecutor( + new RestTemplate(), SyncRetryExecutor.INSTANCE) + when: + executor.exchange(HttpMethod.GET, [host: 'http://localhost:7777', url: '/api'.toURI()], Object) + + then: + ResourceAccessException e = thrown(ResourceAccessException) + e.message.contains('localhost:7777') + } + }