Skip to content

Commit

Permalink
Merge pull request #2084 from malakaganga/fix_resolver
Browse files Browse the repository at this point in the history
Remove msgCtx in Resolvers after the XPath2.0 evaluation
  • Loading branch information
malakaganga authored Jul 12, 2023
2 parents fe943a4 + 0326b60 commit 728985f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ public Object resolveVariable(QName variable) {
throw new SynapseException("DOM Synapse XPATH variable resolution failed",e);
}
}

public void setSynCtx(MessageContext synCtx) {
this.synCtx = synCtx;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ public GetPropertyFunctionResolver(MessageContext synCtx) {
}

public XPathFunction resolveFunction(QName functionName, int arity) {

if (SynapseXPathConstants.GET_PROPERTY_FUNCTION.equals(functionName.getLocalPart())) {
return new GetPropertyFunction(synCtx);
}
return null;
}

public void setSynCtx(MessageContext synCtx) {
this.synCtx = synCtx;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -670,12 +670,19 @@ public synchronized String evaluateDOMXPath(MessageContext synCtx) throws XPathE
doomElement = convertToDOOM(element);
}
domXpath.setNamespaceContext(domNamespaceMap);
domXpath.setXPathFunctionResolver(new GetPropertyFunctionResolver(synCtx));
domXpath.setXPathVariableResolver(new DOMSynapseXPathVariableResolver(this.getVariableContext(), synCtx));
GetPropertyFunctionResolver getPropertyFunctionResolver = new GetPropertyFunctionResolver(synCtx);
DOMSynapseXPathVariableResolver domSynapseXPathVariableResolver =
new DOMSynapseXPathVariableResolver(this.getVariableContext(), synCtx);
domXpath.setXPathFunctionResolver(getPropertyFunctionResolver);
domXpath.setXPathVariableResolver(domSynapseXPathVariableResolver);
/* Compile the original expression again with Saxon to be evaluated with XPath 2.0 */
XPathExpression expr = domXpath.compile(getExpression());
Object result = expr.evaluate(doomElement);

// Set message contexts in resolvers to null to avoid memory leaks. Resolvers are initialized for each evaluation
domSynapseXPathVariableResolver.setSynCtx(null);
getPropertyFunctionResolver.setSynCtx(null);

if (result != null) {
return result.toString();
}
Expand Down

0 comments on commit 728985f

Please sign in to comment.