Search in sources :

Example 1 with LoggingInterceptor

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;
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) PlainConnectionSocketFactory(org.apache.http.conn.socket.PlainConnectionSocketFactory) LoggingInterceptor(ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) HttpClient(org.apache.http.client.HttpClient) SSLContext(javax.net.ssl.SSLContext) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Example 2 with LoggingInterceptor

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;
}
Also used : LoggingInterceptor(ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) BearerTokenAuthInterceptor(ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor)

Example 3 with LoggingInterceptor

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);
}
Also used : IpfFhirServlet(org.openehealth.ipf.commons.ihe.fhir.IpfFhirServlet) Logger(org.slf4j.Logger) MessageDigest(java.security.MessageDigest) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) FhirTestContainer(org.openehealth.ipf.platform.camel.ihe.fhir.test.FhirTestContainer) SslAwareMethanolRestfulClientFactory(org.openehealth.ipf.commons.ihe.fhir.SslAwareMethanolRestfulClientFactory) LoggingInterceptor(ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor) java.time(java.time) IpfFhirServlet(org.openehealth.ipf.commons.ihe.fhir.IpfFhirServlet) FhirVersionEnum(ca.uhn.fhir.context.FhirVersionEnum) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Iti65Constants(org.openehealth.ipf.commons.ihe.fhir.iti65.Iti65Constants) org.hl7.fhir.dstu3.model(org.hl7.fhir.dstu3.model) LoggingInterceptor(ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor) SslAwareMethanolRestfulClientFactory(org.openehealth.ipf.commons.ihe.fhir.SslAwareMethanolRestfulClientFactory)

Example 4 with 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));
}
Also used : LoggingInterceptor(ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with LoggingInterceptor

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));
}
Also used : LoggingInterceptor(ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

LoggingInterceptor (ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor)21 BeforeEach (org.junit.jupiter.api.BeforeEach)9 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)4 BearerTokenAuthInterceptor (ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor)4 Server (org.eclipse.jetty.server.Server)4 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)4 BeforeClass (org.junit.BeforeClass)4 FhirVersionEnum (ca.uhn.fhir.context.FhirVersionEnum)2 UrlTenantSelectionInterceptor (ca.uhn.fhir.rest.client.interceptor.UrlTenantSelectionInterceptor)2 IpfFhirServlet (org.openehealth.ipf.commons.ihe.fhir.IpfFhirServlet)2 SslAwareMethanolRestfulClientFactory (org.openehealth.ipf.commons.ihe.fhir.SslAwareMethanolRestfulClientFactory)2 FhirTestContainer (org.openehealth.ipf.platform.camel.ihe.fhir.test.FhirTestContainer)2 IClientInterceptor (ca.uhn.fhir.rest.client.api.IClientInterceptor)1 AdditionalRequestHeadersInterceptor (ca.uhn.fhir.rest.client.interceptor.AdditionalRequestHeadersInterceptor)1 BasicAuthInterceptor (ca.uhn.fhir.rest.client.interceptor.BasicAuthInterceptor)1 CookieInterceptor (ca.uhn.fhir.rest.client.interceptor.CookieInterceptor)1 ICriterion (ca.uhn.fhir.rest.gclient.ICriterion)1 ReferenceClientParam (ca.uhn.fhir.rest.gclient.ReferenceClientParam)1 TokenClientParam (ca.uhn.fhir.rest.gclient.TokenClientParam)1 MessageDigest (java.security.MessageDigest)1