Package com.jcabi.http.wire
Class AutoRedirectingWire
java.lang.Object
com.jcabi.http.wire.AutoRedirectingWire
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionAutoRedirectingWire(Wire wire) Public ctor.AutoRedirectingWire(Wire wire, int retries) Public ctor. -
Method Summary
Modifier and TypeMethodDescriptionsend(Request req, String home, String method, Collection<Map.Entry<String, String>> headers, InputStream content, int connect, int read) Send request and return response.
-
Constructor Details
-
AutoRedirectingWire
Public ctor.- Parameters:
wire- Original wire
-
AutoRedirectingWire
Public ctor.- Parameters:
wire- Original wireretries- Maximum number of retries
-
-
Method Details
-
send
public Response send(Request req, String home, String method, Collection<Map.Entry<String, String>> headers, InputStream content, int connect, int read) throws IOExceptionDescription copied from interface:WireSend request and return response.- Specified by:
sendin interfaceWire- Parameters:
req- Requesthome- URI to fetchmethod- HTTP methodheaders- Headerscontent- HTTP bodyconnect- The connect timeoutread- The read timeout- Returns:
- Response obtained
- Throws:
IOException- if fails
-