Class VManagerHttpClient
java.lang.Object
org.jenkinsci.plugins.vmanager.charts.util.VManagerHttpClient
Single shared HTTP client for all vManager REST calls in this plugin.
Centralises the three things that were previously duplicated across
VManagerSessionsClient, MetricDefinition.DescriptorImpl,
ChartDefinition.DescriptorImpl and CustomMetricsRunListener:
- opening an
HttpURLConnectionthat trusts all certs / hostnames (vManager servers commonly use self-signed certs); - HTTP
GETreturning the response body as a UTF-8 string; - HTTP
POSTof a JSON body returning the response body as a UTF-8 string.
Both verbs add HTTP Basic auth from the supplied credentials (when
non-null), use a 60000 ms connect/read timeout, and
raise an IOException that includes the error body for any
HTTP ≥ 400 response.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classHTTP response container: trimmed body + a case-insensitive view of the response headers. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetJson(String urlStr, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials creds) HTTPGET.static HttpURLConnectionopenConnection(String urlStr) Opens a connection that trusts all certificates and hostnames.static StringpostJson(String urlStr, String jsonBody, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials creds) HTTPPOSTof a JSON body.static VManagerHttpClient.ResponsepostJsonFull(String urlStr, String jsonBody, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials creds, Map<String, String> extraHeaders) HTTPPOSTof a JSON body, with optional extra request headers, returning both response body and response headers.
-
Field Details
-
TIMEOUT_MS
public static final int TIMEOUT_MS- See Also:
-
READ_TIMEOUT_MS
public static final int READ_TIMEOUT_MS- See Also:
-
-
Method Details
-
openConnection
Opens a connection that trusts all certificates and hostnames. Returns anHttpsURLConnectionforhttps://URLs, a plainHttpURLConnectionotherwise.- Throws:
IOException
-
getJson
public static String getJson(String urlStr, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials creds) throws IOException HTTPGET.credsmay benullfor unauthenticated.- Returns:
- the response body as a trimmed UTF-8 string.
- Throws:
IOException
-
postJson
public static String postJson(String urlStr, String jsonBody, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials creds) throws IOException HTTPPOSTof a JSON body.credsmay benull.- Returns:
- the response body as a trimmed UTF-8 string.
- Throws:
IOException
-
postJsonFull
public static VManagerHttpClient.Response postJsonFull(String urlStr, String jsonBody, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials creds, Map<String, String> extraHeaders) throws IOExceptionHTTPPOSTof a JSON body, with optional extra request headers, returning both response body and response headers.- Parameters:
urlStr- full URL.jsonBody- JSON request body.creds- HTTP Basic credentials, ornull.extraHeaders- extra request headers to set (e.g.x-vmgr-routing-retain); may benull.- Throws:
IOException
-