Class FhirRequestBuilder
- java.lang.Object
-
- org.hl7.fhir.dstu3.utils.client.network.FhirRequestBuilder
-
public class FhirRequestBuilder extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringCONTENT_LOCATION_HEADERprotected static StringDEFAULT_CHARSETprotected static StringHEADER_PROXY_AUTHprotected static StringHTTP_PROXY_PASSprotected static StringHTTP_PROXY_USERprotected static StringLOCATION_HEADER
-
Constructor Summary
Constructors Constructor Description FhirRequestBuilder(okhttp3.Request.Builder httpRequest)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static voidaddDefaultHeaders(okhttp3.Request.Builder request, okhttp3.Headers headers)Adds necessary headers for all REST requests.protected static voidaddHeaders(okhttp3.Request.Builder request, okhttp3.Headers headers)Iterates through the passed inHeadersand adds them to the providedRequest.Builder.protected static voidaddResourceFormatHeaders(okhttp3.Request.Builder request, String format)Adds necessary headers for the given resource format provided.protected okhttp3.RequestbuildRequest()<T extends Resource>
ResourceRequest<T>execute()BundleexecuteAsBatch()protected static voidformatHeaders(okhttp3.Request.Builder request, String format, okhttp3.Headers headers)Adds necessary default headers, formatting headers, and any passed inHeadersto the passed inRequest.Builderprotected okhttp3.OkHttpClientgetHttpClient()We only ever want to have one copy of the HttpClient kicking around at any given time.protected static StringgetLocationHeader(okhttp3.Headers headers)Extracts the 'location' header from the passes inHeaders.protected IParsergetParser(String format)Returns the appropriate parser based on the format type passed in.protected static booleanhasError(OperationOutcome oo)Returns true if any of theOperationOutcome.OperationOutcomeIssueComponentwithin the providedOperationOutcomehave anOperationOutcome.IssueSeverityofOperationOutcome.IssueSeverity.ERRORorOperationOutcome.IssueSeverity.FATALprotected voidlog(int responseCode, okhttp3.Headers responseHeaders, byte[] responseBody)Logs the givenResponse, using the currentToolingClientLogger.protected voidlog(String method, String url, okhttp3.Headers requestHeaders, byte[] requestBody)Logs the givenRequest, using the currentToolingClientLogger.protected BundleunmarshalFeed(okhttp3.Response response, String format)Unmarshalls Bundle from response stream.protected <T extends Resource>
TunmarshalReference(okhttp3.Response response, String format)Unmarshalls a resource from the response stream.FhirRequestBuilderwithHeaders(okhttp3.Headers headers)FhirRequestBuilderwithLogger(org.hl7.fhir.utilities.ToolingClientLogger logger)FhirRequestBuilderwithMessage(String message)FhirRequestBuilderwithResourceFormat(String resourceFormat)FhirRequestBuilderwithRetryCount(int retryCount)FhirRequestBuilderwithTimeout(long timeout, TimeUnit unit)
-
-
-
Field Detail
-
HTTP_PROXY_USER
protected static final String HTTP_PROXY_USER
- See Also:
- Constant Field Values
-
HTTP_PROXY_PASS
protected static final String HTTP_PROXY_PASS
- See Also:
- Constant Field Values
-
HEADER_PROXY_AUTH
protected static final String HEADER_PROXY_AUTH
- See Also:
- Constant Field Values
-
LOCATION_HEADER
protected static final String LOCATION_HEADER
- See Also:
- Constant Field Values
-
CONTENT_LOCATION_HEADER
protected static final String CONTENT_LOCATION_HEADER
- See Also:
- Constant Field Values
-
DEFAULT_CHARSET
protected static final String DEFAULT_CHARSET
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FhirRequestBuilder
public FhirRequestBuilder(okhttp3.Request.Builder httpRequest)
-
-
Method Detail
-
formatHeaders
protected static void formatHeaders(okhttp3.Request.Builder request, String format, okhttp3.Headers headers)
Adds necessary default headers, formatting headers, and any passed inHeadersto the passed inRequest.Builder- Parameters:
request-Request.Builderto add headers to.format- ExpectedResourceformat.headers- Any additionalHeadersto 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
- Accept-Charset :
DEFAULT_CHARSET- Parameters:
request-Request.Builderto 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.Builderto add default headers to.
-
addHeaders
protected static void addHeaders(okhttp3.Request.Builder request, okhttp3.Headers headers)
Iterates through the passed inHeadersand adds them to the providedRequest.Builder.- Parameters:
request-Request.Builderto add headers to.headers-Headersto add to request.
-
hasError
protected static boolean hasError(OperationOutcome oo)
Returns true if any of theOperationOutcome.OperationOutcomeIssueComponentwithin the providedOperationOutcomehave anOperationOutcome.IssueSeverityofOperationOutcome.IssueSeverity.ERRORorOperationOutcome.IssueSeverity.FATAL- Parameters:
oo-OperationOutcometo evaluate.- Returns:
Boolean.TRUEif an error exists.
-
getLocationHeader
protected static String getLocationHeader(okhttp3.Headers headers)
Extracts the 'location' header from the passes inHeaders. If no value for 'location' exists, the value for 'content-location' is returned. If neither header exists, we return null.- Parameters:
headers-Headersto evaluate- Returns:
Stringheader 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 theOkHttpClient.newBuilder()method. That will return a builder that shares the same connection pool, dispatcher, and configuration with the original client. TheOkHttpClientuses 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:
OkHttpClientinstance
-
withResourceFormat
public FhirRequestBuilder withResourceFormat(String resourceFormat)
-
withHeaders
public FhirRequestBuilder withHeaders(okhttp3.Headers headers)
-
withMessage
public FhirRequestBuilder withMessage(String message)
-
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
public Bundle executeAsBatch() throws IOException
- 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:
JsonParserorXmlParser
-
log
protected void log(String method, String url, okhttp3.Headers requestHeaders, byte[] requestBody)
Logs the givenRequest, using the currentToolingClientLogger. If the currentloggeris null, no action is taken.- Parameters:
method- HTTP request methodurl- request URLrequestHeaders-Headersfor requestrequestBody- Byte array request
-
log
protected void log(int responseCode, okhttp3.Headers responseHeaders, byte[] responseBody)
Logs the givenResponse, using the currentToolingClientLogger. If the currentloggeris null, no action is taken.- Parameters:
responseCode- HTTP response coderesponseHeaders-Headersfrom responseresponseBody- Byte array response
-
-