Class RetryWire

  • All Implemented Interfaces:
    Wire

    @Immutable
    public final class RetryWire
    extends Object
    implements Wire
    Wire that retries a few times before giving up and throwing exception.

    This wire retries again (at least three times) if an original one throws IOException:

     String html = new JdkRequest("http://goggle.com")
       .through(RetryWire.class)
       .header(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN)
       .fetch()
       .body();

    Since version 1.9 this wire retries also if HTTP status code is between 500 and 599.

    The class is immutable and thread-safe.

    Since:
    0.10
    • Constructor Detail

      • RetryWire

        public RetryWire​(Wire wire)
        Public ctor.
        Parameters:
        wire - Original wire
    • Method Detail

      • send

        public Response send​(Request req,
                             String home,
                             String method,
                             Collection<Map.Entry<String,​String>> headers,
                             InputStream content,
                             int connect,
                             int read)
                      throws IOException
        Description copied from interface: Wire
        Send request and return response.
        Specified by:
        send in interface Wire
        Parameters:
        req - Request
        home - URI to fetch
        method - HTTP method
        headers - Headers
        content - HTTP body
        connect - The connect timeout
        read - The read timeout
        Returns:
        Response obtained
        Throws:
        IOException - if fails