Search in sources :

Example 1 with LenientErrorHandler

use of ca.uhn.fhir.parser.LenientErrorHandler in project ipf by oehf.

the class IpfFhirServlet method initialize.

/**
 * Called upon initialization of the servlet, which is too early to know about the existing FHIR consumers
 * initialization of Camel routes and endpoints.
 */
@Override
protected void initialize() {
    if (fhirContext == null) {
        setFhirContext(new FhirContext(fhirVersion));
        getFhirContext().setParserErrorHandler(strictErrorHandler ? new StrictErrorHandler() : new LenientErrorHandler());
        /*
             * Use a narrative generator. This is a completely optional step,
             * but can be useful as it causes HAPI to generate narratives for
             * resources which don't otherwise have one.
             */
        getFhirContext().setNarrativeGenerator(getDefaultNarrativeGenerator());
    }
    if (logging) {
        registerInterceptor(getLoggingInterceptor());
    }
    if (responseHighlighting) {
        registerInterceptor(new ResponseHighlighterInterceptor());
    }
    setPagingProvider(getDefaultPagingProvider(pagingProviderSize));
    setDefaultPrettyPrint(prettyPrint);
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) StrictErrorHandler(ca.uhn.fhir.parser.StrictErrorHandler) ResponseHighlighterInterceptor(ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor) LenientErrorHandler(ca.uhn.fhir.parser.LenientErrorHandler)

Example 2 with LenientErrorHandler

use of ca.uhn.fhir.parser.LenientErrorHandler in project snowstorm by IHTSDO.

the class HapiRestfulServlet method initialize.

/**
 * The initialize method is automatically called when the servlet is starting up, so it can be used to configure the
 * servlet to define resource providers, or set up configuration, interceptors, etc.
 */
@Override
protected void initialize() throws ServletException {
    final WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    setDefaultResponseEncoding(EncodingEnum.JSON);
    final FhirContext ctxt = FhirContext.forR4();
    final LenientErrorHandler delegateHandler = new LenientErrorHandler();
    ctxt.setParserErrorHandler(new StrictErrorHandler() {

        @Override
        public void unknownAttribute(IParseLocation theLocation, String theAttributeName) {
            delegateHandler.unknownAttribute(theLocation, theAttributeName);
        }

        @Override
        public void unknownElement(IParseLocation theLocation, String theElementName) {
            delegateHandler.unknownElement(theLocation, theElementName);
        }

        @Override
        public void unknownReference(IParseLocation theLocation, String theReference) {
            delegateHandler.unknownReference(theLocation, theReference);
        }
    });
    setFhirContext(ctxt);
    /*
		 * The servlet defines any number of resource providers, and configures itself to use them by calling
		 * setResourceProviders()
		 */
    List<IResourceProvider> resourceProviders = new ArrayList<>();
    FHIRCodeSystemProvider csp = applicationContext.getBean(FHIRCodeSystemProvider.class);
    FHIRValueSetProvider vsp = applicationContext.getBean(FHIRValueSetProvider.class);
    FHIRConceptMapProvider cmp = applicationContext.getBean(FHIRConceptMapProvider.class);
    FHIRMedicationProvider mp = applicationContext.getBean(FHIRMedicationProvider.class);
    FHIRStructureDefinitionProvider sd = applicationContext.getBean(FHIRStructureDefinitionProvider.class);
    resourceProviders.add(csp);
    resourceProviders.add(vsp);
    resourceProviders.add(cmp);
    resourceProviders.add(mp);
    resourceProviders.add(sd);
    setResourceProviders(resourceProviders);
    FHIRTerminologyCapabilitiesProvider tcp = applicationContext.getBean(FHIRTerminologyCapabilitiesProvider.class);
    setServerConformanceProvider(tcp);
    // Now register interceptors
    RootInterceptor interceptor = new RootInterceptor();
    registerInterceptor(interceptor);
    logger.info("FHIR Resource providers and interceptors registered");
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) ArrayList(java.util.ArrayList) FHIRCodeSystemProvider(org.snomed.snowstorm.fhir.services.FHIRCodeSystemProvider) FHIRMedicationProvider(org.snomed.snowstorm.fhir.services.FHIRMedicationProvider) LenientErrorHandler(ca.uhn.fhir.parser.LenientErrorHandler) WebApplicationContext(org.springframework.web.context.WebApplicationContext) IResourceProvider(ca.uhn.fhir.rest.server.IResourceProvider) FHIRValueSetProvider(org.snomed.snowstorm.fhir.services.FHIRValueSetProvider) FHIRStructureDefinitionProvider(org.snomed.snowstorm.fhir.services.FHIRStructureDefinitionProvider) StrictErrorHandler(ca.uhn.fhir.parser.StrictErrorHandler) FHIRTerminologyCapabilitiesProvider(org.snomed.snowstorm.fhir.services.FHIRTerminologyCapabilitiesProvider) FHIRConceptMapProvider(org.snomed.snowstorm.fhir.services.FHIRConceptMapProvider)

Aggregations

FhirContext (ca.uhn.fhir.context.FhirContext)2 LenientErrorHandler (ca.uhn.fhir.parser.LenientErrorHandler)2 StrictErrorHandler (ca.uhn.fhir.parser.StrictErrorHandler)2 IResourceProvider (ca.uhn.fhir.rest.server.IResourceProvider)1 ResponseHighlighterInterceptor (ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor)1 ArrayList (java.util.ArrayList)1 FHIRCodeSystemProvider (org.snomed.snowstorm.fhir.services.FHIRCodeSystemProvider)1 FHIRConceptMapProvider (org.snomed.snowstorm.fhir.services.FHIRConceptMapProvider)1 FHIRMedicationProvider (org.snomed.snowstorm.fhir.services.FHIRMedicationProvider)1 FHIRStructureDefinitionProvider (org.snomed.snowstorm.fhir.services.FHIRStructureDefinitionProvider)1 FHIRTerminologyCapabilitiesProvider (org.snomed.snowstorm.fhir.services.FHIRTerminologyCapabilitiesProvider)1 FHIRValueSetProvider (org.snomed.snowstorm.fhir.services.FHIRValueSetProvider)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1