Class AutoRedirectingWire

  • All Implemented Interfaces:

    public final class AutoRedirectingWire
    extends Object
    implements Wire
    Auto Redirecting Wire.

    This wire will retry a request a certain number of times (default: 5) after a short delay when a HTTP response with a status code of 300-399 is received. On every next attempt a new URL will be used, according to the value of Location HTTP header of the response.

    If the maximum number of retries are reached, the last response received is returned to the caller, regardless of its status code.

     String html = new JdkRequest("")
       .header(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN)

    The class is immutable and thread-safe.

    • Constructor Detail

      • AutoRedirectingWire

        public AutoRedirectingWire​(Wire wire)
        Public ctor.
        wire - Original wire
      • AutoRedirectingWire

        public AutoRedirectingWire​(Wire wire,
                                   int retries)
        Public ctor.
        wire - Original wire
        retries - Maximum number of retries
    • 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
        req - Request
        home - URI to fetch
        method - HTTP method
        headers - Headers
        content - HTTP body
        connect - The connect timeout
        read - The read timeout
        Response obtained
        IOException - if fails