Class FhirRequestBuilder

java.lang.Object
org.hl7.fhir.dstu3.utils.client.network.FhirRequestBuilder

public class FhirRequestBuilder extends Object
  • Field Details

  • Constructor Details

  • Method Details

    • formatHeaders

      protected static void formatHeaders(okhttp3.Request.Builder request, String format, okhttp3.Headers headers)
      Adds necessary default headers, formatting headers, and any passed in Headers to the passed in Request.Builder
      Parameters:
      request - Request.Builder to add headers to.
      format - Expected Resource format.
      headers - Any additional Headers to add to the request.
    • addDefaultHeaders

      protected static void addDefaultHeaders(okhttp3.Request.Builder request, okhttp3.Headers headers)
      Adds necessary headers for all REST requests.
    • User-Agent : hapi-fhir-tooling-client
    • Parameters:
      request - Request.Builder to add default headers to.
    • addResourceFormatHeaders

      protected static void addResourceFormatHeaders(okhttp3.Request.Builder request, String format)
      Adds necessary headers for the given resource format provided.
      Parameters:
      request - Request.Builder to add default headers to.
    • addHeaders

      protected static void addHeaders(okhttp3.Request.Builder request, okhttp3.Headers headers)
      Iterates through the passed in Headers and adds them to the provided Request.Builder.
      Parameters:
      request - Request.Builder to add headers to.
      headers - Headers to add to request.
    • hasError

      protected static boolean hasError(OperationOutcome oo)
      Parameters:
      oo - OperationOutcome to evaluate.
      Returns:
      Boolean.TRUE if an error exists.
    • getLocationHeader

      protected static String getLocationHeader(okhttp3.Headers headers)
      Extracts the 'location' header from the passes in Headers. If no value for 'location' exists, the value for 'content-location' is returned. If neither header exists, we return null.
      Parameters:
      headers - Headers to evaluate
      Returns:
      String header value, or null if no location headers are set.
    • getHttpClient

      protected okhttp3.OkHttpClient getHttpClient()
      We only ever want to have one copy of the HttpClient kicking around at any given time. If we need to make changes to any configuration, such as proxy settings, timeout, caches, etc, we can do a per-call configuration through the OkHttpClient.newBuilder() method. That will return a builder that shares the same connection pool, dispatcher, and configuration with the original client.

      The OkHttpClient uses the proxy auth properties set in the current system properties. The reason we don't set the proxy address and authentication explicitly, is due to the fact that this class is often used in conjunction with other http client tools which rely on the system.properties settings to determine proxy settings. It's easier to keep the method consistent across the board. ...for now.
      Returns:
      OkHttpClient instance
    • withResourceFormat

      public FhirRequestBuilder withResourceFormat(String resourceFormat)
    • withHeaders

      public FhirRequestBuilder withHeaders(okhttp3.Headers headers)
    • withMessage

    • withRetryCount

      public FhirRequestBuilder withRetryCount(int retryCount)
    • withLogger

      public FhirRequestBuilder withLogger(org.hl7.fhir.utilities.ToolingClientLogger logger)
    • withTimeout

      public FhirRequestBuilder withTimeout(long timeout, TimeUnit unit)
    • buildRequest

      protected okhttp3.Request buildRequest()
    • execute

      public <T extends Resource> ResourceRequest<T> execute() throws IOException
      Throws:
      IOException
    • executeAsBatch

      Throws:
      IOException
    • unmarshalReference

      protected <T extends Resource> T unmarshalReference(okhttp3.Response response, String format)
      Unmarshalls a resource from the response stream.
    • unmarshalFeed

      protected Bundle unmarshalFeed(okhttp3.Response response, String format)
      Unmarshalls Bundle from response stream.
    • getParser

      protected IParser getParser(String format)
      Returns the appropriate parser based on the format type passed in. Defaults to XML parser if a blank format is provided...because reasons.

      Currently supports only "json" and "xml" formats.

      Parameters:
      format - One of "json" or "xml".
      Returns:
      JsonParser or XmlParser
    • log

      protected void log(String method, String url, okhttp3.Headers requestHeaders, byte[] requestBody)
      Logs the given Request, using the current ToolingClientLogger. If the current logger is null, no action is taken.
      Parameters:
      method - HTTP request method
      url - request URL
      requestHeaders - Headers for request
      requestBody - Byte array request
    • log

      protected void log(int responseCode, okhttp3.Headers responseHeaders, byte[] responseBody)
      Logs the given Response, using the current ToolingClientLogger. If the current logger is null, no action is taken.
      Parameters:
      responseCode - HTTP response code
      responseHeaders - Headers from response
      responseBody - Byte array response