Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
Unwrapping ExecutionException when executed synchronously. Fixes #139
Browse files Browse the repository at this point in the history
  • Loading branch information
nurkiewicz committed Dec 21, 2014
1 parent fd80e8e commit c1d0aca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -28,7 +30,11 @@ final class RestExecutor<T> {
}

ResponseEntity<T> exchange(HttpMethod httpMethod, Map params, Class<T> responseType) {
return exchangeInternal(params, httpMethod, responseType).get()
try {
return exchangeInternal(params, httpMethod, responseType).get()
} catch (ExecutionException e) {
throw e.cause
}
}

ListenableFuture<ResponseEntity<T>> exchangeAsync(HttpMethod httpMethod, Map params, Class<T> responseType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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')
}

}

0 comments on commit c1d0aca

Please sign in to comment.