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);
}
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");
}
Aggregations