From e8d1b14d94d84eab3ef1d73f177435851712e7ff Mon Sep 17 00:00:00 2001 From: Hilbrand Bouwkamp Date: Mon, 8 Jan 2024 15:25:08 +0100 Subject: [PATCH] AER-1036 log validation errors as debug since message is rethrown again and later logged if needd. (#236) --- .../overheid/aerius/gml/GMLReaderFactory.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/GMLReaderFactory.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/GMLReaderFactory.java index 5378e8c8..b2c3b5a4 100644 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/GMLReaderFactory.java +++ b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/GMLReaderFactory.java @@ -48,6 +48,8 @@ */ public final class GMLReaderFactory { private static final Logger LOG = LoggerFactory.getLogger(GMLReaderFactory.class); + private static final Pattern PARSE_ERROR_PATTERN_1 = Pattern.compile("ParseError at \\[row,col\\]:\\[(\\d+),(\\d+)\\]"); + private static final Pattern PARSE_ERROR_PATTERN_2 = Pattern.compile("The element type \"([^\"]+)\"[^\"]+\"([^\"]+)"); private static final XMLInputFactory XMLINPUT_FACTORY = SafeXMLInputFactory.newFactory(); private static final Object FACTORY_LOCK = new Object(); private static GMLReaderFactory instance; @@ -114,7 +116,7 @@ public ValidationHelper createValidationHelper() { return gmlHelper.getValidationHelper(); } - private void checkEvents(final List events) throws AeriusException { + private static void checkEvents(final List events) throws AeriusException { // information like required elements not being present will not throw an exception, but will trigger an event. // check for these events and throw exception if present. if ((events != null) && !events.isEmpty()) { @@ -122,7 +124,7 @@ private void checkEvents(final List events) throws AeriusExcept } } - private FeatureCollection convertToCollection(final XMLStreamReader xmlStreamReader, final GMLVersionReaderFactory factory, + private static FeatureCollection convertToCollection(final XMLStreamReader xmlStreamReader, final GMLVersionReaderFactory factory, final CustomValidationEventCollector vec, final boolean validate) throws AeriusException { FeatureCollection collection = null; try { @@ -141,7 +143,7 @@ private FeatureCollection convertToCollection(final XMLStreamReader xmlStreamRea return collection; } - private void processException(final CustomValidationEventCollector vec, final JAXBException e) throws AeriusException { + private static void processException(final CustomValidationEventCollector vec, final JAXBException e) throws AeriusException { if ((e.getLinkedException() instanceof UTFDataFormatException) || (e.getLinkedException() instanceof UnsupportedEncodingException)) { throw new AeriusException(ImaerExceptionReason.GML_ENCODING_INCORRECT); } else if (e.getLinkedException() instanceof XMLStreamException) { @@ -152,11 +154,9 @@ private void processException(final CustomValidationEventCollector vec, final JA } } - private AeriusException newGmlParseError(final XMLStreamException e) { - final Pattern pattern1 = Pattern.compile("ParseError at \\[row,col\\]:\\[(\\d+),(\\d+)\\]"); - final Pattern pattern2 = Pattern.compile("The element type \"([^\"]+)\"[^\"]+\"([^\"]+)"); - final Matcher matcher1 = pattern1.matcher(e.getMessage()); - final Matcher matcher2 = pattern2.matcher(e.getMessage()); + private static AeriusException newGmlParseError(final XMLStreamException e) { + final Matcher matcher1 = PARSE_ERROR_PATTERN_1.matcher(e.getMessage()); + final Matcher matcher2 = PARSE_ERROR_PATTERN_2.matcher(e.getMessage()); if (matcher1.find() && matcher2.find()) { return new AeriusException(ImaerExceptionReason.GML_PARSE_ERROR, matcher1.group(1), matcher1.group(2), matcher2.group(1), matcher2.group(2)); } else { @@ -165,13 +165,13 @@ private AeriusException newGmlParseError(final XMLStreamException e) { } } - private AeriusException newValidationFailed(final List list) { + private static AeriusException newValidationFailed(final List list) { final StringBuilder errorLine = new StringBuilder(); for (final ValidationEvent event : list) { errorLine.append(event.getMessage()); errorLine.append(' '); } - LOG.error("validation error: {}", errorLine); + LOG.debug("validation error: {}", errorLine); return new AeriusException(ImaerExceptionReason.GML_VALIDATION_FAILED, errorLine.toString().trim()); } }