Add request logging for dstu3 FhirRequestBuilder
This commit is contained in:
parent
1ac0e90c07
commit
e997f7bb08
|
@ -206,14 +206,19 @@ public class FhirRequestBuilder {
|
||||||
|
|
||||||
public <T extends Resource> ResourceRequest<T> execute() throws IOException {
|
public <T extends Resource> ResourceRequest<T> execute() throws IOException {
|
||||||
formatHeaders(httpRequest, resourceFormat, headers);
|
formatHeaders(httpRequest, resourceFormat, headers);
|
||||||
Response response = getHttpClient().newCall(httpRequest.build()).execute();
|
final Request request = httpRequest.build();
|
||||||
|
log(request.method(), request.url().toString(), request.headers(), request.body() != null ? request.body().toString().getBytes() : null);
|
||||||
|
Response response = getHttpClient().newCall(request).execute();
|
||||||
T resource = unmarshalReference(response, resourceFormat);
|
T resource = unmarshalReference(response, resourceFormat);
|
||||||
return new ResourceRequest<T>(resource, response.code(), getLocationHeader(response.headers()));
|
return new ResourceRequest<T>(resource, response.code(), getLocationHeader(response.headers()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bundle executeAsBatch() throws IOException {
|
public Bundle executeAsBatch() throws IOException {
|
||||||
formatHeaders(httpRequest, resourceFormat, null);
|
formatHeaders(httpRequest, resourceFormat, null);
|
||||||
Response response = getHttpClient().newCall(httpRequest.build()).execute();
|
final Request request = httpRequest.build();
|
||||||
|
log(request.method(), request.url().toString(), request.headers(), request.body() != null ? request.body().toString().getBytes() : null);
|
||||||
|
|
||||||
|
Response response = getHttpClient().newCall(request).execute();
|
||||||
return unmarshalFeed(response, resourceFormat);
|
return unmarshalFeed(response, resourceFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,6 +307,26 @@ public class FhirRequestBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs the given {@link Request}, using the current {@link ToolingClientLogger}. If the current
|
||||||
|
* {@link FhirRequestBuilder#logger} is null, no action is taken.
|
||||||
|
*
|
||||||
|
* @param method HTTP request method
|
||||||
|
* @param url request URL
|
||||||
|
* @param requestHeaders {@link Headers} for request
|
||||||
|
* @param requestBody Byte array request
|
||||||
|
*/
|
||||||
|
protected void log(String method, String url, Headers requestHeaders, byte[] requestBody) {
|
||||||
|
if (logger != null) {
|
||||||
|
List<String> headerList = new ArrayList<>(Collections.emptyList());
|
||||||
|
Map<String, List<String>> headerMap = requestHeaders.toMultimap();
|
||||||
|
headerMap.keySet().forEach(key -> headerMap.get(key).forEach(value -> headerList.add(key + ":" + value)));
|
||||||
|
|
||||||
|
logger.logRequest(method, url, headerList, requestBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs the given {@link Response}, using the current {@link ToolingClientLogger}. If the current
|
* Logs the given {@link Response}, using the current {@link ToolingClientLogger}. If the current
|
||||||
* {@link FhirRequestBuilder#logger} is null, no action is taken.
|
* {@link FhirRequestBuilder#logger} is null, no action is taken.
|
||||||
|
|
|
@ -89,12 +89,13 @@ public class HTMLClientLogger extends BaseLogger implements ToolingClientLogger
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
System.out.println(" txlog resp: " +outcome+" "+present(body));
|
System.out.println(" txlog resp: " +outcome+" "+present(body));
|
||||||
}
|
}
|
||||||
req = false;
|
|
||||||
if (file == null)
|
if (file == null)
|
||||||
return;
|
return;
|
||||||
if (!req) {
|
if (!req) {
|
||||||
System.out.println("Record Response without request");
|
System.out.println("Record Response without request");
|
||||||
}
|
}
|
||||||
|
req = false;
|
||||||
file.println("<pre>");
|
file.println("<pre>");
|
||||||
file.println(outcome);
|
file.println(outcome);
|
||||||
for (String s : headers)
|
for (String s : headers)
|
||||||
|
|
Loading…
Reference in New Issue