Class AutoRedirectingWire

  • All Implemented Interfaces:
    Wire

    @Immutable
    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("http://goggle.com")
       .through(AutoRedirectingWire.class)
       .header(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN)
       .fetch()
       .body();

    The class is immutable and thread-safe.

    Since:
    1.6
    • Constructor Detail

      • AutoRedirectingWire

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

        public AutoRedirectingWire​(Wire wire,
                                   int retries)
        Public ctor.
        Parameters:
        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
        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