From b4af32cb44bf599b28574736ad6dc2f830b00e95 Mon Sep 17 00:00:00 2001 From: "Chris M. Hostetter" Date: Wed, 12 Feb 2014 18:09:42 +0000 Subject: [PATCH] SOLR-5257: Improved error/warn messages when Update XML contains unexpected XML nodes git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1567706 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 4 +++ .../apache/solr/handler/loader/XMLLoader.java | 25 +++++++++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 00ff00a0e69..c71151c8b18 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -418,6 +418,10 @@ Other Changes * SOLR-5585: Raise Collections API timeout to 3 minutes from one minute. (Mark Miller) +* SOLR-5257: Improved error/warn messages when Update XML contains unexpected XML nodes + (Vitaliy Zhovtyuk, hossman) + + ================== 4.6.1 ================== Versions of Major Components diff --git a/solr/core/src/java/org/apache/solr/handler/loader/XMLLoader.java b/solr/core/src/java/org/apache/solr/handler/loader/XMLLoader.java index 400a75337aa..a9374be0766 100644 --- a/solr/core/src/java/org/apache/solr/handler/loader/XMLLoader.java +++ b/solr/core/src/java/org/apache/solr/handler/loader/XMLLoader.java @@ -235,7 +235,7 @@ public class XMLLoader extends ContentStreamLoader { } else if (UpdateRequestHandler.COMMIT_WITHIN.equals(attrName)) { addCmd.commitWithin = Integer.parseInt(attrVal); } else { - log.warn("Unknown attribute id in add:" + attrName); + log.warn("XML element has invalid XML attr: " + attrName); } } @@ -267,7 +267,7 @@ public class XMLLoader extends ContentStreamLoader { processor.processCommit(cmd); } // end commit else if (UpdateRequestHandler.ROLLBACK.equals(currTag)) { - log.trace("parsing " + currTag); + log.trace("parsing rollback"); RollbackUpdateCommand cmd = new RollbackUpdateCommand(req); @@ -303,7 +303,7 @@ public class XMLLoader extends ContentStreamLoader { } else if (UpdateRequestHandler.COMMIT_WITHIN.equals(attrName)) { deleteCmd.commitWithin = Integer.parseInt(attrVal); } else { - log.warn("unexpected attribute delete/@" + attrName); + log.warn("XML element has invalid XML attr: " + attrName); } } @@ -314,9 +314,10 @@ public class XMLLoader extends ContentStreamLoader { case XMLStreamConstants.START_ELEMENT: String mode = parser.getLocalName(); if (!("id".equals(mode) || "query".equals(mode))) { - log.warn("unexpected XML tag /delete/" + mode); + String msg = "XML element has invalid XML child element: " + mode; + log.warn(msg); throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, - "unexpected XML tag /delete/" + mode); + msg); } text.setLength(0); @@ -340,9 +341,10 @@ public class XMLLoader extends ContentStreamLoader { } else if ("delete".equals(currTag)) { return; } else { - log.warn("unexpected XML tag /delete/" + currTag); + String msg = "XML element has invalid XML (closing) child element: " + currTag; + log.warn(msg); throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, - "unexpected XML tag /delete/" + currTag); + msg); } processor.processDelete(deleteCmd); deleteCmd.clear(); @@ -373,7 +375,7 @@ public class XMLLoader extends ContentStreamLoader { if ("boost".equals(attrName)) { doc.setDocumentBoost(Float.parseFloat(parser.getAttributeValue(i))); } else { - log.warn("Unknown attribute doc/@" + attrName); + log.warn("XML element has invalid XML attr:" + attrName); } } @@ -447,9 +449,10 @@ public class XMLLoader extends ContentStreamLoader { } else { if (!"field".equals(localName)) { - log.warn("unexpected XML tag doc/" + localName); + String msg = "XML element has invalid XML child element: " + localName; + log.warn(msg); throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, - "unexpected XML tag doc/" + localName); + msg); } boost = 1.0f; update = null; @@ -467,7 +470,7 @@ public class XMLLoader extends ContentStreamLoader { } else if ("update".equals(attrName)) { update = attrVal; } else { - log.warn("Unknown attribute doc/field/@" + attrName); + log.warn("XML element has invalid XML attr: " + attrName); } } }