This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 6323fb3  Fixed CS for camel-support
6323fb3 is described below

commit 6323fb3e44fe3e1581c7cbc6bb7d154a22f00239
Author: Andrea Cosentino <anco...@gmail.com>
AuthorDate: Fri Jan 25 08:22:40 2019 +0100

    Fixed CS for camel-support
---
 .../apache/camel/support/BaseSelectorProducer.java |   1 -
 .../support/HeaderFilterStrategyComponent.java     |   1 -
 .../camel/support/PropertyPlaceholdersHelper.java  |   2 +-
 .../processor/DefaultExchangeFormatter.java        |   9 +-
 .../processor/validation/ValidatingProcessor.java  | 706 +++++++++++----------
 .../validation/helper/XMLConverterHelper.java      | 299 +++++----
 6 files changed, 511 insertions(+), 507 deletions(-)

diff --git 
a/camel-support/src/main/java/org/apache/camel/support/BaseSelectorProducer.java
 
b/camel-support/src/main/java/org/apache/camel/support/BaseSelectorProducer.java
index fd1ba87..770c547 100644
--- 
a/camel-support/src/main/java/org/apache/camel/support/BaseSelectorProducer.java
+++ 
b/camel-support/src/main/java/org/apache/camel/support/BaseSelectorProducer.java
@@ -19,7 +19,6 @@ package org.apache.camel.support;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
-import org.apache.camel.support.DefaultProducer;
 
 /**
  * A base class for selector-based producers.
diff --git 
a/camel-support/src/main/java/org/apache/camel/support/HeaderFilterStrategyComponent.java
 
b/camel-support/src/main/java/org/apache/camel/support/HeaderFilterStrategyComponent.java
index 06b82ef..a3d50a1 100644
--- 
a/camel-support/src/main/java/org/apache/camel/support/HeaderFilterStrategyComponent.java
+++ 
b/camel-support/src/main/java/org/apache/camel/support/HeaderFilterStrategyComponent.java
@@ -21,7 +21,6 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.spi.HeaderFilterStrategyAware;
 import org.apache.camel.spi.Metadata;
-import org.apache.camel.support.DefaultComponent;
 
 /**
  * Base class for components to support configuring a {@link 
org.apache.camel.spi.HeaderFilterStrategy}.
diff --git 
a/camel-support/src/main/java/org/apache/camel/support/PropertyPlaceholdersHelper.java
 
b/camel-support/src/main/java/org/apache/camel/support/PropertyPlaceholdersHelper.java
index 63d3728..3f78de3 100644
--- 
a/camel-support/src/main/java/org/apache/camel/support/PropertyPlaceholdersHelper.java
+++ 
b/camel-support/src/main/java/org/apache/camel/support/PropertyPlaceholdersHelper.java
@@ -23,7 +23,7 @@ import org.apache.camel.CamelContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class PropertyPlaceholdersHelper {
+public final class PropertyPlaceholdersHelper {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(PropertyPlaceholdersHelper.class);
 
diff --git 
a/camel-support/src/main/java/org/apache/camel/support/processor/DefaultExchangeFormatter.java
 
b/camel-support/src/main/java/org/apache/camel/support/processor/DefaultExchangeFormatter.java
index 66cfb7a..75ab4c8 100644
--- 
a/camel-support/src/main/java/org/apache/camel/support/processor/DefaultExchangeFormatter.java
+++ 
b/camel-support/src/main/java/org/apache/camel/support/processor/DefaultExchangeFormatter.java
@@ -50,7 +50,8 @@ public class DefaultExchangeFormatter implements 
ExchangeFormatter {
     private boolean showProperties;
     @UriParam(label = "formatting", description = "Show the message headers.")
     private boolean showHeaders;
-    @UriParam(label = "formatting", defaultValue = "true", description = 
"Whether to skip line separators when logging the message body. This allows to 
log the message body in one line, setting this option to false will preserve 
any line separators from the body, which then will log the body as is.")
+    @UriParam(label = "formatting", defaultValue = "true", description = 
"Whether to skip line separators when logging the message body." 
+    + "This allows to log the message body in one line, setting this option to 
false will preserve any line separators from the body, which then will log the 
body as is.")
     private boolean skipBodyLineSeparator = true;
     @UriParam(label = "formatting", defaultValue = "true", description = "Show 
the message body.")
     private boolean showBody = true;
@@ -60,7 +61,8 @@ public class DefaultExchangeFormatter implements 
ExchangeFormatter {
     private boolean showOut;
     @UriParam(label = "formatting", description = "If the exchange has an 
exception, show the exception message (no stacktrace)")
     private boolean showException;
-    @UriParam(label = "formatting", description = "f the exchange has a caught 
exception, show the exception message (no stack trace). A caught exception is 
stored as a property on the exchange (using the key 
org.apache.camel.Exchange#EXCEPTION_CAUGHT and for instance a doCatch can catch 
exceptions.")
+    @UriParam(label = "formatting", description = "f the exchange has a caught 
exception, show the exception message (no stack trace)." 
+    + "A caught exception is stored as a property on the exchange (using the 
key org.apache.camel.Exchange#EXCEPTION_CAUGHT and for instance a doCatch can 
catch exceptions.")
     private boolean showCaughtException;
     @UriParam(label = "formatting", description = "Show the stack trace, if an 
exchange has an exception. Only effective if one of showAll, showException or 
showCaughtException are enabled.")
     private boolean showStackTrace;
@@ -70,7 +72,8 @@ public class DefaultExchangeFormatter implements 
ExchangeFormatter {
     private boolean multiline;
     @UriParam(label = "formatting", description = "If enabled Camel will on 
Future objects wait for it to complete to obtain the payload to be logged.")
     private boolean showFuture;
-    @UriParam(label = "formatting", description = "Whether Camel should show 
stream bodies or not (eg such as java.io.InputStream). Beware if you enable 
this option then you may not be able later to access the message body as the 
stream have already been read by this logger. To remedy this you will have to 
use Stream Caching.")
+    @UriParam(label = "formatting", description = "Whether Camel should show 
stream bodies or not (eg such as java.io.InputStream). Beware if you enable 
this option then " 
+    + "you may not be able later to access the message body as the stream have 
already been read by this logger. To remedy this you will have to use Stream 
Caching.")
     private boolean showStreams;
     @UriParam(label = "formatting", description = "If enabled Camel will 
output files")
     private boolean showFiles;
diff --git 
a/camel-support/src/main/java/org/apache/camel/support/processor/validation/ValidatingProcessor.java
 
b/camel-support/src/main/java/org/apache/camel/support/processor/validation/ValidatingProcessor.java
index 49bb354..da079f9 100644
--- 
a/camel-support/src/main/java/org/apache/camel/support/processor/validation/ValidatingProcessor.java
+++ 
b/camel-support/src/main/java/org/apache/camel/support/processor/validation/ValidatingProcessor.java
@@ -16,8 +16,6 @@
  */
 package org.apache.camel.support.processor.validation;
 
-import static 
org.apache.camel.support.processor.validation.SchemaReader.ACCESS_EXTERNAL_DTD;
-
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -39,6 +37,12 @@ import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
 import javax.xml.validation.Validator;
 
+import org.w3c.dom.Node;
+import org.w3c.dom.ls.LSResourceResolver;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExpectedBodyTypeException;
@@ -47,10 +51,8 @@ import org.apache.camel.TypeConverter;
 import org.apache.camel.support.AsyncProcessorSupport;
 import org.apache.camel.support.processor.validation.helper.XMLConverterHelper;
 import org.apache.camel.util.IOHelper;
-import org.w3c.dom.Node;
-import org.w3c.dom.ls.LSResourceResolver;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
+
+import static 
org.apache.camel.support.processor.validation.SchemaReader.ACCESS_EXTERNAL_DTD;
 
 /**
  * A processor which validates the XML version of the inbound message body
@@ -58,350 +60,352 @@ import org.xml.sax.SAXParseException;
  */
 public class ValidatingProcessor extends AsyncProcessorSupport {
 
-       private final SchemaReader schemaReader;
-       private ValidatorErrorHandler errorHandler = new 
DefaultValidationErrorHandler();
-       private boolean useSharedSchema = true;
-       private boolean failOnNullBody = true;
-       private boolean failOnNullHeader = true;
-       private String headerName;
-       private XMLConverterHelper converter = new XMLConverterHelper();
-
-       public ValidatingProcessor() {
-               schemaReader = new SchemaReader();
-       }
-
-       public ValidatingProcessor(SchemaReader schemaReader) {
-               // schema reader can be a singelton per schema, therefore make 
reuse, see
-               // ValidatorEndpoint and ValidatorProducer
-               this.schemaReader = schemaReader;
-       }
-
-       public boolean process(Exchange exchange, AsyncCallback callback) {
-               try {
-                       doProcess(exchange);
-               } catch (Exception e) {
-                       exchange.setException(e);
-               }
-               callback.done(true);
-               return true;
-       }
-
-       protected void doProcess(Exchange exchange) throws Exception {
-               Schema schema;
-               if (isUseSharedSchema()) {
-                       schema = getSchema();
-               } else {
-                       schema = createSchema();
-               }
-
-               Validator validator = schema.newValidator();
-               // turn off access to external schema by default
-               if 
(!Boolean.parseBoolean(exchange.getContext().getGlobalOptions().get(ACCESS_EXTERNAL_DTD)))
 {
-                       try {
-                               log.debug("Configuring Validator to not allow 
access to external DTD/Schema");
-                               
validator.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
-                               
validator.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
-                       } catch (SAXException e) {
-                               log.warn(e.getMessage(), e);
-                       }
-               }
-
-               // the underlying input stream, which we need to close to avoid 
locking files or
-               // other resources
-               Source source = null;
-               InputStream is = null;
-               try {
-                       Result result = null;
-                       // only convert to input stream if really needed
-                       if (isInputStreamNeeded(exchange)) {
-                               is = getContentToValidate(exchange, 
InputStream.class);
-                               if (is != null) {
-                                       source = getSource(exchange, is);
-                               }
-                       } else {
-                               Object content = getContentToValidate(exchange);
-                               if (content != null) {
-                                       source = getSource(exchange, content);
-                               }
-                       }
-
-                       if (shouldUseHeader()) {
-                               if (source == null && isFailOnNullHeader()) {
-                                       throw new 
NoXmlHeaderValidationException(exchange, headerName);
-                               }
-                       } else {
-                               if (source == null && isFailOnNullBody()) {
-                                       throw new 
NoXmlBodyValidationException(exchange);
-                               }
-                       }
-
-                       // CAMEL-7036 We don't need to set the result if the 
source is an instance of
-                       // StreamSource
-                       if (source instanceof DOMSource) {
-                               result = new DOMResult();
-                       } else if (source instanceof SAXSource) {
-                               result = new SAXResult();
-                       } else if (source instanceof StAXSource || source 
instanceof StreamSource) {
-                               result = null;
-                       }
-
-                       if (source != null) {
-                               // create a new errorHandler and set it on the 
validator
-                               // must be a local instance to avoid problems 
with concurrency (to be
-                               // thread safe)
-                               ValidatorErrorHandler handler = 
errorHandler.getClass().newInstance();
-                               validator.setErrorHandler(handler);
-
-                               try {
-                                       log.trace("Validating {}", source);
-                                       validator.validate(source, result);
-                                       handler.handleErrors(exchange, schema, 
result);
-                               } catch (SAXParseException e) {
-                                       // can be thrown for non well formed XML
-                                       throw new 
SchemaValidationException(exchange, schema, Collections.singletonList(e),
-                                                       
Collections.<SAXParseException>emptyList(), 
Collections.<SAXParseException>emptyList());
-                               }
-                       }
-               } finally {
-                       IOHelper.close(is);
-               }
-       }
-
-       private Object getContentToValidate(Exchange exchange) {
-               if (shouldUseHeader()) {
-                       return exchange.getIn().getHeader(headerName);
-               } else {
-                       return exchange.getIn().getBody();
-               }
-       }
-
-       private <T> T getContentToValidate(Exchange exchange, Class<T> clazz) {
-               if (shouldUseHeader()) {
-                       return exchange.getIn().getHeader(headerName, clazz);
-               } else {
-                       return exchange.getIn().getBody(clazz);
-               }
-       }
-
-       private boolean shouldUseHeader() {
-               return headerName != null;
-       }
-
-       public void loadSchema() throws Exception {
-               schemaReader.loadSchema();
-       }
-
-       // Properties
-       // 
-----------------------------------------------------------------------
-
-       public Schema getSchema() throws IOException, SAXException {
-               return schemaReader.getSchema();
-       }
-
-       public void setSchema(Schema schema) {
-               schemaReader.setSchema(schema);
-       }
-
-       public String getSchemaLanguage() {
-               return schemaReader.getSchemaLanguage();
-       }
-
-       public void setSchemaLanguage(String schemaLanguage) {
-               schemaReader.setSchemaLanguage(schemaLanguage);
-       }
-
-       public Source getSchemaSource() throws IOException {
-               return schemaReader.getSchemaSource();
-       }
-
-       public void setSchemaSource(Source schemaSource) {
-               schemaReader.setSchemaSource(schemaSource);
-       }
-
-       public URL getSchemaUrl() {
-               return schemaReader.getSchemaUrl();
-       }
-
-       public void setSchemaUrl(URL schemaUrl) {
-               schemaReader.setSchemaUrl(schemaUrl);
-       }
-
-       public File getSchemaFile() {
-               return schemaReader.getSchemaFile();
-       }
-
-       public void setSchemaFile(File schemaFile) {
-               schemaReader.setSchemaFile(schemaFile);
-       }
-
-       public byte[] getSchemaAsByteArray() {
-               return schemaReader.getSchemaAsByteArray();
-       }
-
-       public void setSchemaAsByteArray(byte[] schemaAsByteArray) {
-               schemaReader.setSchemaAsByteArray(schemaAsByteArray);
-       }
-
-       public SchemaFactory getSchemaFactory() {
-               return schemaReader.getSchemaFactory();
-       }
-
-       public void setSchemaFactory(SchemaFactory schemaFactory) {
-               schemaReader.setSchemaFactory(schemaFactory);
-       }
-
-       public ValidatorErrorHandler getErrorHandler() {
-               return errorHandler;
-       }
-
-       public void setErrorHandler(ValidatorErrorHandler errorHandler) {
-               this.errorHandler = errorHandler;
-       }
-
-       public boolean isUseSharedSchema() {
-               return useSharedSchema;
-       }
-
-       public void setUseSharedSchema(boolean useSharedSchema) {
-               this.useSharedSchema = useSharedSchema;
-       }
-
-       public LSResourceResolver getResourceResolver() {
-               return schemaReader.getResourceResolver();
-       }
-
-       public void setResourceResolver(LSResourceResolver resourceResolver) {
-               schemaReader.setResourceResolver(resourceResolver);
-       }
-
-       public boolean isFailOnNullBody() {
-               return failOnNullBody;
-       }
-
-       public void setFailOnNullBody(boolean failOnNullBody) {
-               this.failOnNullBody = failOnNullBody;
-       }
-
-       public boolean isFailOnNullHeader() {
-               return failOnNullHeader;
-       }
-
-       public void setFailOnNullHeader(boolean failOnNullHeader) {
-               this.failOnNullHeader = failOnNullHeader;
-       }
-
-       public String getHeaderName() {
-               return headerName;
-       }
-
-       public void setHeaderName(String headerName) {
-               this.headerName = headerName;
-       }
-
-       // Implementation methods
-       // 
-----------------------------------------------------------------------
-
-       protected SchemaFactory createSchemaFactory() {
-               return schemaReader.createSchemaFactory();
-       }
-
-       protected Source createSchemaSource() throws IOException {
-               return schemaReader.createSchemaSource();
-       }
-
-       protected Schema createSchema() throws SAXException, IOException {
-               return schemaReader.createSchema();
-       }
-
-       /**
-        * Checks whether we need an {@link InputStream} to access the message 
body or
-        * header.
-        * <p/>
-        * Depending on the content in the message body or header, we may not 
need to
-        * convert to {@link InputStream}.
-        *
-        * @param exchange
-        *            the current exchange
-        * @return <tt>true</tt> to convert to {@link InputStream} beforehand 
converting
-        *         to {@link Source} afterwards.
-        */
-       protected boolean isInputStreamNeeded(Exchange exchange) {
-               Object content = getContentToValidate(exchange);
-               if (content == null) {
-                       return false;
-               }
-
-               if (content instanceof InputStream) {
-                       return true;
-               } else if (content instanceof Source) {
-                       return false;
-               } else if (content instanceof String) {
-                       return false;
-               } else if (content instanceof byte[]) {
-                       return false;
-               } else if (content instanceof Node) {
-                       return false;
-               } else if 
(exchange.getContext().getTypeConverterRegistry().lookup(Source.class, 
content.getClass()) != null) {
-                       // there is a direct and hopefully optimized converter 
to Source
-                       return false;
-               }
-               // yes an input stream is needed
-               return true;
-       }
-
-       /**
-        * Converts the inbound body or header to a {@link Source}, if it is 
<b>not</b>
-        * already a {@link Source}.
-        * <p/>
-        * This implementation will prefer to source in the following order:
-        * <ul>
-        * <li>DOM - DOM if explicit configured to use DOM</li>
-        * <li>SAX - SAX as 2nd choice</li>
-        * <li>Stream - Stream as 3rd choice</li>
-        * <li>DOM - DOM as 4th choice</li>
-        * </ul>
-        */
-       protected Source getSource(Exchange exchange, Object content) {
-               // body or header may already be a source
-               if (content instanceof Source) {
-                       return (Source) content;
-               }
-               Source source = null;
-               if (content instanceof InputStream) {
-                       return new StreamSource((InputStream) content);
-               }
-               if (content != null) {
-                       TypeConverter tc = 
exchange.getContext().getTypeConverterRegistry().lookup(Source.class,
-                                       content.getClass());
-                       if (tc != null) {
-                               source = tc.convertTo(Source.class, exchange, 
content);
-                       }
-               }
-
-               if (source == null) {
-                       // then try SAX
-                       source = 
exchange.getContext().getTypeConverter().tryConvertTo(SAXSource.class, 
exchange, content);
-               }
-               if (source == null) {
-                       // then try stream
-                       source = 
exchange.getContext().getTypeConverter().tryConvertTo(StreamSource.class, 
exchange, content);
-               }
-               if (source == null) {
-                       // and fallback to DOM
-                       source = 
exchange.getContext().getTypeConverter().tryConvertTo(DOMSource.class, 
exchange, content);
-               }
-               if (source == null) {
-                       if (isFailOnNullBody()) {
-                               throw new ExpectedBodyTypeException(exchange, 
Source.class);
-                       } else {
-                               try {
-                                       source = 
converter.toDOMSource(converter.createDocument());
-                               } catch (ParserConfigurationException | 
TransformerException e) {
-                                       throw new RuntimeTransformException(e);
-                               }
-                       }
-               }
-               return source;
-       }
+    private final SchemaReader schemaReader;
+    private ValidatorErrorHandler errorHandler = new 
DefaultValidationErrorHandler();
+    private boolean useSharedSchema = true;
+    private boolean failOnNullBody = true;
+    private boolean failOnNullHeader = true;
+    private String headerName;
+    private XMLConverterHelper converter = new XMLConverterHelper();
+
+    public ValidatingProcessor() {
+        schemaReader = new SchemaReader();
+    }
+
+    public ValidatingProcessor(SchemaReader schemaReader) {
+        // schema reader can be a singelton per schema, therefore make reuse,
+        // see
+        // ValidatorEndpoint and ValidatorProducer
+        this.schemaReader = schemaReader;
+    }
+
+    public boolean process(Exchange exchange, AsyncCallback callback) {
+        try {
+            doProcess(exchange);
+        } catch (Exception e) {
+            exchange.setException(e);
+        }
+        callback.done(true);
+        return true;
+    }
+
+    protected void doProcess(Exchange exchange) throws Exception {
+        Schema schema;
+        if (isUseSharedSchema()) {
+            schema = getSchema();
+        } else {
+            schema = createSchema();
+        }
+
+        Validator validator = schema.newValidator();
+        // turn off access to external schema by default
+        if 
(!Boolean.parseBoolean(exchange.getContext().getGlobalOptions().get(ACCESS_EXTERNAL_DTD)))
 {
+            try {
+                log.debug("Configuring Validator to not allow access to 
external DTD/Schema");
+                validator.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+                validator.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
+            } catch (SAXException e) {
+                log.warn(e.getMessage(), e);
+            }
+        }
+
+        // the underlying input stream, which we need to close to avoid locking
+        // files or
+        // other resources
+        Source source = null;
+        InputStream is = null;
+        try {
+            Result result = null;
+            // only convert to input stream if really needed
+            if (isInputStreamNeeded(exchange)) {
+                is = getContentToValidate(exchange, InputStream.class);
+                if (is != null) {
+                    source = getSource(exchange, is);
+                }
+            } else {
+                Object content = getContentToValidate(exchange);
+                if (content != null) {
+                    source = getSource(exchange, content);
+                }
+            }
+
+            if (shouldUseHeader()) {
+                if (source == null && isFailOnNullHeader()) {
+                    throw new NoXmlHeaderValidationException(exchange, 
headerName);
+                }
+            } else {
+                if (source == null && isFailOnNullBody()) {
+                    throw new NoXmlBodyValidationException(exchange);
+                }
+            }
+
+            // CAMEL-7036 We don't need to set the result if the source is an
+            // instance of
+            // StreamSource
+            if (source instanceof DOMSource) {
+                result = new DOMResult();
+            } else if (source instanceof SAXSource) {
+                result = new SAXResult();
+            } else if (source instanceof StAXSource || source instanceof 
StreamSource) {
+                result = null;
+            }
+
+            if (source != null) {
+                // create a new errorHandler and set it on the validator
+                // must be a local instance to avoid problems with concurrency
+                // (to be
+                // thread safe)
+                ValidatorErrorHandler handler = 
errorHandler.getClass().newInstance();
+                validator.setErrorHandler(handler);
+
+                try {
+                    log.trace("Validating {}", source);
+                    validator.validate(source, result);
+                    handler.handleErrors(exchange, schema, result);
+                } catch (SAXParseException e) {
+                    // can be thrown for non well formed XML
+                    throw new SchemaValidationException(exchange, schema, 
Collections.singletonList(e), Collections.<SAXParseException> emptyList(),
+                                                        
Collections.<SAXParseException> emptyList());
+                }
+            }
+        } finally {
+            IOHelper.close(is);
+        }
+    }
+
+    private Object getContentToValidate(Exchange exchange) {
+        if (shouldUseHeader()) {
+            return exchange.getIn().getHeader(headerName);
+        } else {
+            return exchange.getIn().getBody();
+        }
+    }
+
+    private <T> T getContentToValidate(Exchange exchange, Class<T> clazz) {
+        if (shouldUseHeader()) {
+            return exchange.getIn().getHeader(headerName, clazz);
+        } else {
+            return exchange.getIn().getBody(clazz);
+        }
+    }
+
+    private boolean shouldUseHeader() {
+        return headerName != null;
+    }
+
+    public void loadSchema() throws Exception {
+        schemaReader.loadSchema();
+    }
+
+    // Properties
+    // -----------------------------------------------------------------------
+
+    public Schema getSchema() throws IOException, SAXException {
+        return schemaReader.getSchema();
+    }
+
+    public void setSchema(Schema schema) {
+        schemaReader.setSchema(schema);
+    }
+
+    public String getSchemaLanguage() {
+        return schemaReader.getSchemaLanguage();
+    }
+
+    public void setSchemaLanguage(String schemaLanguage) {
+        schemaReader.setSchemaLanguage(schemaLanguage);
+    }
+
+    public Source getSchemaSource() throws IOException {
+        return schemaReader.getSchemaSource();
+    }
+
+    public void setSchemaSource(Source schemaSource) {
+        schemaReader.setSchemaSource(schemaSource);
+    }
+
+    public URL getSchemaUrl() {
+        return schemaReader.getSchemaUrl();
+    }
+
+    public void setSchemaUrl(URL schemaUrl) {
+        schemaReader.setSchemaUrl(schemaUrl);
+    }
+
+    public File getSchemaFile() {
+        return schemaReader.getSchemaFile();
+    }
+
+    public void setSchemaFile(File schemaFile) {
+        schemaReader.setSchemaFile(schemaFile);
+    }
+
+    public byte[] getSchemaAsByteArray() {
+        return schemaReader.getSchemaAsByteArray();
+    }
+
+    public void setSchemaAsByteArray(byte[] schemaAsByteArray) {
+        schemaReader.setSchemaAsByteArray(schemaAsByteArray);
+    }
+
+    public SchemaFactory getSchemaFactory() {
+        return schemaReader.getSchemaFactory();
+    }
+
+    public void setSchemaFactory(SchemaFactory schemaFactory) {
+        schemaReader.setSchemaFactory(schemaFactory);
+    }
+
+    public ValidatorErrorHandler getErrorHandler() {
+        return errorHandler;
+    }
+
+    public void setErrorHandler(ValidatorErrorHandler errorHandler) {
+        this.errorHandler = errorHandler;
+    }
+
+    public boolean isUseSharedSchema() {
+        return useSharedSchema;
+    }
+
+    public void setUseSharedSchema(boolean useSharedSchema) {
+        this.useSharedSchema = useSharedSchema;
+    }
+
+    public LSResourceResolver getResourceResolver() {
+        return schemaReader.getResourceResolver();
+    }
+
+    public void setResourceResolver(LSResourceResolver resourceResolver) {
+        schemaReader.setResourceResolver(resourceResolver);
+    }
+
+    public boolean isFailOnNullBody() {
+        return failOnNullBody;
+    }
+
+    public void setFailOnNullBody(boolean failOnNullBody) {
+        this.failOnNullBody = failOnNullBody;
+    }
+
+    public boolean isFailOnNullHeader() {
+        return failOnNullHeader;
+    }
+
+    public void setFailOnNullHeader(boolean failOnNullHeader) {
+        this.failOnNullHeader = failOnNullHeader;
+    }
+
+    public String getHeaderName() {
+        return headerName;
+    }
+
+    public void setHeaderName(String headerName) {
+        this.headerName = headerName;
+    }
+
+    // Implementation methods
+    // -----------------------------------------------------------------------
+
+    protected SchemaFactory createSchemaFactory() {
+        return schemaReader.createSchemaFactory();
+    }
+
+    protected Source createSchemaSource() throws IOException {
+        return schemaReader.createSchemaSource();
+    }
+
+    protected Schema createSchema() throws SAXException, IOException {
+        return schemaReader.createSchema();
+    }
+
+    /**
+     * Checks whether we need an {@link InputStream} to access the message body
+     * or header.
+     * <p/>
+     * Depending on the content in the message body or header, we may not need
+     * to convert to {@link InputStream}.
+     *
+     * @param exchange the current exchange
+     * @return <tt>true</tt> to convert to {@link InputStream} beforehand
+     *         converting to {@link Source} afterwards.
+     */
+    protected boolean isInputStreamNeeded(Exchange exchange) {
+        Object content = getContentToValidate(exchange);
+        if (content == null) {
+            return false;
+        }
+
+        if (content instanceof InputStream) {
+            return true;
+        } else if (content instanceof Source) {
+            return false;
+        } else if (content instanceof String) {
+            return false;
+        } else if (content instanceof byte[]) {
+            return false;
+        } else if (content instanceof Node) {
+            return false;
+        } else if 
(exchange.getContext().getTypeConverterRegistry().lookup(Source.class, 
content.getClass()) != null) {
+            // there is a direct and hopefully optimized converter to Source
+            return false;
+        }
+        // yes an input stream is needed
+        return true;
+    }
+
+    /**
+     * Converts the inbound body or header to a {@link Source}, if it is
+     * <b>not</b> already a {@link Source}.
+     * <p/>
+     * This implementation will prefer to source in the following order:
+     * <ul>
+     * <li>DOM - DOM if explicit configured to use DOM</li>
+     * <li>SAX - SAX as 2nd choice</li>
+     * <li>Stream - Stream as 3rd choice</li>
+     * <li>DOM - DOM as 4th choice</li>
+     * </ul>
+     */
+    protected Source getSource(Exchange exchange, Object content) {
+        // body or header may already be a source
+        if (content instanceof Source) {
+            return (Source)content;
+        }
+        Source source = null;
+        if (content instanceof InputStream) {
+            return new StreamSource((InputStream)content);
+        }
+        if (content != null) {
+            TypeConverter tc = 
exchange.getContext().getTypeConverterRegistry().lookup(Source.class, 
content.getClass());
+            if (tc != null) {
+                source = tc.convertTo(Source.class, exchange, content);
+            }
+        }
+
+        if (source == null) {
+            // then try SAX
+            source = 
exchange.getContext().getTypeConverter().tryConvertTo(SAXSource.class, 
exchange, content);
+        }
+        if (source == null) {
+            // then try stream
+            source = 
exchange.getContext().getTypeConverter().tryConvertTo(StreamSource.class, 
exchange, content);
+        }
+        if (source == null) {
+            // and fallback to DOM
+            source = 
exchange.getContext().getTypeConverter().tryConvertTo(DOMSource.class, 
exchange, content);
+        }
+        if (source == null) {
+            if (isFailOnNullBody()) {
+                throw new ExpectedBodyTypeException(exchange, Source.class);
+            } else {
+                try {
+                    source = converter.toDOMSource(converter.createDocument());
+                } catch (ParserConfigurationException | TransformerException 
e) {
+                    throw new RuntimeTransformException(e);
+                }
+            }
+        }
+        return source;
+    }
 
 }
diff --git 
a/camel-support/src/main/java/org/apache/camel/support/processor/validation/helper/XMLConverterHelper.java
 
b/camel-support/src/main/java/org/apache/camel/support/processor/validation/helper/XMLConverterHelper.java
index b69793c..fc8d3cf 100644
--- 
a/camel-support/src/main/java/org/apache/camel/support/processor/validation/helper/XMLConverterHelper.java
+++ 
b/camel-support/src/main/java/org/apache/camel/support/processor/validation/helper/XMLConverterHelper.java
@@ -28,27 +28,28 @@ import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.dom.DOMSource;
 
-import org.apache.camel.support.processor.validation.ValidatingProcessor;
-import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.StringHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
+
 import org.xml.sax.ErrorHandler;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
 
-public class XMLConverterHelper {
+import org.apache.camel.support.processor.validation.ValidatingProcessor;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.StringHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-       private static final ErrorHandler 
DOCUMENT_BUILDER_LOGGING_ERROR_HANDLER = new 
DocumentBuilderLoggingErrorHandler();
-       private static final String DOCUMENT_BUILDER_FACTORY_FEATURE = 
"org.apache.camel.xmlconverter.documentBuilderFactory.feature";
+public class XMLConverterHelper {
+    
+    private static final Logger LOG = 
LoggerFactory.getLogger(ValidatingProcessor.class);
+    private static final ErrorHandler DOCUMENT_BUILDER_LOGGING_ERROR_HANDLER = 
new DocumentBuilderLoggingErrorHandler();
+    private static final String DOCUMENT_BUILDER_FACTORY_FEATURE = 
"org.apache.camel.xmlconverter.documentBuilderFactory.feature";
 
-       private volatile DocumentBuilderFactory documentBuilderFactory;
+    private volatile DocumentBuilderFactory documentBuilderFactory;
 
-       private static final Logger LOG = 
LoggerFactory.getLogger(ValidatingProcessor.class);
-       
     public XMLConverterHelper() {
     }
 
@@ -56,143 +57,141 @@ public class XMLConverterHelper {
         this.documentBuilderFactory = documentBuilderFactory;
     }
 
-       public Document toDOMDocument(final Node node) throws 
ParserConfigurationException, TransformerException {
-               ObjectHelper.notNull(node, "node");
-
-               // If the node is the document, just cast it
-               if (node instanceof Document) {
-                       return (Document) node;
-                       // If the node is an element
-               } else if (node instanceof Element) {
-                       Element elem = (Element) node;
-                       // If this is the root element, return its owner 
document
-                       if (elem.getOwnerDocument().getDocumentElement() == 
elem) {
-                               return elem.getOwnerDocument();
-                               // else, create a new doc and copy the element 
inside it
-                       } else {
-                               Document doc = createDocument();
-                               // import node must not occur concurrent on the 
same node (must be its owner)
-                               // so we need to synchronize on it
-                               synchronized (node.getOwnerDocument()) {
-                                       doc.appendChild(doc.importNode(node, 
true));
-                               }
-                               return doc;
-                       }
-                       // other element types are not handled
-               } else {
-                       throw new TransformerException("Unable to convert DOM 
node to a Document: " + node);
-               }
-       }
-
-       public DOMSource toDOMSource(Node node) throws 
ParserConfigurationException, TransformerException {
-               Document document = toDOMDocument(node);
-               return new DOMSource(document);
-       }
-
-       public DocumentBuilderFactory createDocumentBuilderFactory() {
-               DocumentBuilderFactory factory = 
DocumentBuilderFactory.newInstance();
-               factory.setNamespaceAware(true);
-               factory.setIgnoringElementContentWhitespace(true);
-               factory.setIgnoringComments(true);
-               try {
-                       // Set secure processing
-                       
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
-               } catch (ParserConfigurationException e) {
-                       LOG.warn("DocumentBuilderFactory doesn't support the 
feature {} with value {}, due to {}.",
-                                       new Object[] { 
XMLConstants.FEATURE_SECURE_PROCESSING, true, e });
-               }
-               try {
-                       // Disable the external-general-entities by default
-                       
factory.setFeature("http://xml.org/sax/features/external-general-entities";, 
false);
-               } catch (ParserConfigurationException e) {
-                       LOG.warn("DocumentBuilderFactory doesn't support the 
feature {} with value {}, due to {}.",
-                                       new Object[] { 
"http://xml.org/sax/features/external-general-entities";, false, e });
-               }
-               // setup the SecurityManager by default if it's apache xerces
-               try {
-                       Class<?> smClass = 
ObjectHelper.loadClass("org.apache.xerces.util.SecurityManager");
-                       if (smClass != null) {
-                               Object sm = smClass.newInstance();
-                               // Here we just use the default setting of the 
SeurityManager
-                               
factory.setAttribute("http://apache.org/xml/properties/security-manager";, sm);
-                       }
-               } catch (Exception e) {
-                       LOG.warn("DocumentBuilderFactory doesn't support the 
attribute {}, due to {}.",
-                                       new Object[] { 
"http://apache.org/xml/properties/security-manager";, e });
-               }
-               // setup the feature from the system property
-               setupFeatures(factory);
-               return factory;
-       }
-
-       public Document createDocument() throws ParserConfigurationException {
-               DocumentBuilder builder = createDocumentBuilder();
-               return builder.newDocument();
-       }
-
-       public DocumentBuilder createDocumentBuilder() throws 
ParserConfigurationException {
-               return createDocumentBuilder(getDocumentBuilderFactory());
-       }
-
-       public DocumentBuilderFactory getDocumentBuilderFactory() {
-               if (documentBuilderFactory == null) {
-                       documentBuilderFactory = createDocumentBuilderFactory();
-               }
-               return documentBuilderFactory;
-       }
-
-       public DocumentBuilder createDocumentBuilder(DocumentBuilderFactory 
factory) throws ParserConfigurationException {
-               DocumentBuilder builder = factory.newDocumentBuilder();
-               builder.setErrorHandler(DOCUMENT_BUILDER_LOGGING_ERROR_HANDLER);
-               return builder;
-       }
-
-       protected void setupFeatures(DocumentBuilderFactory factory) {
-               Properties properties = System.getProperties();
-               List<String> features = new ArrayList<>();
-               for (Map.Entry<Object, Object> prop : properties.entrySet()) {
-                       String key = (String) prop.getKey();
-                       if (key.startsWith(DOCUMENT_BUILDER_FACTORY_FEATURE)) {
-                               String uri = StringHelper.after(key, ":");
-                               Boolean value = Boolean.valueOf((String) 
prop.getValue());
-                               try {
-                                       factory.setFeature(uri, value);
-                                       features.add("feature " + uri + " value 
" + value);
-                               } catch (ParserConfigurationException e) {
-                                       LOG.warn("DocumentBuilderFactory 
doesn't support the feature {} with value {}, due to {}.", uri,
-                                                       value, e);
-                               }
-                       }
-               }
-               if (features.size() > 0) {
-                       StringBuilder featureString = new StringBuilder();
-                       // just log the configured feature
-                       for (String feature : features) {
-                               if (featureString.length() != 0) {
-                                       featureString.append(", ");
-                               }
-                               featureString.append(feature);
-                       }
-                       LOG.info("DocumentBuilderFactory has been set with 
features {{}}.", featureString);
-               }
-
-       }
-
-       private static class DocumentBuilderLoggingErrorHandler implements 
ErrorHandler {
-
-               @Override
-               public void warning(SAXParseException exception) throws 
SAXException {
-                       LOG.warn(exception.getMessage(), exception);
-               }
-
-               @Override
-               public void error(SAXParseException exception) throws 
SAXException {
-                       LOG.error(exception.getMessage(), exception);
-               }
-
-               @Override
-               public void fatalError(SAXParseException exception) throws 
SAXException {
-                       LOG.error(exception.getMessage(), exception);
-               }
-       }
+    public Document toDOMDocument(final Node node) throws 
ParserConfigurationException, TransformerException {
+        ObjectHelper.notNull(node, "node");
+
+        // If the node is the document, just cast it
+        if (node instanceof Document) {
+            return (Document)node;
+            // If the node is an element
+        } else if (node instanceof Element) {
+            Element elem = (Element)node;
+            // If this is the root element, return its owner document
+            if (elem.getOwnerDocument().getDocumentElement() == elem) {
+                return elem.getOwnerDocument();
+                // else, create a new doc and copy the element inside it
+            } else {
+                Document doc = createDocument();
+                // import node must not occur concurrent on the same node (must
+                // be its owner)
+                // so we need to synchronize on it
+                synchronized (node.getOwnerDocument()) {
+                    doc.appendChild(doc.importNode(node, true));
+                }
+                return doc;
+            }
+            // other element types are not handled
+        } else {
+            throw new TransformerException("Unable to convert DOM node to a 
Document: " + node);
+        }
+    }
+
+    public DOMSource toDOMSource(Node node) throws 
ParserConfigurationException, TransformerException {
+        Document document = toDOMDocument(node);
+        return new DOMSource(document);
+    }
+
+    public DocumentBuilderFactory createDocumentBuilderFactory() {
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        factory.setNamespaceAware(true);
+        factory.setIgnoringElementContentWhitespace(true);
+        factory.setIgnoringComments(true);
+        try {
+            // Set secure processing
+            factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, 
Boolean.TRUE);
+        } catch (ParserConfigurationException e) {
+            LOG.warn("DocumentBuilderFactory doesn't support the feature {} 
with value {}, due to {}.", new Object[] 
{XMLConstants.FEATURE_SECURE_PROCESSING, true, e});
+        }
+        try {
+            // Disable the external-general-entities by default
+            
factory.setFeature("http://xml.org/sax/features/external-general-entities";, 
false);
+        } catch (ParserConfigurationException e) {
+            LOG.warn("DocumentBuilderFactory doesn't support the feature {} 
with value {}, due to {}.",
+                     new Object[] 
{"http://xml.org/sax/features/external-general-entities";, false, e});
+        }
+        // setup the SecurityManager by default if it's apache xerces
+        try {
+            Class<?> smClass = 
ObjectHelper.loadClass("org.apache.xerces.util.SecurityManager");
+            if (smClass != null) {
+                Object sm = smClass.newInstance();
+                // Here we just use the default setting of the SeurityManager
+                
factory.setAttribute("http://apache.org/xml/properties/security-manager";, sm);
+            }
+        } catch (Exception e) {
+            LOG.warn("DocumentBuilderFactory doesn't support the attribute {}, 
due to {}.", new Object[] {"http://apache.org/xml/properties/security-manager";, 
e});
+        }
+        // setup the feature from the system property
+        setupFeatures(factory);
+        return factory;
+    }
+
+    public Document createDocument() throws ParserConfigurationException {
+        DocumentBuilder builder = createDocumentBuilder();
+        return builder.newDocument();
+    }
+
+    public DocumentBuilder createDocumentBuilder() throws 
ParserConfigurationException {
+        return createDocumentBuilder(getDocumentBuilderFactory());
+    }
+
+    public DocumentBuilderFactory getDocumentBuilderFactory() {
+        if (documentBuilderFactory == null) {
+            documentBuilderFactory = createDocumentBuilderFactory();
+        }
+        return documentBuilderFactory;
+    }
+
+    public DocumentBuilder createDocumentBuilder(DocumentBuilderFactory 
factory) throws ParserConfigurationException {
+        DocumentBuilder builder = factory.newDocumentBuilder();
+        builder.setErrorHandler(DOCUMENT_BUILDER_LOGGING_ERROR_HANDLER);
+        return builder;
+    }
+
+    protected void setupFeatures(DocumentBuilderFactory factory) {
+        Properties properties = System.getProperties();
+        List<String> features = new ArrayList<>();
+        for (Map.Entry<Object, Object> prop : properties.entrySet()) {
+            String key = (String)prop.getKey();
+            if (key.startsWith(DOCUMENT_BUILDER_FACTORY_FEATURE)) {
+                String uri = StringHelper.after(key, ":");
+                Boolean value = Boolean.valueOf((String)prop.getValue());
+                try {
+                    factory.setFeature(uri, value);
+                    features.add("feature " + uri + " value " + value);
+                } catch (ParserConfigurationException e) {
+                    LOG.warn("DocumentBuilderFactory doesn't support the 
feature {} with value {}, due to {}.", uri, value, e);
+                }
+            }
+        }
+        if (features.size() > 0) {
+            StringBuilder featureString = new StringBuilder();
+            // just log the configured feature
+            for (String feature : features) {
+                if (featureString.length() != 0) {
+                    featureString.append(", ");
+                }
+                featureString.append(feature);
+            }
+            LOG.info("DocumentBuilderFactory has been set with features 
{{}}.", featureString);
+        }
+
+    }
+
+    private static class DocumentBuilderLoggingErrorHandler implements 
ErrorHandler {
+
+        @Override
+        public void warning(SAXParseException exception) throws SAXException {
+            LOG.warn(exception.getMessage(), exception);
+        }
+
+        @Override
+        public void error(SAXParseException exception) throws SAXException {
+            LOG.error(exception.getMessage(), exception);
+        }
+
+        @Override
+        public void fatalError(SAXParseException exception) throws 
SAXException {
+            LOG.error(exception.getMessage(), exception);
+        }
+    }
 }

Reply via email to