diff --git a/pom.xml b/pom.xml index f054d4ea5..12561d8af 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.marklogic java-client-api jar - 2.0.5 + 2.0.6 MarkLogic Java Client API The official MarkLogic Java client API. https://github.com/marklogic/java-client-api diff --git a/src/main/java/com/marklogic/client/alerting/RuleDefinition.java b/src/main/java/com/marklogic/client/alerting/RuleDefinition.java index a3574f3c9..96829f396 100644 --- a/src/main/java/com/marklogic/client/alerting/RuleDefinition.java +++ b/src/main/java/com/marklogic/client/alerting/RuleDefinition.java @@ -262,12 +262,15 @@ public void write(OutputStream out) throws IOException { "description", RequestConstants.RESTAPI_NS); serializer.writeCharacters(getDescription()); serializer.writeEndElement(); + serializer.flush(); // logger.debug("Send: " + new String(queryPayload)); XMLEventWriter eventWriter = factory.createXMLEventWriter(out); for (XMLEvent event : this.queryPayload) { eventWriter.add(event); } + eventWriter.flush(); + out.flush(); writeMetadataElement(serializer); diff --git a/src/main/java/com/marklogic/client/impl/BinaryDocumentImpl.java b/src/main/java/com/marklogic/client/impl/BinaryDocumentImpl.java index db711521e..9b8ffdd07 100644 --- a/src/main/java/com/marklogic/client/impl/BinaryDocumentImpl.java +++ b/src/main/java/com/marklogic/client/impl/BinaryDocumentImpl.java @@ -132,7 +132,7 @@ public T read(DocumentDescriptor desc, DocumentMeta RequestParameters extraParams = new RequestParameters(); if (length > 0) - extraParams.put("range", "bytes="+start+"-"+(start + length)); + extraParams.put("range", "bytes="+start+"-"+(start + length - 1)); else extraParams.put("range", "bytes="+String.valueOf(start)); diff --git a/src/main/java/com/marklogic/client/io/DocumentMetadataHandle.java b/src/main/java/com/marklogic/client/io/DocumentMetadataHandle.java index 62ce84493..c06f95efc 100644 --- a/src/main/java/com/marklogic/client/io/DocumentMetadataHandle.java +++ b/src/main/java/com/marklogic/client/io/DocumentMetadataHandle.java @@ -659,6 +659,7 @@ private void receiveQualityImpl(Document document) { private void sendMetadataImpl(OutputStream out) { try { XMLOutputFactory factory = XMLOutputFactory.newInstance(); + factory.setProperty("javax.xml.stream.isRepairingNamespaces", true); valueSerializer = null; diff --git a/src/main/java/com/marklogic/client/io/QueryOptionsHandle.java b/src/main/java/com/marklogic/client/io/QueryOptionsHandle.java index 0250a71ba..9a30a9027 100644 --- a/src/main/java/com/marklogic/client/io/QueryOptionsHandle.java +++ b/src/main/java/com/marklogic/client/io/QueryOptionsHandle.java @@ -80,27 +80,24 @@ import com.marklogic.client.io.marker.QueryOptionsWriteHandle; /** - * A QueryOptionsHandle is used to configure query configurations. - * - *

Use a QueryOptionsHandle if you want to use Java to configure and manage - * MarkLogic query configurations, for search, value lookups, and facets.

- * - *

Read an options node from MarkLogic with

- * - *
QueryOptionsHandle handle = QueryOptionsManager.readOptions(name, new QueryOptionsHandle());
- * - *

or construct a fresh empty one (which is not a valid configuration without further building)

- * - *
QueryOptionsHandle handle = new QueryOptionsHandle();
- * - *

Build up options to a handle using fluent setter methods

- * - *
handle.withConstraints(...).withTerm(...).withOperators(...)
- * - *

and constructed items from {@link com.marklogic.client.admin.config.QueryOptionsBuilder}.

- * + * @deprecated Use a JSON or XML + * {@link com.marklogic.client.io.marker.StructureWriteHandle write handle} or + * {@link com.marklogic.client.io.marker.StructureReadHandle read handle} + * implementation instead of this class to write or read + * query options. For instance: + *
{@code
+ *  String opts = new StringBuilder()
+ *      .append("")
+ *      .append(    "true")
+ *      .append("")
+ *      .toString();
+ *  optsMgr.writeOptions("debug", new StringHandle(opts)); }
+ * or + *
{@code
+ *  String opts = "{\"options\":{\"debug\":true}}";
+ *  optsMgr.writeOptions("debug", new StringHandle(opts).withFormat(Format.JSON)); }
*/ -@SuppressWarnings("deprecation") +@Deprecated public final class QueryOptionsHandle extends BaseHandle implements OutputStreamSender, BufferableHandle, diff --git a/src/test/java/com/marklogic/client/test/BinaryDocumentTest.java b/src/test/java/com/marklogic/client/test/BinaryDocumentTest.java index 73373a938..f3c25a7b4 100644 --- a/src/test/java/com/marklogic/client/test/BinaryDocumentTest.java +++ b/src/test/java/com/marklogic/client/test/BinaryDocumentTest.java @@ -41,6 +41,7 @@ public class BinaryDocumentTest { @BeforeClass public static void beforeClass() { Common.connect(); + //System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "debug"); } @AfterClass public static void afterClass() { @@ -80,7 +81,7 @@ public void testReadWrite() throws IOException, XpathException { docMgr.setMetadataCategories(Metadata.PROPERTIES); Document metadataDocument = docMgr.readMetadata(docId, new DOMHandle()).get(); assertXpathEvaluatesTo("image/png","string(/*[local-name()='metadata']/*[local-name()='properties']/*[local-name()='content-type'])", metadataDocument); - assertXpathEvaluatesTo("none","string(/*[local-name()='metadata']/*[local-name()='properties']/*[local-name()='filter-capabilities'])", metadataDocument); + assertXpathEvaluatesTo("text HD-HTML","string(/*[local-name()='metadata']/*[local-name()='properties']/*[local-name()='filter-capabilities'])", metadataDocument); assertXpathEvaluatesTo("815","string(/*[local-name()='metadata']/*[local-name()='properties']/*[local-name()='size'])", metadataDocument); } } diff --git a/src/test/java/com/marklogic/client/test/JSONDocumentTest.java b/src/test/java/com/marklogic/client/test/JSONDocumentTest.java index 8fcafa834..f826d382e 100644 --- a/src/test/java/com/marklogic/client/test/JSONDocumentTest.java +++ b/src/test/java/com/marklogic/client/test/JSONDocumentTest.java @@ -23,8 +23,6 @@ import java.io.IOException; import java.io.Reader; -import javax.xml.XMLConstants; - import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; @@ -40,7 +38,6 @@ import com.marklogic.client.document.DocumentPatchBuilder; import com.marklogic.client.document.DocumentPatchBuilder.Position; import com.marklogic.client.document.JSONDocumentManager; -import com.marklogic.client.document.XMLDocumentManager; import com.marklogic.client.io.BytesHandle; import com.marklogic.client.io.DOMHandle; import com.marklogic.client.io.FileHandle; @@ -91,23 +88,6 @@ public void testReadWrite() throws IOException { File file = docMgr.read(docId, new FileHandle()).get(); readNode = mapper.readTree(file); assertTrue("JSON document mismatch with file", sourceNode.equals(readNode)); - - docMgr.write(docId, - new StringHandle().with(GenericDocumentTest.metadata).withFormat(Format.XML), - new StringHandle().with(content)); - docText = docMgr.read(docId, new StringHandle()).get(); - assertNotNull("Read null string for JSON content",docText); - readNode = mapper.readTree(docText); - assertTrue("Failed to read JSON document as String", sourceNode.equals(readNode)); - - String lang = "fr-CA"; - docMgr.setLanguage(lang); - docMgr.write(docId, new StringHandle().with(content)); - - XMLDocumentManager xmlMgr = Common.client.newXMLDocumentManager(); - Document document = xmlMgr.read(docId, new DOMHandle()).get(); - assertEquals("Failed to set language attribute on JSON", lang, - document.getDocumentElement().getAttributeNS(XMLConstants.XML_NS_URI, "lang")); } @Test diff --git a/src/test/java/com/marklogic/client/test/StructuredQueryBuilderTest.java b/src/test/java/com/marklogic/client/test/StructuredQueryBuilderTest.java index a8c4a4978..5e22dd38c 100644 --- a/src/test/java/com/marklogic/client/test/StructuredQueryBuilderTest.java +++ b/src/test/java/com/marklogic/client/test/StructuredQueryBuilderTest.java @@ -15,12 +15,18 @@ */ package com.marklogic.client.test; +import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; import static org.junit.Assert.assertEquals; +import org.custommonkey.xmlunit.XpathEngine; +import org.custommonkey.xmlunit.SimpleNamespaceContext; +import org.custommonkey.xmlunit.XMLUnit; + import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.HashMap; import javax.xml.XMLConstants; import javax.xml.parsers.ParserConfigurationException; @@ -30,6 +36,7 @@ import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; +import org.junit.BeforeClass; import org.junit.Test; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; @@ -42,6 +49,30 @@ import com.marklogic.client.util.EditableNamespaceContext; public class StructuredQueryBuilderTest { + static private XpathEngine xpather; + + @BeforeClass + public static void beforeClass() { + XMLUnit.setIgnoreAttributeOrder(true); + XMLUnit.setIgnoreWhitespace(true); + XMLUnit.setNormalize(true); + XMLUnit.setNormalizeWhitespace(true); + XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); + + HashMap namespaces = new HashMap(); + namespaces.put("rapi", "http://marklogic.com/rest-api"); + namespaces.put("prop", "http://marklogic.com/xdmp/property"); + namespaces.put("xs", "http://www.w3.org/2001/XMLSchema"); + namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance"); + namespaces.put("search", "http://marklogic.com/appservices/search"); + + + SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(namespaces); + + xpather = XMLUnit.newXpathEngine(); + xpather.setNamespaceContext(namespaceContext); + } + // remove dependency on org.apache.tools.ant.filters.StringInputStream static class StringInputStream extends ByteArrayInputStream { StringInputStream(String input) { @@ -508,7 +539,7 @@ public void testBuilder() throws IOException, SAXException, ParserConfigurationE xml = new StringInputStream(q); parser.parse(xml, handler); - assertEquals( + assertXMLEqual("Geospatial query malformed", "