diff --git a/solr/src/java/org/apache/solr/handler/XmlUpdateRequestHandler.java b/solr/src/java/org/apache/solr/handler/XmlUpdateRequestHandler.java index c86f7fafbf5..7dbfc45cf04 100644 --- a/solr/src/java/org/apache/solr/handler/XmlUpdateRequestHandler.java +++ b/solr/src/java/org/apache/solr/handler/XmlUpdateRequestHandler.java @@ -84,47 +84,6 @@ public class XmlUpdateRequestHandler extends ContentStreamHandlerBase { return new XMLLoader(processor, inputFactory); } - - /** - * A Convenience method for getting back a simple XML string indicating - * success or failure from an XML formated Update (from the Reader) - * - * @since solr 1.2 - * @deprecated Direct updates fro ma Reader, as well as the response - * format produced by this method, have been deprecated - * and will be removed in future versions. Any code using - * this method should be changed to use {@link #handleRequest} - * method with a ContentStream. - */ - @Deprecated - public void doLegacyUpdate(Reader input, Writer output) { - SolrCore core = SolrCore.getSolrCore(); - SolrQueryRequest req = new LocalSolrQueryRequest(core, new HashMap()); - - try { - // Old style requests do not choose a custom handler - UpdateRequestProcessorChain processorFactory = core.getUpdateProcessingChain(null); - - SolrQueryResponse rsp = new SolrQueryResponse(); // ignored - XMLStreamReader parser = inputFactory.createXMLStreamReader(input); - UpdateRequestProcessor processor = processorFactory.createProcessor(req, rsp); - XMLLoader loader = (XMLLoader) newLoader(req, processor); - loader.processUpdate(req, processor, parser); - processor.finish(); - output.write(""); - } - catch (Exception ex) { - try { - SolrException.logOnce(log, "Error processing \"legacy\" update command", ex); - XML.writeXML(output, "result", SolrException.toStr(ex), "status", "1"); - } catch (Exception ee) { - log.error("Error writing to output stream: " + ee); - } - } - finally { - req.close(); - } - } //////////////////////// SolrInfoMBeans methods ////////////////////// @Override diff --git a/solr/src/java/org/apache/solr/util/TestHarness.java b/solr/src/java/org/apache/solr/util/TestHarness.java index d6c1a633ba9..ea5a703133c 100644 --- a/solr/src/java/org/apache/solr/util/TestHarness.java +++ b/solr/src/java/org/apache/solr/util/TestHarness.java @@ -17,6 +17,7 @@ package org.apache.solr.util; +import org.apache.solr.common.SolrException; import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.XML; @@ -25,13 +26,16 @@ import org.apache.solr.core.SolrCore; import org.apache.solr.core.CoreContainer; import org.apache.solr.core.CoreDescriptor; import org.apache.solr.core.SolrResourceLoader; +import org.apache.solr.handler.JsonUpdateRequestHandler; import org.apache.solr.handler.XmlUpdateRequestHandler; import org.apache.solr.request.LocalSolrQueryRequest; import org.apache.solr.request.SolrQueryRequest; +import org.apache.solr.request.SolrRequestHandler; import org.apache.solr.request.SolrRequestInfo; import org.apache.solr.response.QueryResponseWriter; import org.apache.solr.response.SolrQueryResponse; import org.apache.solr.schema.IndexSchema; +import org.apache.solr.servlet.DirectSolrConnection; import org.w3c.dom.Document; import org.xml.sax.SAXException; import org.apache.solr.common.util.NamedList.NamedListEntry; @@ -202,20 +206,25 @@ public class TestHarness { /** * Processes an "update" (add, commit or optimize) and * returns the response as a String. - * - * @deprecated The better approach is to instantiate an Updatehandler directly * * @param xml The XML of the update * @return The XML response to the update */ - @Deprecated public String update(String xml) { - - StringReader req = new StringReader(xml); - StringWriter writer = new StringWriter(32000); - - updater.doLegacyUpdate(req, writer); - return writer.toString(); + DirectSolrConnection connection = new DirectSolrConnection(core); + SolrRequestHandler handler = core.getRequestHandler("/update"); + // prefer the handler mapped to /update, but use our generic backup handler + // if that lookup fails + if (handler == null) { + handler = updater; + } + try { + return connection.request(handler, null, xml); + } catch (SolrException e) { + throw (SolrException)e; + } catch (Exception e) { + throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e); + } } @@ -240,7 +249,12 @@ public class TestHarness { * @return null if successful, otherwise the XML response to the update */ public String validateErrorUpdate(String xml) throws SAXException { - return checkUpdateStatus(xml, "1"); + try { + return checkUpdateStatus(xml, "1"); + } catch (SolrException e) { + // return ((SolrException)e).getMessage(); + return null; // success + } } /** @@ -254,7 +268,7 @@ public class TestHarness { public String checkUpdateStatus(String xml, String code) throws SAXException { try { String res = update(xml); - String valid = validateXPath(res, "//result[@status="+code+"]" ); + String valid = validateXPath(res, "//int[@name='status']="+code ); return (null == valid) ? null : res; } catch (XPathExpressionException e) { throw new RuntimeException @@ -262,27 +276,6 @@ public class TestHarness { } } - /** - * Validates that an add of a single document results in success. - * - * @param fieldsAndValues Odds are field names, Evens are values - * @return null if successful, otherwise the XML response to the update - * @see #appendSimpleDoc - */ - public String validateAddDoc(String... fieldsAndValues) - throws XPathExpressionException, SAXException, IOException { - - StringBuilder buf = new StringBuilder(); - buf.append(""); - appendSimpleDoc(buf, fieldsAndValues); - buf.append(""); - - String res = update(buf.toString()); - String valid = validateXPath(res, "//result[@status=0]" ); - return (null == valid) ? null : res; - } - - /** * Validates a "query" response against an array of XPath test strings @@ -409,29 +402,6 @@ public class TestHarness { } } - /** - * A helper that adds an xml <doc> containing all of the - * fields and values specified (odds are fields, evens are values) - * to a StringBuilder - */ - public void appendSimpleDoc(StringBuilder buf, String... fieldsAndValues) - throws IOException { - - buf.append(makeSimpleDoc(fieldsAndValues)); - } - - /** - * A helper that adds an xml <doc> containing all of the - * fields and values specified (odds are fields, evens are values) - * to a StringBuffer. - * @deprecated see {@link #appendSimpleDoc(StringBuilder, String...)} - */ - @Deprecated - public void appendSimpleDoc(StringBuffer buf, String... fieldsAndValues) - throws IOException { - - buf.append(makeSimpleDoc(fieldsAndValues)); - } /** * A helper that creates an xml <doc> containing all of the * fields and values specified diff --git a/solr/src/test/org/apache/solr/BasicFunctionalityTest.java b/solr/src/test/org/apache/solr/BasicFunctionalityTest.java index f50bbe1c1e3..7cac48d9c17 100644 --- a/solr/src/test/org/apache/solr/BasicFunctionalityTest.java +++ b/solr/src/test/org/apache/solr/BasicFunctionalityTest.java @@ -247,7 +247,7 @@ public class BasicFunctionalityTest extends SolrTestCaseJ4 { clearIndex(); // big freaking kludge since the response is currently not well formed. String res = h.update("12"); - assertEquals("", res); + // assertEquals("", res); assertU(""); assertQ(req("id:[0 TO 99]") ,"//*[@numFound='2']" @@ -263,7 +263,7 @@ public class BasicFunctionalityTest extends SolrTestCaseJ4 { "hello" + ""); - assertEquals("", res); + // assertEquals("", res); assertU(""); assertQ(req("text:hello") ,"//*[@numFound='2']" @@ -282,7 +282,7 @@ public class BasicFunctionalityTest extends SolrTestCaseJ4 { "hello" + ""); - assertEquals("", res); + // assertEquals("", res); assertU(""); assertQ(req("text:hello"), "//*[@numFound='2']" diff --git a/solr/src/test/org/apache/solr/update/DirectUpdateHandlerTest.java b/solr/src/test/org/apache/solr/update/DirectUpdateHandlerTest.java index 832687a585a..2e05af23d3d 100644 --- a/solr/src/test/org/apache/solr/update/DirectUpdateHandlerTest.java +++ b/solr/src/test/org/apache/solr/update/DirectUpdateHandlerTest.java @@ -60,10 +60,12 @@ public class DirectUpdateHandlerTest extends SolrTestCaseJ4 { assertU(adoc("id","1")); // More than one id should fail - assertFailedU(adoc("id","2", "id","3", "text","ignore_exception")); + assertFailedU(adoc("id","2", "id","ignore_exception", "text","foo")); // No id should fail - assertFailedU(adoc("text","ignore_exception")); + ignoreException("id"); + assertFailedU(adoc("text","foo")); + resetExceptionIgnores(); } diff --git a/solr/src/test/test-files/solr/conf/solrconfig-functionquery.xml b/solr/src/test/test-files/solr/conf/solrconfig-functionquery.xml index e4b8d791ee3..0276195c762 100755 --- a/solr/src/test/test-files/solr/conf/solrconfig-functionquery.xml +++ b/solr/src/test/test-files/solr/conf/solrconfig-functionquery.xml @@ -28,10 +28,12 @@ + 0.0 +