Browse Source

Correctly handle IOExceptions wrapped by Ribbon.

pull/89/head
adriancole 11 years ago
parent
commit
68b54dcf65
  1. 1
      CHANGES.md
  2. 3
      ribbon/src/main/java/feign/ribbon/RibbonModule.java
  3. 30
      ribbon/src/test/java/feign/ribbon/RibbonClientTest.java

1
CHANGES.md

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
### Version 5.1.0
* Correctly handle IOExceptions wrapped by Ribbon.
* Miscellaneous findbugs fixes.
### Version 5.0.1

3
ribbon/src/main/java/feign/ribbon/RibbonModule.java

@ -76,6 +76,9 @@ public class RibbonModule { @@ -76,6 +76,9 @@ public class RibbonModule {
LBClient.RibbonRequest ribbonRequest = new LBClient.RibbonRequest(request, uriWithoutSchemeAndPort);
return lbClient(clientName).executeWithLoadBalancer(ribbonRequest).toResponse();
} catch (ClientException e) {
if (e.getCause() instanceof IOException) {
throw IOException.class.cast(e.getCause());
}
throw Throwables.propagate(e);
}
}

30
ribbon/src/test/java/feign/ribbon/RibbonClientTest.java

@ -17,6 +17,7 @@ package feign.ribbon; @@ -17,6 +17,7 @@ package feign.ribbon;
import com.google.mockwebserver.MockResponse;
import com.google.mockwebserver.MockWebServer;
import com.google.mockwebserver.SocketPolicy;
import dagger.Provides;
import feign.Feign;
import feign.RequestLine;
@ -36,7 +37,7 @@ public class RibbonClientTest { @@ -36,7 +37,7 @@ public class RibbonClientTest {
interface TestInterface {
@RequestLine("POST /") void post();
@dagger.Module(injects = Feign.class, addsTo = Feign.Defaults.class)
@dagger.Module(injects = Feign.class, overrides = true, addsTo = Feign.Defaults.class)
static class Module {
@Provides Decoder defaultDecoder() {
return new Decoder.Default();
@ -80,6 +81,33 @@ public class RibbonClientTest { @@ -80,6 +81,33 @@ public class RibbonClientTest {
}
}
@Test
public void ioExceptionRetry() throws IOException, InterruptedException {
String client = "RibbonClientTest-ioExceptionRetry";
String serverListKey = client + ".ribbon.listOfServers";
MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.DISCONNECT_AT_START));
server.enqueue(new MockResponse().setBody("success!".getBytes(UTF_8)));
server.play();
getConfigInstance().setProperty(serverListKey, hostAndPort(server.getUrl("")));
try {
TestInterface api = Feign.create(TestInterface.class, "http://" + client, new TestInterface.Module(), new RibbonModule());
api.post();
assertEquals(server.getRequestCount(), 2);
// TODO: verify ribbon stats match
// assertEquals(target.lb().getLoadBalancerStats().getSingleServerStat())
} finally {
server.shutdown();
getConfigInstance().clearProperty(serverListKey);
}
}
static String hostAndPort(URL url) {
// our build slaves have underscores in their hostnames which aren't permitted by ribbon
return "localhost:" + url.getPort();

Loading…
Cancel
Save