public final class RobustHTTPClient extends Object implements Serializable
| Modifier and Type | Class and Description |
|---|---|
static interface |
RobustHTTPClient.ConnectionCreator
How to initiate a connection.
|
static interface |
RobustHTTPClient.ConnectionUser
What to do with a successful (2xx) connection.
|
| Constructor and Description |
|---|
RobustHTTPClient()
Creates a client configured with reasonable defaults from system properties.
|
| Modifier and Type | Method and Description |
|---|---|
void |
connect(String whatConcise,
String whatVerbose,
RobustHTTPClient.ConnectionCreator connectionCreator,
RobustHTTPClient.ConnectionUser connectionUser,
hudson.model.TaskListener listener)
Perform an HTTP network operation with appropriate timeouts and retries.
|
void |
copyFromRemotely(hudson.FilePath f,
URL url,
hudson.model.TaskListener listener)
Like
FilePath.copyFrom(URL) but using downloadFile(java.io.File, java.net.URL, hudson.model.TaskListener) and running remotely on the agent. |
void |
downloadFile(File f,
URL url,
hudson.model.TaskListener listener)
Download a file from a URL.
|
static String |
sanitize(URL url)
Mask out query string or user info details in a URL.
|
void |
setStopAfterAttemptNumber(int stopAfterAttemptNumber)
Number of upload/download attempts of nonfatal errors before giving up.
|
void |
setTimeout(long timeout,
TimeUnit unit)
Time to permit a single upload/download attempt to take.
|
void |
setWaitMaximum(long waitMaximum,
TimeUnit unit)
Maximum time between upload/download attempts.
|
void |
setWaitMultiplier(long waitMultiplier,
TimeUnit unit)
Initial time between first and second upload/download attempts.
|
void |
uploadFile(File f,
String contentType,
URL url,
hudson.model.TaskListener listener)
Upload a file to a URL with a specific content type.
|
void |
uploadFile(File f,
URL url,
hudson.model.TaskListener listener)
Upload a file to a URL.
|
public RobustHTTPClient()
This constructor should be run in the Jenkins master.
To make requests from an agent JVM, create a final field of this type in your MasterToSlaveCallable or similar;
set it with a field initializer (run in the callable’s constructor on the master),
letting the agent deserialize the configuration.
public void setStopAfterAttemptNumber(int stopAfterAttemptNumber)
public void setWaitMultiplier(long waitMultiplier,
TimeUnit unit)
public void setWaitMaximum(long waitMaximum,
TimeUnit unit)
public void setTimeout(long timeout,
TimeUnit unit)
public void connect(String whatConcise, String whatVerbose, @NonNull RobustHTTPClient.ConnectionCreator connectionCreator, @NonNull RobustHTTPClient.ConnectionUser connectionUser, @NonNull hudson.model.TaskListener listener) throws IOException, InterruptedException
whatConcise - a short description of the operation, like upload, used when retryingwhatVerbose - a longer description of the operation, like uploading … to …, used when retrying (see sanitize(java.net.URL))connectionCreator - how to establish a connection prior to getting the server’s responseconnectionUser - what to do, if anything, after a successful (2xx) server responselistener - a place to print messagesIOException - if there is an unrecoverable error; AbortException will be used where appropriateInterruptedException - if an operation, or a sleep between retries, is interruptedpublic static String sanitize(URL url)
VirtualFile#toExternalURL.url - any URLURL.getQuery() and/or URL.getUserInfo() concealedpublic void uploadFile(File f, URL url, hudson.model.TaskListener listener) throws IOException, InterruptedException
IOExceptionInterruptedExceptionpublic void uploadFile(File f, String contentType, URL url, hudson.model.TaskListener listener) throws IOException, InterruptedException
f - the file to uploadcontentType - the content type for the specified fileIOExceptionInterruptedExceptionpublic void downloadFile(File f, URL url, hudson.model.TaskListener listener) throws IOException, InterruptedException
IOExceptionInterruptedExceptionpublic void copyFromRemotely(hudson.FilePath f,
URL url,
hudson.model.TaskListener listener)
throws IOException,
InterruptedException
FilePath.copyFrom(URL) but using downloadFile(java.io.File, java.net.URL, hudson.model.TaskListener) and running remotely on the agent.IOExceptionInterruptedExceptionCopyright © 2016–2021. All rights reserved.