You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/08/19 09:45:29 UTC
[3/3] git commit: CAMEL-7721 Support to setup the SaxParserFactory
from the exchange property
CAMEL-7721 Support to setup the SaxParserFactory from the exchange property
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2cdff24b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2cdff24b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2cdff24b
Branch: refs/heads/master
Commit: 2cdff24bb8ebafedc540fdde7b39bafcd55db8aa
Parents: 7e346f9
Author: Willem Jiang <wi...@gmail.com>
Authored: Tue Aug 19 15:44:58 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Tue Aug 19 15:44:58 2014 +0800
----------------------------------------------------------------------
.../main/java/org/apache/camel/Exchange.java | 4 ++-
.../camel/converter/jaxp/XmlConverter.java | 29 +++++++++++++++-----
2 files changed, 25 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/2cdff24b/camel-core/src/main/java/org/apache/camel/Exchange.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/Exchange.java b/camel-core/src/main/java/org/apache/camel/Exchange.java
index 642e9a4..587f17d 100644
--- a/camel-core/src/main/java/org/apache/camel/Exchange.java
+++ b/camel-core/src/main/java/org/apache/camel/Exchange.java
@@ -167,7 +167,7 @@ public interface Exchange {
String OVERRULE_FILE_NAME = "CamelOverruleFileName";
String PARENT_UNIT_OF_WORK = "CamelParentUnitOfWork";
-
+
String RECIPIENT_LIST_ENDPOINT = "CamelRecipientListEndpoint";
String RECEIVED_TIMESTAMP = "CamelReceivedTimestamp";
String REDELIVERED = "CamelRedelivered";
@@ -178,6 +178,8 @@ public interface Exchange {
String ROLLBACK_ONLY = "CamelRollbackOnly";
String ROLLBACK_ONLY_LAST = "CamelRollbackOnlyLast";
String ROUTE_STOP = "CamelRouteStop";
+
+ String SAXPARSER_FACTORY = "CamelSAXParserFactory";
String SOAP_ACTION = "CamelSoapAction";
String SKIP_GZIP_ENCODING = "CamelSkipGzipEncoding";
http://git-wip-us.apache.org/repos/asf/camel/blob/2cdff24b/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java b/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
index 2f066a0..cdef86c 100644
--- a/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
+++ b/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
@@ -469,7 +469,7 @@ public class XmlConverter {
} else if (source instanceof DOMSource) {
return toSAXSourceFromDOM((DOMSource) source, exchange);
} else if (source instanceof StreamSource) {
- return toSAXSourceFromStream((StreamSource) source);
+ return toSAXSourceFromStream((StreamSource) source, exchange);
} else if (source instanceof StAXSource) {
return toSAXSourceFromStAX((StAXSource) source, exchange);
} else {
@@ -569,8 +569,16 @@ public class XmlConverter {
return new StringSource(result);
}
- @Converter
+ /**
+ * @deprecated will be removed in Camel 3.0. Use the method which has 2 parameters.
+ */
+ @Deprecated
public SAXSource toSAXSourceFromStream(StreamSource source) throws SAXException {
+ return toSAXSourceFromStream(source, (Exchange) null);
+ }
+
+ @Converter
+ public SAXSource toSAXSourceFromStream(StreamSource source, Exchange exchange) throws SAXException {
InputSource inputSource;
if (source.getReader() != null) {
inputSource = new InputSource(source.getReader());
@@ -580,13 +588,20 @@ public class XmlConverter {
inputSource.setSystemId(source.getSystemId());
inputSource.setPublicId(source.getPublicId());
XMLReader xmlReader = null;
+ SAXParserFactory sfactory = null;
//Need to setup XMLReader security feature by default
try {
- SAXParserFactory sfactory = SAXParserFactory.newInstance();
- try {
- sfactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
- } catch (Exception e) {
- LOG.warn("SAXParser doesn't support the feature {} with value {}, due to {}.", new Object[]{javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, "true", e});
+ // use the SAXPaserFactory which is set from exchange
+ if (exchange != null) {
+ sfactory = exchange.getProperty(Exchange.SAXPARSER_FACTORY, SAXParserFactory.class);
+ }
+ if (sfactory == null) {
+ sfactory = SAXParserFactory.newInstance();
+ try {
+ sfactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ } catch (Exception e) {
+ LOG.warn("SAXParser doesn't support the feature {} with value {}, due to {}.", new Object[]{javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, "true", e});
+ }
}
SAXParser parser = sfactory.newSAXParser();
xmlReader = parser.getXMLReader();