Permalink
Browse files

[bugfix] Executing a query stored in the DB should use DBSource and n…

…ot read the resource into a StringSource
  • Loading branch information...
1 parent 97c6a27 commit 05308ce534c264d112fdb036188866f251300819 @adamretter adamretter committed Nov 17, 2013
Showing with 23 additions and 11 deletions.
  1. +23 −11 src/org/exist/xmlrpc/RpcConnection.java
@@ -1,6 +1,6 @@
/*
* eXist Open Source Native XML Database
- * Copyright (C) 2001-07 The eXist Project
+ * Copyright (C) 2013 The eXist Project
* http://exist-db.org
*
* This program is free software; you can redistribute it and/or
@@ -42,7 +42,6 @@
import org.exist.numbering.NodeId;
import org.exist.protocolhandler.embedded.EmbeddedInputStream;
import org.exist.protocolhandler.xmldb.XmldbURL;
-import org.exist.repo.RepoBackup;
import org.exist.security.ACLPermission;
import org.exist.security.AXSchemaType;
import org.exist.security.Account;
@@ -59,6 +58,7 @@
import org.exist.security.internal.aider.GroupAider;
import org.exist.security.internal.aider.UserAider;
import org.exist.security.xacml.AccessContext;
+import org.exist.source.DBSource;
import org.exist.source.Source;
import org.exist.source.StringSource;
import org.exist.storage.BrokerPool;
@@ -83,7 +83,6 @@
import org.exist.xquery.value.*;
import org.exist.xupdate.Modification;
import org.exist.xupdate.XUpdateProcessor;
-import org.expath.pkg.repo.PackageException;
import org.w3c.dom.DocumentType;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -2923,13 +2922,6 @@ public String query(String xpath, int howmany, int start,
@Override
public HashMap<String, Object> execute(final String pathToQuery, final HashMap<String, Object> parameters) throws EXistException, PermissionDeniedException {
final long startTime = System.currentTimeMillis();
- final byte[] doc = getBinaryResource(XmldbURI.createInternal(pathToQuery), Permission.READ | Permission.EXECUTE);
- String xpath = null;
- try {
- xpath = new String(doc, DEFAULT_ENCODING);
- } catch(final UnsupportedEncodingException e) {
- throw new EXistException("Character encoding issue while reading stored XQuery: " + e.getMessage());
- }
final String sortBy = (String) parameters.get(RpcAPI.SORT_EXPR);
@@ -2939,11 +2931,27 @@ public String query(String xpath, int howmany, int start,
QueryResult queryResult;
Sequence resultSeq = null;
DBBroker broker = null;
+ BinaryDocument xquery = null;
Source source = null;
CompiledXQuery compiled = null;
try {
broker = factory.getBrokerPool().get(user);
- source = new StringSource(xpath);
+
+ xquery = (BinaryDocument)broker.getResource(XmldbURI.createInternal(pathToQuery), Lock.READ_LOCK);
+
+ if(xquery == null) {
+ throw new EXistException("Resource " + pathToQuery + " not found");
+ }
+
+ if(xquery.getResourceType() != DocumentImpl.BINARY_FILE) {
+ throw new EXistException("Document " + pathToQuery + " is not a binary resource");
+ }
+
+ if(!xquery.getPermissions().validate(user, Permission.READ | Permission.EXECUTE)) {
+ throw new PermissionDeniedException("Insufficient privileges to access resource");
+ }
+
+ source = new DBSource(broker, xquery, true);
compiled = compile(broker, source, parameters);
queryResult = doQuery(broker, compiled, nodes, parameters);
if(queryResult == null) {
@@ -3013,6 +3021,10 @@ public String query(String xpath, int howmany, int start,
broker.getXQueryService().getXQueryPool().returnCompiledXQuery(source, compiled);
}
factory.getBrokerPool().release(broker);
+
+ if(xquery != null) {
+ xquery.getUpdateLock().release(Lock.READ_LOCK);
+ }
}
queryResult.result = resultSeq;
queryResult.queryTime = (System.currentTimeMillis() - startTime);

0 comments on commit 05308ce

Please sign in to comment.