@SuppressWarnings("unused") public void enableValidation() { // START SNIPPET: clientValidation FhirContext ctx = FhirContext.forDstu3(); ctx.setParserErrorHandler(new StrictErrorHandler()); // This client will have strict parser validation enabled IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu3"); // END SNIPPET: clientValidation }
@Override public void invalidValue(IParseLocation theLocation, String theValue, String theError) { if (isBlank(theValue) || myErrorOnInvalidValue == false) { if (myLogErrors) { ourLog.warn("Invalid attribute value \"{}\": {}", theValue, theError); } } else { STRICT_ERROR_HANDLER.invalidValue(theLocation, theValue, theError); } }
@Override protected void initialize() throws ServletException { // ...Configure resource providers, etc... // Create a context, set the error handler and instruct // the server to use it FhirContext ctx = FhirContext.forDstu3(); ctx.setParserErrorHandler(new StrictErrorHandler()); setFhirContext(ctx); }
@Override public void invalidValue(IParseLocation theLocation, String theValue, String theError) { if (isBlank(theValue) || myErrorOnInvalidValue == false) { if (myLogErrors) { ourLog.warn("Invalid attribute value \"{}\": {}", theValue, theError); } } else { STRICT_ERROR_HANDLER.invalidValue(theLocation, theValue, theError); } }
public void parserValidation() { // START SNIPPET: parserValidation FhirContext ctx = FhirContext.forDstu3(); // Create a parser and configure it to use the strict error handler IParser parser = ctx.newXmlParser(); parser.setParserErrorHandler(new StrictErrorHandler()); // This example resource is invalid, as Patient.active can not repeat String input = "<Patient><active value=\"true\"/><active value=\"false\"/></Patient>"; // The following will throw a DataFormatException because of the StrictErrorHandler parser.parseResource(Patient.class, input); // END SNIPPET: parserValidation }
String key = "key"; Integer cached = 0; MemcacheService memcacheService = MemcacheServiceFactory.getMemcacheService(); memcacheService.setErrorHandler(new StrictErrorHandler()); cached = (Integer) memcacheService.get(key); if (cached == null) { memcacheService.put(key, 0); } else { memcacheService.put(key, cached + 1); }
public static void main(String[] args) { String input = "<Encounter xmlns=\"http://hl7.org/fhir\"><AAAA value=\"foo\"/></Encounter>"; IParser p = FhirContext.forDstu3().newXmlParser(); // Parse with (default) lenient error handler p.setParserErrorHandler(new LenientErrorHandler()); p.parseResource(input); // Parse with strict error handler p.setParserErrorHandler(new StrictErrorHandler()); p.parseResource(input); } }
jsonParser.setParserErrorHandler(new StrictErrorHandler());