Class VManagerHttpClient

java.lang.Object
org.jenkinsci.plugins.vmanager.charts.util.VManagerHttpClient

public final class VManagerHttpClient extends Object
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 HttpURLConnection that trusts all certs / hostnames (vManager servers commonly use self-signed certs);
  • HTTP GET returning the response body as a UTF-8 string;
  • HTTP POST of 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.

  • Field Details

  • Method Details

    • openConnection

      public static HttpURLConnection openConnection(String urlStr) throws IOException
      Opens a connection that trusts all certificates and hostnames. Returns an HttpsURLConnection for https:// URLs, a plain HttpURLConnection otherwise.
      Throws:
      IOException
    • getJson

      public static String getJson(String urlStr, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials creds) throws IOException
      HTTP GET. creds may be null for 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
      HTTP POST of a JSON body. creds may be null.
      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 IOException
      HTTP POST of 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, or null.
      extraHeaders - extra request headers to set (e.g. x-vmgr-routing-retain); may be null.
      Throws:
      IOException