Patch rundeck API v11 bug for execution query results

This commit is contained in:
Greg Schueler 2014-11-07 15:23:12 -08:00
parent 18ec800264
commit c8e1315612
2 changed files with 51 additions and 3 deletions

View file

@ -1587,13 +1587,26 @@ public class RundeckClient implements Serializable {
.param(new ExecutionQueryParameters(query))
.param("max", max)
.param("offset", offset),
new PagedResultParser<RundeckExecution>(
new ListParser<RundeckExecution>(new ExecutionParser(), "execution"),
rootXpath()+"/executions"
patchApiV11Response(
new PagedResultParser<RundeckExecution>(
new ListParser<RundeckExecution>(new ExecutionParser(), "execution"),
rootXpath() + "/executions"
)
)
);
}
/**
* Fix potential buggy response from Rundeck, where &lt;result&gt; wrapper exists
* even if it should not.
* @param parser
* @return
*/
private XmlNodeParser<PagedResults<RundeckExecution>> patchApiV11Response
(final PagedResultParser<RundeckExecution> parser) {
return new PagedResultParser_BugPatchV11<RundeckExecution>(parser);
}
/**
* Get a single execution, identified by the given ID
*

View file

@ -0,0 +1,35 @@
package org.rundeck.api.parser;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.Node;
import org.rundeck.api.util.PagedResults;
/**
* WRaps a {@link PagedResultParser} to detect whether the result XML incorrectly is wrapped with a
* &lt;result&gt; element.
*
* @author Greg Schueler <greg@simplifyops.com>
* @since 2014-11-07
*/
public class PagedResultParser_BugPatchV11<T> implements XmlNodeParser<PagedResults<T>> {
PagedResultParser<T> parser;
public PagedResultParser_BugPatchV11(final PagedResultParser<T> parser) {
this.parser = parser;
}
@Override public PagedResults<T> parseXmlNode(final Node node) {
Node sourceNode = node;
final Node tested = sourceNode.selectSingleNode(parser.getXpath());
if (null == tested && !parser.getXpath().startsWith("result")) {
//prepend /result
if (null != sourceNode.selectSingleNode("result" + parser.getXpath())) {
sourceNode = sourceNode.selectSingleNode("result" + parser.getXpath());
sourceNode.getParent().remove(sourceNode);
DocumentHelper.createDocument((Element) sourceNode);
}
}
return parser.parseXmlNode(sourceNode);
}
}