use of ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor in project beneficiary-fhir-data by CMSgov.
the class ServerTestUtils method createFhirClient.
/**
* @param versionId the {@link v1 or v2 identifier to use as a part of the URL for the FHIR server
* @param clientSslIdentity the {@link ClientSslIdentity} to use as a login for the FHIR server
* @return a new FHIR {@link IGenericClient} for use
*/
private IGenericClient createFhirClient(String versionId, Optional<ClientSslIdentity> clientSslIdentity, FhirContext ctx) {
// Figure out where the test server is running.
String fhirBaseUrl = String.format("%s/%s/fhir", getServerBaseUrl(), versionId);
/*
* We need to override the FHIR client's SSLContext. Unfortunately, that
* requires overriding the entire HttpClient that it uses. Otherwise,
* the settings used here mirror those that the default FHIR HttpClient
* would use.
*/
SSLContext sslContext = createSslContext(clientSslIdentity);
/*
* The default timeout is 10s, which was failing for batches of 100. A
* 300s timeout was failing for batches of 100 once Part B claims were
* mostly mapped, so batches were cut to 10, which ran at 12s or so,
* each.
*/
ctx.getRestfulClientFactory().setSocketTimeout((int) TimeUnit.MINUTES.toMillis(5));
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", new SSLConnectionSocketFactory(sslContext)).build(), null, null, null, 5000, TimeUnit.MILLISECONDS);
@SuppressWarnings("deprecation") RequestConfig defaultRequestConfig = RequestConfig.custom().setSocketTimeout(ctx.getRestfulClientFactory().getSocketTimeout()).setConnectTimeout(ctx.getRestfulClientFactory().getConnectTimeout()).setConnectionRequestTimeout(ctx.getRestfulClientFactory().getConnectionRequestTimeout()).setStaleConnectionCheckEnabled(true).build();
HttpClient httpClient = HttpClients.custom().setConnectionManager(connectionManager).setDefaultRequestConfig(defaultRequestConfig).disableCookieManagement().build();
ctx.getRestfulClientFactory().setHttpClient(httpClient);
IGenericClient client = ctx.newRestfulGenericClient(fhirBaseUrl);
/*
* The FHIR client logging (for tests) can be managed via the
* `src/test/resources/logback-test.xml` file.
*/
LoggingInterceptor loggingInterceptor = new LoggingInterceptor();
loggingInterceptor.setLogRequestSummary(LOGGER.isDebugEnabled());
loggingInterceptor.setLogResponseSummary(LOGGER.isDebugEnabled());
loggingInterceptor.setLogRequestHeaders(LOGGER.isTraceEnabled());
loggingInterceptor.setLogResponseHeaders(LOGGER.isTraceEnabled());
loggingInterceptor.setLogRequestBody(LOGGER.isTraceEnabled());
loggingInterceptor.setLogResponseBody(LOGGER.isTraceEnabled());
client.registerInterceptor(loggingInterceptor);
return client;
}
use of ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor in project cqf-ruler by DBCG.
the class EvaluationContext method getHookFhirClient.
public IGenericClient getHookFhirClient() {
IGenericClient client = this.fhirContext.newRestfulGenericClient(this.hook.getRequest().getFhirServerUrl());
if (this.hook.getRequest().getFhirAuthorization() != null && hook.getRequest().getFhirAuthorization().getTokenType().equals("Bearer")) {
BearerTokenAuthInterceptor authInterceptor = new BearerTokenAuthInterceptor(hook.getRequest().getFhirAuthorization().getAccessToken());
client.registerInterceptor(authInterceptor);
// TODO: account for the expires_in, scope and subject properties within
// workflow
}
LoggingInterceptor loggingInterceptor = new LoggingInterceptor();
loggingInterceptor.setLogRequestSummary(true);
loggingInterceptor.setLogRequestHeaders(true);
loggingInterceptor.setLogRequestBody(true);
loggingInterceptor.setLogResponseSummary(true);
loggingInterceptor.setLogResponseHeaders(true);
loggingInterceptor.setLogResponseBody(true);
client.registerInterceptor(loggingInterceptor);
return client;
}
use of ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor in project ipf by oehf.
the class AbstractTestIti65 method startServer.
public static void startServer(String contextDescriptor) {
var servlet = new IpfFhirServlet(FhirVersionEnum.DSTU3);
startServer(servlet, contextDescriptor, false, DEMO_APP_PORT, "FhirServlet");
var loggingInterceptor = new LoggingInterceptor();
loggingInterceptor.setLogRequestSummary(false);
loggingInterceptor.setLogRequestBody(true);
loggingInterceptor.setLogResponseBody(true);
startClient(String.format("http://localhost:%d/", DEMO_APP_PORT), fhirContext -> {
var clientFactory = new SslAwareMethanolRestfulClientFactory(fhirContext);
clientFactory.setAsync(true);
fhirContext.setRestfulClientFactory(clientFactory);
}).registerInterceptor(loggingInterceptor);
}
use of ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor in project hapi-fhir-jpaserver-starter by hapifhir.
the class ElasticsearchLastNR4IT method beforeEach.
@BeforeEach
void beforeEach() {
ourCtx = FhirContext.forR4();
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
String ourServerBase = "http://localhost:" + port + "/fhir/";
ourClient = ourCtx.newRestfulGenericClient(ourServerBase);
ourClient.registerInterceptor(new LoggingInterceptor(true));
}
use of ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor in project hapi-fhir-jpaserver-starter by hapifhir.
the class ExampleServerR5IT method beforeEach.
@BeforeEach
void beforeEach() {
ourCtx = FhirContext.forR5();
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
String ourServerBase = "http://localhost:" + port + "/fhir/";
ourClient = ourCtx.newRestfulGenericClient(ourServerBase);
ourClient.registerInterceptor(new LoggingInterceptor(true));
}
Aggregations