SWS-613 - Jaxp13XPathTemplate uses thread-unsafe XPathFactory as field
This commit is contained in:
@@ -41,7 +41,7 @@ import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
* Adapter that supports endpoint methods that use marshalling. Supports methods with the following signature:
|
||||
* Adapter that supports endpoint methods that use XPath expressions. Supports methods with the following signature:
|
||||
* <pre>
|
||||
* void handleMyMessage(@XPathParam("/root/child/text")String param);
|
||||
* </pre>
|
||||
@@ -83,7 +83,7 @@ public class XPathParamAnnotationMethodEndpointAdapter extends AbstractMethodEnd
|
||||
}
|
||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
if (getXPathParamAnnotation(method, i) == null || !isSuportedType(parameterTypes[i])) {
|
||||
if (getXPathParamAnnotation(method, i) == null || !isSupportedType(parameterTypes[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public class XPathParamAnnotationMethodEndpointAdapter extends AbstractMethodEnd
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isSuportedType(Class<?> clazz) {
|
||||
private boolean isSupportedType(Class<?> clazz) {
|
||||
return Boolean.class.isAssignableFrom(clazz) || Boolean.TYPE.isAssignableFrom(clazz) ||
|
||||
Double.class.isAssignableFrom(clazz) || Double.TYPE.isAssignableFrom(clazz) ||
|
||||
Node.class.isAssignableFrom(clazz) || NodeList.class.isAssignableFrom(clazz) ||
|
||||
@@ -151,7 +151,7 @@ public class XPathParamAnnotationMethodEndpointAdapter extends AbstractMethodEnd
|
||||
return args;
|
||||
}
|
||||
|
||||
private XPath createXPath() {
|
||||
private synchronized XPath createXPath() {
|
||||
XPath xpath = xpathFactory.newXPath();
|
||||
if (namespaces != null) {
|
||||
SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext();
|
||||
|
||||
@@ -40,11 +40,7 @@ import org.w3c.dom.NodeList;
|
||||
*/
|
||||
abstract class Jaxp13XPathExpressionFactory {
|
||||
|
||||
private static XPathFactory xpathFactory;
|
||||
|
||||
static {
|
||||
xpathFactory = XPathFactory.newInstance();
|
||||
}
|
||||
private static XPathFactory xpathFactory = XPathFactory.newInstance();
|
||||
|
||||
/**
|
||||
* Creates a JAXP 1.3 <code>XPathExpression</code> from the given string expression.
|
||||
@@ -55,7 +51,7 @@ abstract class Jaxp13XPathExpressionFactory {
|
||||
*/
|
||||
static XPathExpression createXPathExpression(String expression) {
|
||||
try {
|
||||
XPath xpath = xpathFactory.newXPath();
|
||||
XPath xpath = createXPath();
|
||||
javax.xml.xpath.XPathExpression xpathExpression = xpath.compile(expression);
|
||||
return new Jaxp13XPathExpression(xpathExpression);
|
||||
}
|
||||
@@ -75,7 +71,7 @@ abstract class Jaxp13XPathExpressionFactory {
|
||||
*/
|
||||
public static XPathExpression createXPathExpression(String expression, Map<String, String> namespaces) {
|
||||
try {
|
||||
XPath xpath = xpathFactory.newXPath();
|
||||
XPath xpath = createXPath();
|
||||
SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext();
|
||||
namespaceContext.setBindings(namespaces);
|
||||
xpath.setNamespaceContext(namespaceContext);
|
||||
@@ -88,6 +84,11 @@ abstract class Jaxp13XPathExpressionFactory {
|
||||
}
|
||||
}
|
||||
|
||||
private static synchronized XPath createXPath() {
|
||||
return xpathFactory.newXPath();
|
||||
}
|
||||
|
||||
|
||||
/** JAXP 1.3 implementation of the <code>XPathExpression</code> interface. */
|
||||
private static class Jaxp13XPathExpression implements XPathExpression {
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ public class Jaxp13XPathTemplate extends AbstractXPathTemplate {
|
||||
}
|
||||
|
||||
private Object evaluate(String expression, Source context, QName returnType) throws XPathException {
|
||||
XPath xpath = xpathFactory.newXPath();
|
||||
XPath xpath = createXPath();
|
||||
if (getNamespaces() != null && !getNamespaces().isEmpty()) {
|
||||
SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext();
|
||||
namespaceContext.setBindings(getNamespaces());
|
||||
@@ -166,4 +166,9 @@ public class Jaxp13XPathTemplate extends AbstractXPathTemplate {
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized XPath createXPath() {
|
||||
return xpathFactory.newXPath();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user