Compare commits

...

7 Commits

Author SHA1 Message Date
dotasek 765ba8baed Fix get bytes for -1 or chunked content 2024-11-08 15:22:50 -05:00
Grahame Grieve 8b43a95aa8 update vsac access code 2024-11-09 06:33:07 +10:30
dotasek d724a27d95 Final rename 2024-11-08 14:35:36 -05:00
dotasek fb6a22c3b1 Clean up comments and JavaDoc 2024-11-08 14:29:40 -05:00
dotasek cc00bb903c Move tests to utilities. Clarify missing functionality 2024-11-08 11:26:43 -05:00
dotasek ebcbf4db49 More TODO erasures. Plus found missing functionality 2024-11-08 11:18:57 -05:00
dotasek 2bbfcb8845 Resolve all deletions enclosed in FIXME + fix headers in dstu2 postfeed 2024-11-08 11:08:06 -05:00
28 changed files with 157 additions and 317 deletions

View File

@ -1,6 +1,5 @@
package org.hl7.fhir.convertors.misc; package org.hl7.fhir.convertors.misc;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
@ -395,7 +394,7 @@ public class ICD11Generator {
private JsonObject fetchJson(String source) throws IOException { private JsonObject fetchJson(String source) throws IOException {
HTTPResult res = ManagedWebAccess.builder().withHeader("API-Version", "v2").withHeader("Accept-Language", "en").get(source,"application/json"); HTTPResult res = ManagedWebAccess.accessor().withHeader("API-Version", "v2").withHeader("Accept-Language", "en").get(source,"application/json");
res.checkThrowException(); res.checkThrowException();
return JsonParser.parseObject(res.getContent()); return JsonParser.parseObject(res.getContent());
} }

View File

@ -46,10 +46,10 @@ public class VSACImporter extends OIDBasedValueSetImporter {
public static void main(String[] args) throws FHIRException, IOException, ParseException, URISyntaxException { public static void main(String[] args) throws FHIRException, IOException, ParseException, URISyntaxException {
VSACImporter self = new VSACImporter(); VSACImporter self = new VSACImporter();
self.process(args[0], args[1], args[2], "true".equals(args[3]), "true".equals(args[4])); self.process(args[0], args[1], "true".equals(args[2]), "true".equals(args[3]));
} }
private void process(String source, String dest, String apiKey, boolean onlyNew, boolean onlyActive) throws FHIRException, IOException, URISyntaxException { private void process(String source, String dest, boolean onlyNew, boolean onlyActive) throws FHIRException, IOException, URISyntaxException {
CSVReader csv = new CSVReader(ManagedFileAccess.inStream(source)); CSVReader csv = new CSVReader(ManagedFileAccess.inStream(source));
csv.readHeaders(); csv.readHeaders();
Map<String, String> errs = new HashMap<>(); Map<String, String> errs = new HashMap<>();
@ -121,6 +121,7 @@ public class VSACImporter extends OIDBasedValueSetImporter {
oo.addIssue().setSeverity(IssueSeverity.ERROR).setCode(IssueType.EXCEPTION).setDiagnostics(errs.get(oid)).addLocation(oid); oo.addIssue().setSeverity(IssueSeverity.ERROR).setCode(IssueType.EXCEPTION).setDiagnostics(errs.get(oid)).addLocation(oid);
} }
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(ManagedFileAccess.outStream(Utilities.path(dest, "other", "OperationOutcome-vsac-errors.json")), oo); new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(ManagedFileAccess.outStream(Utilities.path(dest, "other", "OperationOutcome-vsac-errors.json")), oo);
System.out.println();
System.out.println("Done. " + i + " ValueSets in "+Utilities.describeDuration(System.currentTimeMillis() - tt)); System.out.println("Done. " + i + " ValueSets in "+Utilities.describeDuration(System.currentTimeMillis() - tt));
} }

View File

@ -81,17 +81,10 @@ public class ClientUtils {
private static boolean debugging = false; private static boolean debugging = false;
/*
@Getter
@Setter
private HttpHost proxy;
*/
@Getter @Getter
@Setter @Setter
private int timeout = 5000; private int timeout = 5000;
@Setter @Setter
@Getter @Getter
private ToolingClientLogger logger; private ToolingClientLogger logger;
@ -109,8 +102,8 @@ public class ClientUtils {
private String contentLanguage; private String contentLanguage;
private final TimeUnit timeoutUnit = TimeUnit.MILLISECONDS; private final TimeUnit timeoutUnit = TimeUnit.MILLISECONDS;
protected ManagedFhirWebAccessor getManagedWebAccessBuilder() { protected ManagedFhirWebAccessor getManagedWebAccessor() {
return ManagedWebAccess.fhirBuilder().withRetries(retryCount).withTimeout(timeout, timeoutUnit).withLogger(logger); return ManagedWebAccess.fhirAccessor().withRetries(retryCount).withTimeout(timeout, timeoutUnit).withLogger(logger);
} }
public <T extends Resource> ResourceRequest<T> issueOptionsRequest(URI optionsUri, String resourceFormat, public <T extends Resource> ResourceRequest<T> issueOptionsRequest(URI optionsUri, String resourceFormat,
@ -119,9 +112,6 @@ public class ClientUtils {
throw new FHIRException("Network Access is prohibited in this context"); throw new FHIRException("Network Access is prohibited in this context");
} }
/*FIXME delete this after refactor
HttpOptions options = new HttpOptions(optionsUri);
*/
HTTPRequest httpRequest = new HTTPRequest() HTTPRequest httpRequest = new HTTPRequest()
.withMethod(HTTPRequest.HttpMethod.OPTIONS) .withMethod(HTTPRequest.HttpMethod.OPTIONS)
.withUrl(optionsUri.toString()); .withUrl(optionsUri.toString());
@ -133,9 +123,7 @@ public class ClientUtils {
if (FhirSettings.isProhibitNetworkAccess()) { if (FhirSettings.isProhibitNetworkAccess()) {
throw new FHIRException("Network Access is prohibited in this context"); throw new FHIRException("Network Access is prohibited in this context");
} }
/*FIXME delete this after refactor
HttpGet httpget = new HttpGet(resourceUri);
*/
HTTPRequest httpRequest = new HTTPRequest() HTTPRequest httpRequest = new HTTPRequest()
.withMethod(HTTPRequest.HttpMethod.GET) .withMethod(HTTPRequest.HttpMethod.GET)
.withUrl(resourceUri.toString()); .withUrl(resourceUri.toString());
@ -159,9 +147,7 @@ public class ClientUtils {
if (FhirSettings.isProhibitNetworkAccess()) { if (FhirSettings.isProhibitNetworkAccess()) {
throw new FHIRException("Network Access is prohibited in this context"); throw new FHIRException("Network Access is prohibited in this context");
} }
/*FIXME delete this after refactor
HttpPut httpPut = new HttpPut(resourceUri);
*/
HTTPRequest httpRequest = new HTTPRequest() HTTPRequest httpRequest = new HTTPRequest()
.withMethod(HTTPRequest.HttpMethod.PUT) .withMethod(HTTPRequest.HttpMethod.PUT)
.withUrl(resourceUri.toString()) .withUrl(resourceUri.toString())
@ -174,9 +160,7 @@ public class ClientUtils {
if (FhirSettings.isProhibitNetworkAccess()) { if (FhirSettings.isProhibitNetworkAccess()) {
throw new FHIRException("Network Access is prohibited in this context"); throw new FHIRException("Network Access is prohibited in this context");
} }
/*FIXME delete this after refactor
HttpPost httpPost = new HttpPost(resourceUri);
*/
HTTPRequest httpRequest = new HTTPRequest() HTTPRequest httpRequest = new HTTPRequest()
.withMethod(HTTPRequest.HttpMethod.POST) .withMethod(HTTPRequest.HttpMethod.POST)
.withUrl(resourceUri.toString()) .withUrl(resourceUri.toString())
@ -193,9 +177,7 @@ public class ClientUtils {
if (FhirSettings.isProhibitNetworkAccess()) { if (FhirSettings.isProhibitNetworkAccess()) {
throw new FHIRException("Network Access is prohibited in this context"); throw new FHIRException("Network Access is prohibited in this context");
} }
/*FIXME delete this after refactor
HttpGet httpget = new HttpGet(resourceUri);
*/
HTTPRequest httpRequest = new HTTPRequest() HTTPRequest httpRequest = new HTTPRequest()
.withMethod(HTTPRequest.HttpMethod.GET) .withMethod(HTTPRequest.HttpMethod.GET)
.withUrl(resourceUri.toString()); .withUrl(resourceUri.toString());
@ -208,9 +190,7 @@ public class ClientUtils {
if (FhirSettings.isProhibitNetworkAccess()) { if (FhirSettings.isProhibitNetworkAccess()) {
throw new FHIRException("Network Access is prohibited in this context"); throw new FHIRException("Network Access is prohibited in this context");
} }
/*FIXME delete this after refactor
HttpPost httpPost = new HttpPost(resourceUri);
*/
HTTPRequest httpRequest = new HTTPRequest() HTTPRequest httpRequest = new HTTPRequest()
.withMethod(HTTPRequest.HttpMethod.POST) .withMethod(HTTPRequest.HttpMethod.POST)
.withUrl(resourceUri.toString()) .withUrl(resourceUri.toString())
@ -224,9 +204,7 @@ public class ClientUtils {
if (FhirSettings.isProhibitNetworkAccess()) { if (FhirSettings.isProhibitNetworkAccess()) {
throw new FHIRException("Network Access is prohibited in this context"); throw new FHIRException("Network Access is prohibited in this context");
} }
/*FIXME delete this after refactor
HttpDelete deleteRequest = new HttpDelete(resourceUri);
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withMethod(HTTPRequest.HttpMethod.DELETE) .withMethod(HTTPRequest.HttpMethod.DELETE)
.withUrl(resourceUri.toString()); .withUrl(resourceUri.toString());
@ -248,8 +226,12 @@ public class ClientUtils {
return issueResourceRequest(resourceFormat, request, Collections.emptyList(), timeoutLoading); return issueResourceRequest(resourceFormat, request, Collections.emptyList(), timeoutLoading);
} }
/** /**
* @param resourceFormat * Issue a resource request.
* @return * @param resourceFormat the expected FHIR format
* @param request the request to be sent
* @param headers any additional headers to add
*
* @return A ResourceRequest object containing the requested resource
*/ */
protected <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HTTPRequest request, protected <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HTTPRequest request,
@Nonnull Iterable<HTTPHeader> headers, int timeoutLoading) { @Nonnull Iterable<HTTPHeader> headers, int timeoutLoading) {
@ -259,7 +241,7 @@ public class ClientUtils {
Iterable<HTTPHeader> configuredHeaders = getFhirHeaders(request, resourceFormat, headers); Iterable<HTTPHeader> configuredHeaders = getFhirHeaders(request, resourceFormat, headers);
try { try {
HTTPResult response = getManagedWebAccessBuilder().httpCall(request.withHeaders(configuredHeaders)); HTTPResult response = getManagedWebAccessor().httpCall(request.withHeaders(configuredHeaders));
T resource = unmarshalReference(response, resourceFormat); T resource = unmarshalReference(response, resourceFormat);
return new ResourceRequest<T>(resource, response.getCode(), getLocationHeader(response.getHeaders())); return new ResourceRequest<T>(resource, response.getCode(), getLocationHeader(response.getHeaders()));
} catch (IOException ioe) { } catch (IOException ioe) {
@ -269,18 +251,21 @@ public class ClientUtils {
} }
/** /**
* Method adds required request headers. TODO handle JSON request as well. * Get required headers for FHIR requests.
* *
* @param format * @param httpRequest the request
* @param format the expected format
*/ */
protected Iterable<HTTPHeader> getFhirHeaders(HTTPRequest httpRequest, String format) { protected Iterable<HTTPHeader> getFhirHeaders(HTTPRequest httpRequest, String format) {
return getFhirHeaders(httpRequest, format, null); return getFhirHeaders(httpRequest, format, null);
} }
/** /**
* Method adds required request headers. TODO handle JSON request as well. * Get required headers for FHIR requests.
* *
* @param format * @param httpRequest the request
* @param format the expected format
* @param headers any additional headers to add
*/ */
protected Iterable<HTTPHeader> getFhirHeaders(HTTPRequest httpRequest, String format, Iterable<HTTPHeader> headers) { protected Iterable<HTTPHeader> getFhirHeaders(HTTPRequest httpRequest, String format, Iterable<HTTPHeader> headers) {
List<HTTPHeader> configuredHeaders = new ArrayList<>(); List<HTTPHeader> configuredHeaders = new ArrayList<>();
@ -303,7 +288,6 @@ public class ClientUtils {
return configuredHeaders; return configuredHeaders;
} }
//FIXME this shouldn't set Content-Type header for GET requests
protected static List<HTTPHeader> getResourceFormatHeaders(HTTPRequest httpRequest, String format) { protected static List<HTTPHeader> getResourceFormatHeaders(HTTPRequest httpRequest, String format) {
List<HTTPHeader> headers = new ArrayList<>(); List<HTTPHeader> headers = new ArrayList<>();
headers.add(new HTTPHeader("Accept", format)); headers.add(new HTTPHeader("Accept", format));
@ -328,7 +312,7 @@ public class ClientUtils {
HTTPResult response = null; HTTPResult response = null;
try { try {
response = getManagedWebAccessBuilder().httpCall(request); response = getManagedWebAccessor().httpCall(request);
return response; return response;
} catch (IOException ioe) { } catch (IOException ioe) {
if (ClientUtils.debugging) { if (ClientUtils.debugging) {
@ -341,8 +325,8 @@ public class ClientUtils {
/** /**
* Unmarshals a resource from the response stream. * Unmarshals a resource from the response stream.
* *
* @param response * @param response The response from the server
* @return * @return The unmarshalled resource
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected <T extends Resource> T unmarshalReference(HTTPResult response, String format) { protected <T extends Resource> T unmarshalReference(HTTPResult response, String format) {
@ -369,8 +353,8 @@ public class ClientUtils {
/** /**
* Unmarshals Bundle from response stream. * Unmarshals Bundle from response stream.
* *
* @param response * @param response The response from the server
* @return * @return The unmarshalled Bundle
*/ */
protected Bundle unmarshalFeed(HTTPResult response, String format) { protected Bundle unmarshalFeed(HTTPResult response, String format) {
Bundle feed = null; Bundle feed = null;
@ -531,9 +515,6 @@ public class ClientUtils {
public Bundle issuePostFeedRequest(URI resourceUri, Map<String, String> parameters, String resourceName, public Bundle issuePostFeedRequest(URI resourceUri, Map<String, String> parameters, String resourceName,
Resource resource, String resourceFormat) throws IOException { Resource resource, String resourceFormat) throws IOException {
/*FIXME delete this after refactor
HttpPost httpRequest = new HttpPost(resourceUri);
*/
HTTPRequest httpRequest = new HTTPRequest() HTTPRequest httpRequest = new HTTPRequest()
.withMethod(HTTPRequest.HttpMethod.POST) .withMethod(HTTPRequest.HttpMethod.POST)
@ -542,8 +523,9 @@ public class ClientUtils {
List<HTTPHeader> headers = new ArrayList<>(); List<HTTPHeader> headers = new ArrayList<>();
headers.add(new HTTPHeader("Content-Type", "multipart/form-data; boundary=" + boundary)); headers.add(new HTTPHeader("Content-Type", "multipart/form-data; boundary=" + boundary));
headers.add(new HTTPHeader("Accept", resourceFormat)); headers.add(new HTTPHeader("Accept", resourceFormat));
this.getFhirHeaders(httpRequest, null); this.getFhirHeaders(httpRequest, null).forEach(headers::add);
HTTPResult response = sendPayload(httpRequest.withBody(encodeFormSubmission(parameters, resourceName, resource, boundary)));
HTTPResult response = sendPayload(httpRequest.withBody(encodeFormSubmission(parameters, resourceName, resource, boundary)).withHeaders(headers));
return unmarshalFeed(response, resourceFormat); return unmarshalFeed(response, resourceFormat);
} }
@ -574,16 +556,16 @@ public class ClientUtils {
} }
/** /**
* Method posts request payload * Send an HTTP Post/Put Payload
* *
* @param request * @param request The request to be sent
* @return * @return The response from the server
*/ */
protected HTTPResult sendPayload(HTTPRequest request) { protected HTTPResult sendPayload(HTTPRequest request) {
HTTPResult response = null; HTTPResult response = null;
try { try {
response = getManagedWebAccessBuilder().httpCall(request); response = getManagedWebAccessor().httpCall(request);
} catch (IOException ioe) { } catch (IOException ioe) {
throw new EFhirClientException("Error sending HTTP Post/Put Payload: " + ioe.getMessage(), ioe); throw new EFhirClientException("Error sending HTTP Post/Put Payload: " + ioe.getMessage(), ioe);
} }

View File

@ -402,10 +402,13 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
/** /**
* Helper method to prevent nesting of previously thrown EFhirClientExceptions * Helper method to prevent nesting of previously thrown EFhirClientExceptions. If the e param is an instance of
* * EFhirClientException, it will be rethrown. Otherwise, a new EFhirClientException will be thrown with e as the
* @param e * cause.
* @throws EFhirClientException *
* @param message The EFhirClientException message.
* @param e The exception.
* @throws EFhirClientException representing the exception.
*/ */
protected void handleException(String message, Exception e) throws EFhirClientException { protected void handleException(String message, Exception e) throws EFhirClientException {
if (e instanceof EFhirClientException) { if (e instanceof EFhirClientException) {
@ -419,8 +422,8 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
* Helper method to determine whether desired resource representation is Json or * Helper method to determine whether desired resource representation is Json or
* XML. * XML.
* *
* @param format * @param format the format to check
* @return * @return true if JSON, false if XML
*/ */
protected boolean isJson(String format) { protected boolean isJson(String format) {
boolean isJson = false; boolean isJson = false;

View File

@ -375,10 +375,14 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
} }
/** /**
* Helper method to prevent nesting of previously thrown EFhirClientExceptions * Helper method to prevent nesting of previously thrown EFhirClientExceptions. If the e param is an instance of
* EFhirClientException, it will be rethrown. Otherwise, a new EFhirClientException will be thrown with e as the
* cause.
* *
* @param e
* @throws EFhirClientException * @param message The EFhirClientException message.
* @param e The exception
* @throws EFhirClientException EFhirClientException representing the exception.
*/ */
protected void handleException(String message, Exception e) throws EFhirClientException { protected void handleException(String message, Exception e) throws EFhirClientException {
if (e instanceof EFhirClientException) { if (e instanceof EFhirClientException) {
@ -389,11 +393,11 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
} }
/** /**
* Helper method to determine whether desired resource representation * Helper method to determine whether desired resource representation is Json or
* is Json or XML. * XML.
* *
* @param format * @param format the format
* @return * @return true if the format is JSON, false otherwise
*/ */
protected boolean isJson(String format) { protected boolean isJson(String format) {
boolean isJson = false; boolean isJson = false;

View File

@ -60,11 +60,7 @@ public class Client {
String resourceFormat, String resourceFormat,
String message, String message,
long timeout) throws IOException { long timeout) throws IOException {
/*FIXME delete after refactor
Request.Builder request = new Request.Builder()
.method("OPTIONS", null)
.url(optionsUri.toURL());
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(optionsUri.toURL()) .withUrl(optionsUri.toURL())
.withMethod(HTTPRequest.HttpMethod.OPTIONS); .withMethod(HTTPRequest.HttpMethod.OPTIONS);
@ -77,10 +73,6 @@ public class Client {
Iterable<HTTPHeader> headers, Iterable<HTTPHeader> headers,
String message, String message,
long timeout) throws IOException { long timeout) throws IOException {
/*FIXME delete after refactor
Request.Builder request = new Request.Builder()
.url(resourceUri.toURL());
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.GET); .withMethod(HTTPRequest.HttpMethod.GET);
@ -105,12 +97,7 @@ public class Client {
String message, String message,
long timeout) throws IOException { long timeout) throws IOException {
if (payload == null) throw new EFhirClientException("PUT requests require a non-null payload"); if (payload == null) throw new EFhirClientException("PUT requests require a non-null payload");
/*FIXME delete after refactor
RequestBody body = RequestBody.create(payload);
Request.Builder request = new Request.Builder()
.url(resourceUri.toURL())
.put(body);
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.PUT) .withMethod(HTTPRequest.HttpMethod.PUT)
@ -133,12 +120,7 @@ public class Client {
String message, String message,
long timeout) throws IOException { long timeout) throws IOException {
if (payload == null) throw new EFhirClientException("POST requests require a non-null payload"); if (payload == null) throw new EFhirClientException("POST requests require a non-null payload");
/*FIXME delete after refactor
RequestBody body = RequestBody.create(MediaType.parse(resourceFormat + ";charset=" + DEFAULT_CHARSET), payload);
Request.Builder request = new Request.Builder()
.url(resourceUri.toURL())
.post(body);
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.POST) .withMethod(HTTPRequest.HttpMethod.POST)
@ -147,11 +129,6 @@ public class Client {
} }
public boolean issueDeleteRequest(URI resourceUri) throws IOException { public boolean issueDeleteRequest(URI resourceUri) throws IOException {
/*FIXME delete after refactor
Request.Builder request = new Request.Builder()
.url(resourceUri.toURL())
.delete();
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.DELETE); .withMethod(HTTPRequest.HttpMethod.DELETE);
@ -159,10 +136,6 @@ public class Client {
} }
public Bundle issueGetFeedRequest(URI resourceUri, String resourceFormat) throws IOException { public Bundle issueGetFeedRequest(URI resourceUri, String resourceFormat) throws IOException {
/*FIXME delete after refactor
Request.Builder request = new Request.Builder()
.url(resourceUri.toURL());
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.GET); .withMethod(HTTPRequest.HttpMethod.GET);
@ -176,12 +149,7 @@ public class Client {
String resourceFormat) throws IOException { String resourceFormat) throws IOException {
String boundary = "----WebKitFormBoundarykbMUo6H8QaUnYtRy"; String boundary = "----WebKitFormBoundarykbMUo6H8QaUnYtRy";
byte[] payload = ByteUtils.encodeFormSubmission(parameters, resourceName, resource, boundary); byte[] payload = ByteUtils.encodeFormSubmission(parameters, resourceName, resource, boundary);
/*FIXME delete after refactor
RequestBody body = RequestBody.create(MediaType.parse(resourceFormat + ";charset=" + DEFAULT_CHARSET), payload);
Request.Builder request = new Request.Builder()
.url(resourceUri.toURL())
.post(body);
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.POST) .withMethod(HTTPRequest.HttpMethod.POST)
@ -196,12 +164,7 @@ public class Client {
String message, String message,
int timeout) throws IOException { int timeout) throws IOException {
if (payload == null) throw new EFhirClientException("POST requests require a non-null payload"); if (payload == null) throw new EFhirClientException("POST requests require a non-null payload");
/*FIXME delete after refactor
RequestBody body = RequestBody.create(MediaType.parse(resourceFormat + ";charset=" + DEFAULT_CHARSET), payload);
Request.Builder request = new Request.Builder()
.url(resourceUri.toURL())
.post(body);
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.POST) .withMethod(HTTPRequest.HttpMethod.POST)

View File

@ -56,9 +56,9 @@ public class FhirRequestBuilder {
/** /**
* Adds necessary default headers, formatting headers, and any passed in {@link HTTPHeader}s to the passed in * Adds necessary default headers, formatting headers, and any passed in {@link HTTPHeader}s to the passed in
* {@link okhttp3.Request.Builder} * {@link HTTPRequest}
* *
* @param request {@link okhttp3.Request.Builder} to add headers to. * @param request {@link HTTPRequest} to add headers to.
* @param format Expected {@link Resource} format. * @param format Expected {@link Resource} format.
* @param headers Any additional {@link HTTPHeader}s to add to the request. * @param headers Any additional {@link HTTPHeader}s to add to the request.
*/ */
@ -114,8 +114,8 @@ public class FhirRequestBuilder {
return HTTPHeaderUtil.getSingleHeader(headers, CONTENT_LOCATION_HEADER); return HTTPHeaderUtil.getSingleHeader(headers, CONTENT_LOCATION_HEADER);
} }
protected ManagedFhirWebAccessor getManagedWebAccessBuilder() { protected ManagedFhirWebAccessor getManagedWebAccessor() {
return ManagedWebAccess.fhirBuilder().withRetries(retryCount).withTimeout(timeout, timeoutUnit).withLogger(logger); return ManagedWebAccess.fhirAccessor().withRetries(retryCount).withTimeout(timeout, timeoutUnit).withLogger(logger);
} }
public FhirRequestBuilder withResourceFormat(String resourceFormat) { public FhirRequestBuilder withResourceFormat(String resourceFormat) {
@ -151,14 +151,14 @@ public class FhirRequestBuilder {
public <T extends Resource> ResourceRequest<T> execute() throws IOException { public <T extends Resource> ResourceRequest<T> execute() throws IOException {
HTTPRequest requestWithHeaders = formatHeaders(httpRequest, resourceFormat, headers); HTTPRequest requestWithHeaders = formatHeaders(httpRequest, resourceFormat, headers);
HTTPResult response = getManagedWebAccessBuilder().httpCall(requestWithHeaders); HTTPResult response = getManagedWebAccessor().httpCall(requestWithHeaders);
T resource = unmarshalReference(response, resourceFormat); T resource = unmarshalReference(response, resourceFormat);
return new ResourceRequest<T>(resource, response.getCode(), getLocationHeader(response.getHeaders())); return new ResourceRequest<T>(resource, response.getCode(), getLocationHeader(response.getHeaders()));
} }
public Bundle executeAsBatch() throws IOException { public Bundle executeAsBatch() throws IOException {
HTTPRequest requestWithHeaders = formatHeaders(httpRequest, resourceFormat, null); HTTPRequest requestWithHeaders = formatHeaders(httpRequest, resourceFormat, null);
HTTPResult response = getManagedWebAccessBuilder().httpCall(requestWithHeaders); HTTPResult response = getManagedWebAccessor().httpCall(requestWithHeaders);
return unmarshalFeed(response, resourceFormat); return unmarshalFeed(response, resourceFormat);
} }
@ -228,7 +228,7 @@ public class FhirRequestBuilder {
/** /**
* Returns the appropriate parser based on the format type passed in. Defaults to XML parser if a blank format is * Returns the appropriate parser based on the format type passed in. Defaults to XML parser if a blank format is
* provided...because reasons. * provided...because reasons.
* <p> * <p/>
* Currently supports only "json" and "xml" formats. * Currently supports only "json" and "xml" formats.
* *
* @param format One of "json" or "xml". * @param format One of "json" or "xml".

View File

@ -16,7 +16,6 @@ public class FhirRequestBuilderTests {
@Test @Test
@DisplayName("Test resource format headers are added correctly (GET).") @DisplayName("Test resource format headers are added correctly (GET).")
void addResourceFormatHeadersGET() { void addResourceFormatHeadersGET() {
//FIXME tested here. Should get list of HTTPHeader.
String testFormat = "yaml"; String testFormat = "yaml";
HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com").withMethod(HTTPRequest.HttpMethod.GET); HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com").withMethod(HTTPRequest.HttpMethod.GET);
@ -33,7 +32,6 @@ public class FhirRequestBuilderTests {
@Test @Test
@DisplayName("Test resource format headers are added correctly (POST).") @DisplayName("Test resource format headers are added correctly (POST).")
void addResourceFormatHeadersPOST() { void addResourceFormatHeadersPOST() {
//FIXME tested here. Should get list of HTTPHeader.
String testFormat = "yaml"; String testFormat = "yaml";
HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com").withMethod(HTTPRequest.HttpMethod.POST); HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com").withMethod(HTTPRequest.HttpMethod.POST);

View File

@ -356,10 +356,14 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
} }
/** /**
* Helper method to prevent nesting of previously thrown EFhirClientExceptions * Helper method to prevent nesting of previously thrown EFhirClientExceptions. If the e param is an instance of
* EFhirClientException, it will be rethrown. Otherwise, a new EFhirClientException will be thrown with e as the
* cause.
* *
* @param e * @param code The EFhirClientException code.
* @throws EFhirClientException * @param message The EFhirClientException message.
* @param e The exception.
* @throws EFhirClientException representing the exception.
*/ */
protected void handleException(int code, String message, Exception e) throws EFhirClientException { protected void handleException(int code, String message, Exception e) throws EFhirClientException {
if (e instanceof EFhirClientException) { if (e instanceof EFhirClientException) {
@ -370,11 +374,11 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
} }
/** /**
* Helper method to determine whether desired resource representation is Json or * Helper method to determine whether desired resource representation
* XML. * is Json or XML.
* *
* @param format * @param format The format
* @return * @return true if the format is JSON, false otherwise
*/ */
protected boolean isJson(String format) { protected boolean isJson(String format) {
boolean isJson = false; boolean isJson = false;
@ -539,7 +543,6 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
headers.forEach(this.headers::add); headers.forEach(this.headers::add);
} }
//FIXME should be in ManagedWebAccess?
private Iterable<HTTPHeader> generateHeaders(boolean hasBody) { private Iterable<HTTPHeader> generateHeaders(boolean hasBody) {
// Add any other headers // Add any other headers
List<HTTPHeader> headers = new ArrayList<>(this.headers); List<HTTPHeader> headers = new ArrayList<>(this.headers);

View File

@ -31,9 +31,7 @@ public class Client {
public <T extends Resource> ResourceRequest<T> issueOptionsRequest(URI optionsUri, String resourceFormat, public <T extends Resource> ResourceRequest<T> issueOptionsRequest(URI optionsUri, String resourceFormat,
String message, long timeout) throws IOException { String message, long timeout) throws IOException {
/*FIXME delete once refactor is done
Request.Builder request = new Request.Builder().method("OPTIONS", null).url(optionsUri.toURL());
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(optionsUri.toURL()) .withUrl(optionsUri.toURL())
.withMethod(HTTPRequest.HttpMethod.OPTIONS); .withMethod(HTTPRequest.HttpMethod.OPTIONS);
@ -42,10 +40,6 @@ public class Client {
public <T extends Resource> ResourceRequest<T> issueGetResourceRequest(URI resourceUri, String resourceFormat, public <T extends Resource> ResourceRequest<T> issueGetResourceRequest(URI resourceUri, String resourceFormat,
Iterable<HTTPHeader> headers, String message, long timeout) throws IOException { Iterable<HTTPHeader> headers, String message, long timeout) throws IOException {
/*FIXME delete once refactor is done
Request.Builder request = new Request.Builder().url(resourceUri.toURL());
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.GET); .withMethod(HTTPRequest.HttpMethod.GET);
@ -61,10 +55,7 @@ public class Client {
Iterable<HTTPHeader> headers, String message, long timeout) throws IOException { Iterable<HTTPHeader> headers, String message, long timeout) throws IOException {
if (payload == null) if (payload == null)
throw new EFhirClientException("PUT requests require a non-null payload"); throw new EFhirClientException("PUT requests require a non-null payload");
/*FIXME delete once refactor is done
RequestBody body = RequestBody.create(payload);
Request.Builder request = new Request.Builder().url(resourceUri.toURL()).put(body);
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.PUT) .withMethod(HTTPRequest.HttpMethod.PUT)
@ -83,10 +74,7 @@ public class Client {
String resourceFormat, Iterable<HTTPHeader> headers, String message, long timeout) throws IOException { String resourceFormat, Iterable<HTTPHeader> headers, String message, long timeout) throws IOException {
if (payload == null) if (payload == null)
throw new EFhirClientException("POST requests require a non-null payload"); throw new EFhirClientException("POST requests require a non-null payload");
/*FIXME delete once refactor is done
RequestBody body = RequestBody.create(MediaType.parse(resourceFormat + ";charset=" + DEFAULT_CHARSET), payload);
Request.Builder request = new Request.Builder().url(resourceUri.toURL()).post(body);
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.POST) .withMethod(HTTPRequest.HttpMethod.POST)
@ -97,9 +85,6 @@ public class Client {
} }
public boolean issueDeleteRequest(URI resourceUri, int timeout) throws IOException { public boolean issueDeleteRequest(URI resourceUri, int timeout) throws IOException {
/*FIXME delete once refactor is done
Request.Builder request = new Request.Builder().url(resourceUri.toURL()).delete();
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.DELETE); .withMethod(HTTPRequest.HttpMethod.DELETE);
@ -108,9 +93,6 @@ public class Client {
} }
public Bundle issueGetFeedRequest(URI resourceUri, String resourceFormat, int timeout) throws IOException { public Bundle issueGetFeedRequest(URI resourceUri, String resourceFormat, int timeout) throws IOException {
/*FIXME delete once refactor is done
Request.Builder request = new Request.Builder().url(resourceUri.toURL());
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.GET); .withMethod(HTTPRequest.HttpMethod.GET);
@ -123,11 +105,6 @@ public class Client {
String boundary = "----WebKitFormBoundarykbMUo6H8QaUnYtRy"; String boundary = "----WebKitFormBoundarykbMUo6H8QaUnYtRy";
byte[] payload = ByteUtils.encodeFormSubmission(parameters, resourceName, resource, boundary); byte[] payload = ByteUtils.encodeFormSubmission(parameters, resourceName, resource, boundary);
/*FIXME delete once refactor is done
RequestBody body = RequestBody.create(MediaType.parse(resourceFormat + ";charset=" + DEFAULT_CHARSET), payload);
Request.Builder request = new Request.Builder().url(resourceUri.toURL()).post(body);
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.POST) .withMethod(HTTPRequest.HttpMethod.POST)
@ -141,10 +118,7 @@ public class Client {
throws IOException { throws IOException {
if (payload == null) if (payload == null)
throw new EFhirClientException("POST requests require a non-null payload"); throw new EFhirClientException("POST requests require a non-null payload");
/*FIXME delete once refactor is done
RequestBody body = RequestBody.create(MediaType.parse(resourceFormat + ";charset=" + DEFAULT_CHARSET), payload);
Request.Builder request = new Request.Builder().url(resourceUri.toURL()).post(body);
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.POST) .withMethod(HTTPRequest.HttpMethod.POST)

View File

@ -28,9 +28,7 @@ public class FhirRequestBuilder {
protected static final String LOCATION_HEADER = "location"; protected static final String LOCATION_HEADER = "location";
protected static final String CONTENT_LOCATION_HEADER = "content-location"; protected static final String CONTENT_LOCATION_HEADER = "content-location";
protected static final String DEFAULT_CHARSET = "UTF-8"; protected static final String DEFAULT_CHARSET = "UTF-8";
/**
* The singleton instance of the HttpClient, used for all requests.
*/
private final HTTPRequest httpRequest; private final HTTPRequest httpRequest;
private String resourceFormat = null; private String resourceFormat = null;
private Iterable<HTTPHeader> headers = null; private Iterable<HTTPHeader> headers = null;
@ -62,9 +60,9 @@ public class FhirRequestBuilder {
/** /**
* Adds necessary default headers, formatting headers, and any passed in * Adds necessary default headers, formatting headers, and any passed in
* {@link HTTPHeader}s to the passed in {@link okhttp3.Request.Builder} * {@link HTTPHeader}s to the passed in {@link HTTPRequest}
* *
* @param request {@link okhttp3.Request.Builder} to add headers to. * @param request {@link HTTPRequest} to add headers to.
* @param format Expected {@link Resource} format. * @param format Expected {@link Resource} format.
* @param headers Any additional {@link HTTPHeader}s to add to the request. * @param headers Any additional {@link HTTPHeader}s to add to the request.
*/ */
@ -122,8 +120,8 @@ public class FhirRequestBuilder {
return HTTPHeaderUtil.getSingleHeader(headers, CONTENT_LOCATION_HEADER); return HTTPHeaderUtil.getSingleHeader(headers, CONTENT_LOCATION_HEADER);
} }
protected ManagedFhirWebAccessor getManagedWebAccessBuilder() { protected ManagedFhirWebAccessor getManagedWebAccessor() {
return ManagedWebAccess.fhirBuilder().withRetries(retryCount).withTimeout(timeout, timeoutUnit).withLogger(logger); return ManagedWebAccess.fhirAccessor().withRetries(retryCount).withTimeout(timeout, timeoutUnit).withLogger(logger);
} }
public FhirRequestBuilder withResourceFormat(String resourceFormat) { public FhirRequestBuilder withResourceFormat(String resourceFormat) {
@ -160,7 +158,7 @@ public class FhirRequestBuilder {
public <T extends Resource> ResourceRequest<T> execute() throws IOException { public <T extends Resource> ResourceRequest<T> execute() throws IOException {
HTTPRequest requestWithHeaders = formatHeaders(httpRequest, resourceFormat, headers); HTTPRequest requestWithHeaders = formatHeaders(httpRequest, resourceFormat, headers);
HTTPResult response = getManagedWebAccessBuilder().httpCall(requestWithHeaders); HTTPResult response = getManagedWebAccessor().httpCall(requestWithHeaders);
T resource = unmarshalReference(response, resourceFormat, null); T resource = unmarshalReference(response, resourceFormat, null);
return new ResourceRequest<T>(resource, response.getCode(), getLocationHeader(response.getHeaders())); return new ResourceRequest<T>(resource, response.getCode(), getLocationHeader(response.getHeaders()));
@ -168,7 +166,7 @@ public class FhirRequestBuilder {
public Bundle executeAsBatch() throws IOException { public Bundle executeAsBatch() throws IOException {
HTTPRequest requestWithHeaders = formatHeaders(httpRequest, resourceFormat, null); HTTPRequest requestWithHeaders = formatHeaders(httpRequest, resourceFormat, null);
HTTPResult response = getManagedWebAccessBuilder().httpCall(requestWithHeaders); HTTPResult response = getManagedWebAccessor().httpCall(requestWithHeaders);
return unmarshalFeed(response, resourceFormat); return unmarshalFeed(response, resourceFormat);
} }
@ -269,7 +267,7 @@ public class FhirRequestBuilder {
/** /**
* Returns the appropriate parser based on the format type passed in. Defaults * Returns the appropriate parser based on the format type passed in. Defaults
* to XML parser if a blank format is provided...because reasons. * to XML parser if a blank format is provided...because reasons.
* <p> * <p/>
* Currently supports only "json" and "xml" formats. * Currently supports only "json" and "xml" formats.
* *
* @param format One of "json" or "xml". * @param format One of "json" or "xml".

View File

@ -33,7 +33,6 @@ public class FhirRequestBuilderTest {
@Test @Test
@DisplayName("Test resource format headers are added correctly (POST).") @DisplayName("Test resource format headers are added correctly (POST).")
void addResourceFormatHeadersPOST() { void addResourceFormatHeadersPOST() {
//FIXME tested here. Should get list of HTTPHeader.
String testFormat = "yaml"; String testFormat = "yaml";
HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com").withMethod(HTTPRequest.HttpMethod.POST); HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com").withMethod(HTTPRequest.HttpMethod.POST);

View File

@ -1,22 +1,14 @@
package org.hl7.fhir.r4b.terminologies; package org.hl7.fhir.r4b.terminologies;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Base64;
import java.util.Date; import java.util.Date;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
@ -156,7 +148,7 @@ public class TerminologyCacheManager {
String url = "https://tx.fhir.org/post/tx-cache/" + ghOrg + "/" + ghRepo + "/" + ghBranch + ".zip"; String url = "https://tx.fhir.org/post/tx-cache/" + ghOrg + "/" + ghRepo + "/" + ghBranch + ".zip";
System.out.println("Sending tx-cache to " + url + " (" + Utilities.describeSize(bs.toByteArray().length) + ")"); System.out.println("Sending tx-cache to " + url + " (" + Utilities.describeSize(bs.toByteArray().length) + ")");
HTTPResult res = ManagedWebAccess.builder() HTTPResult res = ManagedWebAccess.accessor()
.withBasicAuth(token.substring(0, token.indexOf(':')), token.substring(token.indexOf(':') + 1)) .withBasicAuth(token.substring(0, token.indexOf(':')), token.substring(token.indexOf(':') + 1))
.put(url, bs.toByteArray(), null, "application/zip"); .put(url, bs.toByteArray(), null, "application/zip");
if (res.getCode() >= 300) { if (res.getCode() >= 300) {

View File

@ -362,10 +362,14 @@ public class FHIRToolingClient extends FHIRBaseToolingClient{
} }
/** /**
* Helper method to prevent nesting of previously thrown EFhirClientExceptions * Helper method to prevent nesting of previously thrown EFhirClientExceptions. If the e param is an instance of
* EFhirClientException, it will be rethrown. Otherwise, a new EFhirClientException will be thrown with e as the
* cause.
* *
* @param e
* @throws EFhirClientException * @param message The EFhirClientException message.
* @param e The exception
* @throws EFhirClientException EFhirClientException representing the exception.
*/ */
protected void handleException(String message, Exception e) throws EFhirClientException { protected void handleException(String message, Exception e) throws EFhirClientException {
if (e instanceof EFhirClientException) { if (e instanceof EFhirClientException) {
@ -379,8 +383,8 @@ public class FHIRToolingClient extends FHIRBaseToolingClient{
* Helper method to determine whether desired resource representation is Json or * Helper method to determine whether desired resource representation is Json or
* XML. * XML.
* *
* @param format * @param format the format
* @return * @return true if the format is JSON, false otherwise
*/ */
protected boolean isJson(String format) { protected boolean isJson(String format) {
boolean isJson = false; boolean isJson = false;

View File

@ -35,9 +35,6 @@ public class Client {
public <T extends Resource> ResourceRequest<T> issueOptionsRequest(URI optionsUri, String resourceFormat, public <T extends Resource> ResourceRequest<T> issueOptionsRequest(URI optionsUri, String resourceFormat,
String message, long timeout) throws IOException { String message, long timeout) throws IOException {
/*FIXME delete once refactor is done
Request.Builder request = new Request.Builder().method("OPTIONS", null).url(optionsUri.toURL());
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(optionsUri.toURL()) .withUrl(optionsUri.toURL())
.withMethod(HTTPRequest.HttpMethod.OPTIONS); .withMethod(HTTPRequest.HttpMethod.OPTIONS);
@ -46,9 +43,6 @@ public class Client {
public <T extends Resource> ResourceRequest<T> issueGetResourceRequest(URI resourceUri, String resourceFormat, public <T extends Resource> ResourceRequest<T> issueGetResourceRequest(URI resourceUri, String resourceFormat,
Iterable<HTTPHeader> headers, String message, long timeout) throws IOException { Iterable<HTTPHeader> headers, String message, long timeout) throws IOException {
/*FIXME delete once refactor is done
Request.Builder request = new Request.Builder().url(resourceUri.toURL());
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.GET); .withMethod(HTTPRequest.HttpMethod.GET);
@ -64,10 +58,7 @@ public class Client {
Iterable<HTTPHeader> headers, String message, long timeout) throws IOException { Iterable<HTTPHeader> headers, String message, long timeout) throws IOException {
if (payload == null) if (payload == null)
throw new EFhirClientException("PUT requests require a non-null payload"); throw new EFhirClientException("PUT requests require a non-null payload");
/*FIXME delete once refactor is done
RequestBody body = RequestBody.create(payload);
Request.Builder request = new Request.Builder().url(resourceUri.toURL()).put(body);
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.PUT) .withMethod(HTTPRequest.HttpMethod.PUT)
@ -87,10 +78,6 @@ public class Client {
if (payload == null) if (payload == null)
throw new EFhirClientException("POST requests require a non-null payload"); throw new EFhirClientException("POST requests require a non-null payload");
/*FIXME delete once refactor is done
RequestBody body = RequestBody.create(MediaType.parse(resourceFormat + ";charset=" + DEFAULT_CHARSET), payload);
Request.Builder request = new Request.Builder().url(resourceUri.toURL()).post(body);
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.POST) .withMethod(HTTPRequest.HttpMethod.POST)
@ -101,9 +88,6 @@ public class Client {
} }
public boolean issueDeleteRequest(URI resourceUri) throws IOException { public boolean issueDeleteRequest(URI resourceUri) throws IOException {
/*FIXME delete once refactor is done
Request.Builder request = new Request.Builder().url(resourceUri.toURL()).delete();
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.DELETE); .withMethod(HTTPRequest.HttpMethod.DELETE);
@ -112,9 +96,6 @@ public class Client {
} }
public Bundle issueGetFeedRequest(URI resourceUri, String resourceFormat) throws IOException { public Bundle issueGetFeedRequest(URI resourceUri, String resourceFormat) throws IOException {
/*FIXME delete once refactor is done
Request.Builder request = new Request.Builder().url(resourceUri.toURL());
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.GET); .withMethod(HTTPRequest.HttpMethod.GET);
@ -125,10 +106,7 @@ public class Client {
Resource resource, String resourceFormat) throws IOException { Resource resource, String resourceFormat) throws IOException {
String boundary = "----WebKitFormBoundarykbMUo6H8QaUnYtRy"; String boundary = "----WebKitFormBoundarykbMUo6H8QaUnYtRy";
byte[] payload = ByteUtils.encodeFormSubmission(parameters, resourceName, resource, boundary); byte[] payload = ByteUtils.encodeFormSubmission(parameters, resourceName, resource, boundary);
/*FIXME delete once refactor is done
RequestBody body = RequestBody.create(MediaType.parse(resourceFormat + ";charset=" + DEFAULT_CHARSET), payload);
Request.Builder request = new Request.Builder().url(resourceUri.toURL()).post(body);
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.POST) .withMethod(HTTPRequest.HttpMethod.POST)
@ -141,10 +119,7 @@ public class Client {
String message, int timeout) throws IOException { String message, int timeout) throws IOException {
if (payload == null) if (payload == null)
throw new EFhirClientException("POST requests require a non-null payload"); throw new EFhirClientException("POST requests require a non-null payload");
/*FIXME delete once refactor is done
RequestBody body = RequestBody.create(MediaType.parse(resourceFormat + ";charset=" + DEFAULT_CHARSET), payload);
Request.Builder request = new Request.Builder().url(resourceUri.toURL()).post(body);
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.POST) .withMethod(HTTPRequest.HttpMethod.POST)

View File

@ -51,7 +51,6 @@ public class FhirRequestBuilder {
private ToolingClientLogger logger = null; private ToolingClientLogger logger = null;
private String source; private String source;
//TODO this should be the only constructor. There should be no okHttp exposure.
public FhirRequestBuilder(HTTPRequest httpRequest, String source) { public FhirRequestBuilder(HTTPRequest httpRequest, String source) {
this.source = source; this.source = source;
this.httpRequest = httpRequest; this.httpRequest = httpRequest;
@ -103,17 +102,13 @@ public class FhirRequestBuilder {
} }
/** /**
* Extracts the 'location' header from the passes in {@link Headers}. If no * Extracts the 'location' header from the passed in {@link HTTPHeader}s. If no
* value for 'location' exists, the value for 'content-location' is returned. If * value for 'location' exists, the value for 'content-location' is returned. If
* neither header exists, we return null. * neither header exists, we return null.
* *
* @param headers {@link Headers} to evaluate * @param headers {@link HTTPHeader}s to evaluate
* @return {@link String} header value, or null if no location headers are set. * @return {@link String} header value, or null if no location headers are set.
*/ */
/**
* Extracts the 'location' header from. If no value for 'location' exists, the
* value for 'content-location' is returned. If neither header exists, we return null.
*/
protected static String getLocationHeader(Iterable<HTTPHeader> headers) { protected static String getLocationHeader(Iterable<HTTPHeader> headers) {
String locationHeader = HTTPHeaderUtil.getSingleHeader(headers, LOCATION_HEADER); String locationHeader = HTTPHeaderUtil.getSingleHeader(headers, LOCATION_HEADER);
@ -123,8 +118,8 @@ public class FhirRequestBuilder {
return HTTPHeaderUtil.getSingleHeader(headers, CONTENT_LOCATION_HEADER); return HTTPHeaderUtil.getSingleHeader(headers, CONTENT_LOCATION_HEADER);
} }
protected ManagedFhirWebAccessor getManagedWebAccessBuilder() { protected ManagedFhirWebAccessor getManagedWebAccessor() {
return ManagedWebAccess.fhirBuilder().withRetries(retryCount).withTimeout(timeout, timeoutUnit).withLogger(logger); return ManagedWebAccess.fhirAccessor().withRetries(retryCount).withTimeout(timeout, timeoutUnit).withLogger(logger);
} }
public FhirRequestBuilder withResourceFormat(String resourceFormat) { public FhirRequestBuilder withResourceFormat(String resourceFormat) {
@ -160,14 +155,14 @@ public class FhirRequestBuilder {
public <T extends Resource> ResourceRequest<T> execute() throws IOException { public <T extends Resource> ResourceRequest<T> execute() throws IOException {
HTTPRequest requestWithHeaders = formatHeaders(httpRequest, resourceFormat, headers); HTTPRequest requestWithHeaders = formatHeaders(httpRequest, resourceFormat, headers);
HTTPResult response = getManagedWebAccessBuilder().httpCall(requestWithHeaders); HTTPResult response = getManagedWebAccessor().httpCall(requestWithHeaders);
T resource = unmarshalReference(response, resourceFormat, null); T resource = unmarshalReference(response, resourceFormat, null);
return new ResourceRequest<T>(resource, response.getCode(), getLocationHeader(response.getHeaders())); return new ResourceRequest<T>(resource, response.getCode(), getLocationHeader(response.getHeaders()));
} }
public Bundle executeAsBatch() throws IOException { public Bundle executeAsBatch() throws IOException {
HTTPRequest requestWithHeaders = formatHeaders(httpRequest, resourceFormat, null); HTTPRequest requestWithHeaders = formatHeaders(httpRequest, resourceFormat, null);
HTTPResult response = getManagedWebAccessBuilder().httpCall(requestWithHeaders);return unmarshalFeed(response, resourceFormat); HTTPResult response = getManagedWebAccessor().httpCall(requestWithHeaders);return unmarshalFeed(response, resourceFormat);
} }
/** /**

View File

@ -33,7 +33,6 @@ class FhirRequestBuilderTest {
@Test @Test
@DisplayName("Test resource format headers are added correctly (POST).") @DisplayName("Test resource format headers are added correctly (POST).")
void addResourceFormatHeadersPOST() { void addResourceFormatHeadersPOST() {
//FIXME tested here. Should get list of HTTPHeader.
String testFormat = "yaml"; String testFormat = "yaml";
HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com").withMethod(HTTPRequest.HttpMethod.POST); HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com").withMethod(HTTPRequest.HttpMethod.POST);

View File

@ -1,22 +1,14 @@
package org.hl7.fhir.r5.terminologies; package org.hl7.fhir.r5.terminologies;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Base64;
import java.util.Date; import java.util.Date;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
@ -156,7 +148,7 @@ public class TerminologyCacheManager {
// post it to // post it to
String url = "https://tx.fhir.org/post/tx-cache/"+ghOrg+"/"+ghRepo+"/"+ghBranch+".zip"; String url = "https://tx.fhir.org/post/tx-cache/"+ghOrg+"/"+ghRepo+"/"+ghBranch+".zip";
System.out.println("Sending tx-cache to "+url+" ("+Utilities.describeSize(bs.toByteArray().length)+")"); System.out.println("Sending tx-cache to "+url+" ("+Utilities.describeSize(bs.toByteArray().length)+")");
HTTPResult res = ManagedWebAccess.builder() HTTPResult res = ManagedWebAccess.accessor()
.withBasicAuth(token.substring(0, token.indexOf(':')), token.substring(token.indexOf(':') + 1)) .withBasicAuth(token.substring(0, token.indexOf(':')), token.substring(token.indexOf(':') + 1))
.put(url, bs.toByteArray(), null, "application/zip"); .put(url, bs.toByteArray(), null, "application/zip");

View File

@ -80,7 +80,6 @@ public class TerminologyClientR5 implements ITerminologyClient {
public TerminologyClientR5(String id, String address, String userAgent) throws URISyntaxException { public TerminologyClientR5(String id, String address, String userAgent) throws URISyntaxException {
this.client = new FHIRToolingClient(address, userAgent); this.client = new FHIRToolingClient(address, userAgent);
//FIXME set up FHIR Tooling Client to use ManagedWebAccess
setClientHeaders(new ClientHeaders()); setClientHeaders(new ClientHeaders());
this.id = id; this.id = id;
} }

View File

@ -403,10 +403,14 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
} }
/** /**
* Helper method to prevent nesting of previously thrown EFhirClientExceptions * Helper method to prevent nesting of previously thrown EFhirClientExceptions. If the e param is an instance of
* EFhirClientException, it will be rethrown. Otherwise, a new EFhirClientException will be thrown with e as the
* cause.
* *
* @param e * @param code The EFhirClientException code.
* @throws EFhirClientException * @param message The EFhirClientException message.
* @param e The exception.
* @throws EFhirClientException representing the exception.
*/ */
protected void handleException(int code, String message, Exception e) throws EFhirClientException { protected void handleException(int code, String message, Exception e) throws EFhirClientException {
if (e instanceof EFhirClientException) { if (e instanceof EFhirClientException) {
@ -420,8 +424,8 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
* Helper method to determine whether desired resource representation * Helper method to determine whether desired resource representation
* is Json or XML. * is Json or XML.
* *
* @param format * @param format The format
* @return * @return true if the format is JSON, false otherwise
*/ */
protected boolean isJson(String format) { protected boolean isJson(String format) {
boolean isJson = false; boolean isJson = false;
@ -595,7 +599,6 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
headers.forEach(this.headers::add); headers.forEach(this.headers::add);
} }
//FIXME should be in ManagedWebAccess?
private Iterable<HTTPHeader> generateHeaders(boolean hasBody) { private Iterable<HTTPHeader> generateHeaders(boolean hasBody) {
// Add any other headers // Add any other headers
List<HTTPHeader> headers = new ArrayList<>(this.headers); List<HTTPHeader> headers = new ArrayList<>(this.headers);

View File

@ -35,11 +35,6 @@ public class Client {
String resourceFormat, String resourceFormat,
String message, String message,
long timeout) throws IOException { long timeout) throws IOException {
/*FIXME delete once refactor is done
Request.Builder request = new Request.Builder()
.method("OPTIONS", null)
.url(optionsUri.toURL());
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(optionsUri.toURL()) .withUrl(optionsUri.toURL())
.withMethod(HTTPRequest.HttpMethod.OPTIONS); .withMethod(HTTPRequest.HttpMethod.OPTIONS);
@ -51,11 +46,6 @@ public class Client {
Iterable<HTTPHeader> headers, Iterable<HTTPHeader> headers,
String message, String message,
long timeout) throws IOException { long timeout) throws IOException {
/*FIXME delete once refactor is done
Request.Builder request = new Request.Builder()
.url(resourceUri.toURL());
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.GET); .withMethod(HTTPRequest.HttpMethod.GET);
@ -78,12 +68,7 @@ public class Client {
String message, String message,
long timeout) throws IOException { long timeout) throws IOException {
if (payload == null) throw new EFhirClientException(0, "PUT requests require a non-null payload"); if (payload == null) throw new EFhirClientException(0, "PUT requests require a non-null payload");
/*FIXME delete once refactor is done
RequestBody body = RequestBody.create(payload);
Request.Builder request = new Request.Builder()
.url(resourceUri.toURL())
.put(body);
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.PUT) .withMethod(HTTPRequest.HttpMethod.PUT)
@ -108,12 +93,7 @@ public class Client {
String message, String message,
long timeout) throws IOException { long timeout) throws IOException {
if (payload == null) throw new EFhirClientException(0, "POST requests require a non-null payload"); if (payload == null) throw new EFhirClientException(0, "POST requests require a non-null payload");
/*FIXME delete once refactor is done
RequestBody body = RequestBody.create(MediaType.parse(getContentTypeWithDefaultCharset(resourceFormat)), payload);
Request.Builder request = new Request.Builder()
.url(resourceUri.toURL())
.post(body);
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.POST) .withMethod(HTTPRequest.HttpMethod.POST)
@ -124,11 +104,6 @@ public class Client {
} }
public boolean issueDeleteRequest(URI resourceUri) throws IOException { public boolean issueDeleteRequest(URI resourceUri) throws IOException {
/*FIXME delete once refactor is done
Request.Builder request = new Request.Builder()
.url(resourceUri.toURL())
.delete();
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.DELETE); .withMethod(HTTPRequest.HttpMethod.DELETE);
@ -136,10 +111,6 @@ public class Client {
} }
public Bundle issueGetFeedRequest(URI resourceUri, String resourceFormat) throws IOException { public Bundle issueGetFeedRequest(URI resourceUri, String resourceFormat) throws IOException {
/*FIXME delete once refactor is done
Request.Builder request = new Request.Builder()
.url(resourceUri.toURL());
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.GET); .withMethod(HTTPRequest.HttpMethod.GET);
@ -153,12 +124,7 @@ public class Client {
String resourceFormat) throws IOException { String resourceFormat) throws IOException {
String boundary = "----WebKitFormBoundarykbMUo6H8QaUnYtRy"; String boundary = "----WebKitFormBoundarykbMUo6H8QaUnYtRy";
byte[] payload = ByteUtils.encodeFormSubmission(parameters, resourceName, resource, boundary); byte[] payload = ByteUtils.encodeFormSubmission(parameters, resourceName, resource, boundary);
/*FIXME delete once refactor is done
RequestBody body = RequestBody.create(MediaType.parse(getContentTypeWithDefaultCharset(resourceFormat)), payload);
Request.Builder request = new Request.Builder()
.url(resourceUri.toURL())
.post(body);
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.POST) .withMethod(HTTPRequest.HttpMethod.POST)
@ -174,12 +140,7 @@ public class Client {
String message, String message,
int timeout) throws IOException { int timeout) throws IOException {
if (payload == null) throw new EFhirClientException(0, "POST requests require a non-null payload"); if (payload == null) throw new EFhirClientException(0, "POST requests require a non-null payload");
/*FIXME delete once refactor is done
RequestBody body = RequestBody.create(MediaType.parse(resourceFormat + ";charset=" + DEFAULT_CHARSET), payload);
Request.Builder request = new Request.Builder()
.url(resourceUri.toURL())
.post(body);
*/
HTTPRequest request = new HTTPRequest() HTTPRequest request = new HTTPRequest()
.withUrl(resourceUri.toURL()) .withUrl(resourceUri.toURL())
.withMethod(HTTPRequest.HttpMethod.POST) .withMethod(HTTPRequest.HttpMethod.POST)

View File

@ -29,11 +29,6 @@ public class FhirRequestBuilder {
protected static final String LOCATION_HEADER = "location"; protected static final String LOCATION_HEADER = "location";
protected static final String CONTENT_LOCATION_HEADER = "content-location"; protected static final String CONTENT_LOCATION_HEADER = "content-location";
/**
* The singleton instance of the HttpClient, used for all requests.
*/
// private static OkHttpClient okHttpClient;
//private final Request.Builder httpRequest;
private final HTTPRequest httpRequest; private final HTTPRequest httpRequest;
private String resourceFormat = null; private String resourceFormat = null;
private Iterable<HTTPHeader> headers = null; private Iterable<HTTPHeader> headers = null;
@ -55,7 +50,6 @@ public class FhirRequestBuilder {
private String source; private String source;
//TODO this should be the only constructor. There should be no okHttp exposure.
public FhirRequestBuilder(HTTPRequest httpRequest, String source) { public FhirRequestBuilder(HTTPRequest httpRequest, String source) {
this.source = source; this.source = source;
this.httpRequest = httpRequest; this.httpRequest = httpRequest;
@ -78,13 +72,11 @@ public class FhirRequestBuilder {
return request.withHeaders(allHeaders); return request.withHeaders(allHeaders);
} }
/**
/** /**
* Adds necessary headers for the given resource format provided. * Adds necessary headers for the given resource format provided.
* *
* @param httpRequest {@link HTTPRequest} to add default headers to. * @param httpRequest {@link HTTPRequest} to add default headers to.
* @param format Expected {@link Resource} format.
*/ */
protected static Iterable<HTTPHeader> getResourceFormatHeaders(HTTPRequest httpRequest, String format) { protected static Iterable<HTTPHeader> getResourceFormatHeaders(HTTPRequest httpRequest, String format) {
List<HTTPHeader> headers = new ArrayList<>(); List<HTTPHeader> headers = new ArrayList<>();
@ -113,8 +105,8 @@ public class FhirRequestBuilder {
|| issue.getSeverity() == OperationOutcome.IssueSeverity.FATAL)); || issue.getSeverity() == OperationOutcome.IssueSeverity.FATAL));
} }
protected ManagedFhirWebAccessor getManagedWebAccessBuilder() { protected ManagedFhirWebAccessor getManagedWebAccessor() {
return ManagedWebAccess.fhirBuilder().withRetries(retryCount).withTimeout(timeout, timeoutUnit).withLogger(logger); return ManagedWebAccess.fhirAccessor().withRetries(retryCount).withTimeout(timeout, timeoutUnit).withLogger(logger);
} }
public FhirRequestBuilder withResourceFormat(String resourceFormat) { public FhirRequestBuilder withResourceFormat(String resourceFormat) {
@ -150,14 +142,14 @@ public class FhirRequestBuilder {
public <T extends Resource> ResourceRequest<T> execute() throws IOException { public <T extends Resource> ResourceRequest<T> execute() throws IOException {
HTTPRequest requestWithHeaders = formatHeaders(httpRequest, resourceFormat, headers); HTTPRequest requestWithHeaders = formatHeaders(httpRequest, resourceFormat, headers);
HTTPResult response = getManagedWebAccessBuilder().httpCall(requestWithHeaders);//getHttpClient().newCall(httpRequest.build()).execute(); HTTPResult response = getManagedWebAccessor().httpCall(requestWithHeaders);//getHttpClient().newCall(httpRequest.build()).execute();
T resource = unmarshalReference(response, resourceFormat, null); T resource = unmarshalReference(response, resourceFormat, null);
return new ResourceRequest<T>(resource, response.getCode(), getLocationHeader(response.getHeaders())); return new ResourceRequest<T>(resource, response.getCode(), getLocationHeader(response.getHeaders()));
} }
public Bundle executeAsBatch() throws IOException { public Bundle executeAsBatch() throws IOException {
HTTPRequest requestWithHeaders = formatHeaders(httpRequest, resourceFormat, null); HTTPRequest requestWithHeaders = formatHeaders(httpRequest, resourceFormat, null);
HTTPResult response = getManagedWebAccessBuilder().httpCall(requestWithHeaders); HTTPResult response = getManagedWebAccessor().httpCall(requestWithHeaders);
return unmarshalFeed(response, resourceFormat); return unmarshalFeed(response, resourceFormat);
} }
@ -258,7 +250,7 @@ public class FhirRequestBuilder {
/** /**
* Returns the appropriate parser based on the format type passed in. Defaults to XML parser if a blank format is * Returns the appropriate parser based on the format type passed in. Defaults to XML parser if a blank format is
* provided...because reasons. * provided...because reasons.
* <p> * <p/>
* Currently supports only "json" and "xml" formats. * Currently supports only "json" and "xml" formats.
* *
* @param format One of "json" or "xml". * @param format One of "json" or "xml".
@ -279,8 +271,10 @@ public class FhirRequestBuilder {
} }
/** /**
* Extracts the 'location' header from. If no value for 'location' exists, the * Extracts the 'location' header from the passed headers. If no value for 'location' exists, the
* value for 'content-location' is returned. If neither header exists, we return null. * value for 'content-location' is returned. If neither header exists, we return null.
*
* @param headers Headers to search for 'location' or 'content-location'.
*/ */
protected static String getLocationHeader(Iterable<HTTPHeader> headers) { protected static String getLocationHeader(Iterable<HTTPHeader> headers) {
String locationHeader = HTTPHeaderUtil.getSingleHeader(headers, LOCATION_HEADER); String locationHeader = HTTPHeaderUtil.getSingleHeader(headers, LOCATION_HEADER);

View File

@ -18,7 +18,6 @@ class FhirRequestBuilderTest {
@Test @Test
@DisplayName("Test resource format headers are added correctly (GET).") @DisplayName("Test resource format headers are added correctly (GET).")
void addResourceFormatHeadersGET() { void addResourceFormatHeadersGET() {
//FIXME tested here. Should get list of HTTPHeader.
String testFormat = "yaml"; String testFormat = "yaml";
HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com").withMethod(HTTPRequest.HttpMethod.GET); HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com").withMethod(HTTPRequest.HttpMethod.GET);
@ -35,7 +34,6 @@ class FhirRequestBuilderTest {
@Test @Test
@DisplayName("Test resource format headers are added correctly (POST).") @DisplayName("Test resource format headers are added correctly (POST).")
void addResourceFormatHeadersPOST() { void addResourceFormatHeadersPOST() {
//FIXME tested here. Should get list of HTTPHeader.
String testFormat = "yaml"; String testFormat = "yaml";
HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com").withMethod(HTTPRequest.HttpMethod.POST); HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com").withMethod(HTTPRequest.HttpMethod.POST);

View File

@ -126,10 +126,9 @@ public class ManagedFhirWebAccessor extends ManagedWebAccessorBase<ManagedFhirWe
} }
OkHttpClient okHttpClient = getOkHttpClient(); OkHttpClient okHttpClient = getOkHttpClient();
//TODO check and throw based on httpRequest: //TODO check and throw based on httpRequest:
// if (!ManagedWebAccess.inAllowedPaths(url)) {
// throw new IOException("The pathname '"+url+"' cannot be accessed by policy"); if (!ManagedWebAccess.inAllowedPaths(httpRequestWithDirectHeaders.getUrl().toString())) {
// } throw new IOException("The pathname '"+httpRequestWithDirectHeaders.getUrl().toString()+"' cannot be accessed by policy");}
//TODO add auth headers to httpRequest
Response response = okHttpClient.newCall(requestBuilder.build()).execute(); Response response = okHttpClient.newCall(requestBuilder.build()).execute();
return getHTTPResult(response); return getHTTPResult(response);
case MANAGED: case MANAGED:
@ -144,7 +143,7 @@ public class ManagedFhirWebAccessor extends ManagedWebAccessorBase<ManagedFhirWe
} }
private HTTPResult getHTTPResult(Response execute) throws IOException { private HTTPResult getHTTPResult(Response execute) throws IOException {
return new HTTPResult(execute.request().url().toString(), execute.code(), execute.message(), execute.header("Content-Type"), execute.body() != null && execute.body().contentLength() > 0 ? execute.body().bytes() : null, getHeadersFromResponse(execute)); return new HTTPResult(execute.request().url().toString(), execute.code(), execute.message(), execute.header("Content-Type"), execute.body() != null && execute.body().contentLength() != 0 ? execute.body().bytes() : null, getHeadersFromResponse(execute));
} }
private Iterable<HTTPHeader> getHeadersFromResponse(Response response) { private Iterable<HTTPHeader> getHeadersFromResponse(Response response) {

View File

@ -68,6 +68,7 @@ public class ManagedWebAccess {
} }
private static WebAccessPolicy accessPolicy = WebAccessPolicy.DIRECT; // for legacy reasons private static WebAccessPolicy accessPolicy = WebAccessPolicy.DIRECT; // for legacy reasons
//TODO get this from fhir settings
private static List<String> allowedDomains = new ArrayList<>(); private static List<String> allowedDomains = new ArrayList<>();
@Getter @Getter
private static IWebAccessor accessor; private static IWebAccessor accessor;
@ -103,32 +104,32 @@ public class ManagedWebAccess {
ManagedWebAccess.userAgent = userAgent; ManagedWebAccess.userAgent = userAgent;
} }
public static ManagedWebAccessor builder() { public static ManagedWebAccessor accessor() {
return new ManagedWebAccessor(userAgent, serverAuthDetails); return new ManagedWebAccessor(userAgent, serverAuthDetails);
} }
public static ManagedFhirWebAccessor fhirBuilder() { public static ManagedFhirWebAccessor fhirAccessor() {
return new ManagedFhirWebAccessor(userAgent, serverAuthDetails); return new ManagedFhirWebAccessor(userAgent, serverAuthDetails);
} }
public static HTTPResult get(String url) throws IOException { public static HTTPResult get(String url) throws IOException {
return builder().get(url); return accessor().get(url);
} }
public static HTTPResult get(String url, String accept) throws IOException { public static HTTPResult get(String url, String accept) throws IOException {
return builder().get(url, accept); return accessor().get(url, accept);
} }
public static HTTPResult post(String url, byte[] content, String contentType, String accept) throws IOException { public static HTTPResult post(String url, byte[] content, String contentType, String accept) throws IOException {
return builder().post(url, content, contentType, accept); return accessor().post(url, content, contentType, accept);
} }
public static HTTPResult put(String url, byte[] content, String contentType, String accept) throws IOException { public static HTTPResult put(String url, byte[] content, String contentType, String accept) throws IOException {
return builder().put(url, content, contentType, accept); return accessor().put(url, content, contentType, accept);
} }
public static HTTPResult httpCall(HTTPRequest httpRequest) throws IOException { public static HTTPResult httpCall(HTTPRequest httpRequest) throws IOException {
return fhirBuilder().httpCall(httpRequest); return fhirAccessor().httpCall(httpRequest);
} }
public static void loadFromFHIRSettings() { public static void loadFromFHIRSettings() {

View File

@ -175,13 +175,13 @@ public class PackageClient {
} }
private InputStream fetchUrl(String source, String accept) throws IOException { private InputStream fetchUrl(String source, String accept) throws IOException {
ManagedWebAccessor client = ManagedWebAccess.builder(); ManagedWebAccessor webAccessor = ManagedWebAccess.accessor();
if (server.getAuthenticationMode() == HTTPAuthenticationMode.TOKEN) { if (server.getAuthenticationMode() == HTTPAuthenticationMode.TOKEN) {
client.withToken(server.getToken()); webAccessor.withToken(server.getToken());
} else if (server.getAuthenticationMode() == HTTPAuthenticationMode.BASIC) { } else if (server.getAuthenticationMode() == HTTPAuthenticationMode.BASIC) {
client.withBasicAuth(server.getUsername(), server.getPassword()); webAccessor.withBasicAuth(server.getUsername(), server.getPassword());
} }
HTTPResult res = client.get(source, accept); HTTPResult res = webAccessor.get(source, accept);
res.checkThrowException(); res.checkThrowException();
return new ByteArrayInputStream(res.getContent()); return new ByteArrayInputStream(res.getContent());
} }

View File

@ -10,7 +10,6 @@ public class ManagedFhirWebAccessorTests {
@Test @Test
@DisplayName("Test default headers are added correctly.") @DisplayName("Test default headers are added correctly.")
void addDefaultAgentHeader() { void addDefaultAgentHeader() {
// FIXME move to ManagedFhirWebAccessBuilder
HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com"); HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com");
ManagedFhirWebAccessor builder = new ManagedFhirWebAccessor(expectedUserAgent, null); ManagedFhirWebAccessor builder = new ManagedFhirWebAccessor(expectedUserAgent, null);
@ -22,7 +21,6 @@ public class ManagedFhirWebAccessorTests {
@Test @Test
@DisplayName("Test default headers are added correctly.") @DisplayName("Test default headers are added correctly.")
void addDefaultBasicHeader() { void addDefaultBasicHeader() {
// FIXME move to ManagedFhirWebAccessBuilder
HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com"); HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com");
ManagedFhirWebAccessor builder = new ManagedFhirWebAccessor(expectedUserAgent, null) ManagedFhirWebAccessor builder = new ManagedFhirWebAccessor(expectedUserAgent, null)

View File

@ -207,4 +207,10 @@ public void testTokenAuthFromSettings() throws IOException, InterruptedException
null, null,
null, DUMMY_API_KEY); null, DUMMY_API_KEY);
} }
@Test
public void verifyAllowedPaths() {
//TODO the allowed paths cannot be set for now, meaning all will be allowed.
ManagedWebAccess.inAllowedPaths("http://www.anywhere.com");
}
} }