Class RobustHTTPClient
java.lang.Object
org.jenkinsci.plugins.workflowhttp.cps.RobustHTTPClient
- All Implemented Interfaces:
 Serializable
Utility to make HTTP connections with protection against transient failures.
- See Also:
 
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceHow to initiate a connection.static interfaceWhat to do with a successful (2xx) connection. - 
Constructor Summary
ConstructorsConstructorDescriptionCreates a client configured with reasonable defaults from system properties. - 
Method Summary
Modifier and TypeMethodDescriptionvoidconnect(String whatConcise, String whatVerbose, RobustHTTPClient.ConnectionCreator connectionCreator, RobustHTTPClient.ConnectionUser connectionUser, TaskListener listener) Perform an HTTP network operation with appropriate timeouts and retries.voidcopyFromRemotely(FilePath f, URL url, TaskListener listener) LikeFilePath.copyFrom(URL)but usingdownloadFile(java.io.File, java.net.URL, hudson.model.TaskListener)and running remotely on the agent.voiddownloadFile(File f, URL url, TaskListener listener) Download a file from a URL.static StringMask out query string or user info details in a URL.voidsetStopAfterAttemptNumber(int stopAfterAttemptNumber) Number of upload/download attempts of nonfatal errors before giving up.voidsetTimeout(long timeout, TimeUnit unit) Time to permit a single upload/download attempt to take.voidsetWaitMaximum(long waitMaximum, TimeUnit unit) Maximum time between upload/download attempts.voidsetWaitMultiplier(long waitMultiplier, TimeUnit unit) Initial time between first and second upload/download attempts.voiduploadFile(File f, String contentType, URL url, TaskListener listener) Upload a file to a URL with a specific content type.voiduploadFile(File f, URL url, TaskListener listener) Upload a file to a URL. 
- 
Constructor Details
- 
RobustHTTPClient
public RobustHTTPClient()Creates a client configured with reasonable defaults from system properties. THIS IS A ADAPTED COPY OF https://github.com/jenkinsci/apache-httpcomponents-client-4-api-plugin but uses httpclient5 and retries on all errorsThis constructor should be run in the Jenkins master. To make requests from an agent JVM, create a
finalfield of this type in yourMasterToSlaveCallableor similar; set it with a field initializer (run in the callable’s constructor on the master), letting the agent deserialize the configuration. 
 - 
 - 
Method Details
- 
sanitize
Mask out query string or user info details in a URL. Useful in conjunction withVirtualFile#toExternalURL.- Parameters:
 url- any URL- Returns:
 - the same, but with any 
URL.getQuery()and/orURL.getUserInfo()concealed 
 - 
setStopAfterAttemptNumber
public void setStopAfterAttemptNumber(int stopAfterAttemptNumber) Number of upload/download attempts of nonfatal errors before giving up. - 
setWaitMultiplier
Initial time between first and second upload/download attempts. Subsequent ones increase exponentially. Note that this is not a randomized exponential backoff; and the base of the exponent is currently hard-coded to 2. - 
setWaitMaximum
Maximum time between upload/download attempts. - 
setTimeout
Time to permit a single upload/download attempt to take. - 
connect
public void connect(String whatConcise, String whatVerbose, @NonNull RobustHTTPClient.ConnectionCreator connectionCreator, @NonNull RobustHTTPClient.ConnectionUser connectionUser, @NonNull TaskListener listener) throws IOException, InterruptedException Perform an HTTP network operation with appropriate timeouts and retries. 2xx status codes are considered successful. Low-level network errors (for example, DNS failures) and 5xx server responses are considered retryable, as are timeouts on individual attempts; other response codes (normally 3xx or 4xx) are treated as immediate failures.- Parameters:
 whatConcise- a short description of the operation, likeupload, used when retryingwhatVerbose- a longer description of the operation, likeuploading … to …, used when retrying (seesanitize(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 messages- Throws:
 IOException- if there is an unrecoverable error;AbortExceptionwill be used where appropriateInterruptedException- if an operation, or a sleep between retries, is interrupted
 - 
uploadFile
public void uploadFile(File f, URL url, TaskListener listener) throws IOException, InterruptedException Upload a file to a URL.- Throws:
 IOExceptionInterruptedException
 - 
uploadFile
public void uploadFile(File f, String contentType, URL url, TaskListener listener) throws IOException, InterruptedException Upload a file to a URL with a specific content type.- Parameters:
 f- the file to uploadcontentType- the content type for the specified file- Throws:
 IOExceptionInterruptedException
 - 
downloadFile
public void downloadFile(File f, URL url, TaskListener listener) throws IOException, InterruptedException Download a file from a URL.- Throws:
 IOExceptionInterruptedException
 - 
copyFromRemotely
public void copyFromRemotely(FilePath f, URL url, TaskListener listener) throws IOException, InterruptedException LikeFilePath.copyFrom(URL)but usingdownloadFile(java.io.File, java.net.URL, hudson.model.TaskListener)and running remotely on the agent.- Throws:
 IOExceptionInterruptedException
 
 -