CAMEL-10696: Ensure json value is escaped and avoid new line problems in description and in docs.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/481aacfd Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/481aacfd Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/481aacfd Branch: refs/heads/json-simple Commit: 481aacfd2148f8305e76e13d74385d976a7925f9 Parents: d59d7a6 Author: Claus Ibsen <davscl...@apache.org> Authored: Sun Sep 24 15:37:46 2017 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sun Sep 24 15:37:46 2017 +0200 ---------------------------------------------------------------------- camel-core/src/main/docs/test-component.adoc | 2 +- camel-core/src/main/docs/tokenize-language.adoc | 2 +- .../org/apache/camel/component/test/TestEndpoint.java | 2 +- .../apache/camel/model/dataformat/Base64DataFormat.java | 2 +- .../apache/camel/model/dataformat/CsvDataFormat.java | 2 +- .../camel/model/dataformat/FlatpackDataFormat.java | 2 +- .../model/dataformat/UniVocityAbstractDataFormat.java | 2 +- .../model/dataformat/UniVocityFixedWidthDataFormat.java | 2 +- .../camel/model/language/TokenizerExpression.java | 2 +- .../apache/camel/runtimecatalog/JSonSchemaHelper.java | 12 +++++------- .../component/file/remote/RemoteFileConfiguration.java | 4 +--- .../camel/maven/connector/util/JSonSchemaHelper.java | 2 +- .../apache/camel/tools/apt/helper/JsonSchemaHelper.java | 12 +++++------- .../apache/camel/maven/packaging/JSonSchemaHelper.java | 8 +++++++- 14 files changed, 28 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/481aacfd/camel-core/src/main/docs/test-component.adoc ---------------------------------------------------------------------- diff --git a/camel-core/src/main/docs/test-component.adoc b/camel-core/src/main/docs/test-component.adoc index 395d469..dbda46d 100644 --- a/camel-core/src/main/docs/test-component.adoc +++ b/camel-core/src/main/docs/test-component.adoc @@ -89,7 +89,7 @@ with the following path and query parameters: | *retainFirst* (producer) | Specifies to only retain the first n'th number of received Exchanges. This is used when testing with big data to reduce memory consumption by not storing copies of every Exchange this mock endpoint receives. Important: When using this limitation then the link getReceivedCounter() will still return the actual number of received Exchanges. For example if we have received 5000 Exchanges and have configured to only retain the first 10 Exchanges then the link getReceivedCounter() will still return 5000 but there is only the first 10 Exchanges in the link getExchanges() and link getReceivedExchanges() methods. When using this method then some of the other expectation methods is not supported for example the link expectedBodiesReceived(Object...) sets a expectation on the first number of bodies received. You can configure both link setRetainFirst(int) and link setRetainLast(int) methods to limit both the first and last received. | -1 | int | *retainLast* (producer) | Specifies to only retain the last n'th number of received Exchanges. This is used when testing with big data to reduce memory consumption by not storing copies of every Exchange this mock endpoint receives. Important: When using this limitation then the link getReceivedCounter() will still return the actual number of received Exchanges. For example if we have received 5000 Exchanges and have configured to only retain the last 20 Exchanges then the link getReceivedCounter() will still return 5000 but there is only the last 20 Exchanges in the link getExchanges() and link getReceivedExchanges() methods. When using this method then some of the other expectation methods is not supported for example the link expectedBodiesReceived(Object...) sets a expectation on the first number of bodies received. You can configure both link setRetainFirst(int) and link setRetainLast(int) methods to limit both the first and last received. | -1 | int | *sleepForEmptyTest* (producer) | Allows a sleep to be specified to wait to check that this endpoint really is empty when link expectedMessageCount(int) is called with zero | 0 | long -| *split* (producer) | If enabled the the messages loaded from the test endpoint will be split using \n\r delimiters (new lines) so each line is an expected message. For example to use a file endpoint to load a file where each line is an expected message. | false | boolean +| *split* (producer) | If enabled the the messages loaded from the test endpoint will be split using new line delimiters so each line is an expected message. For example to use a file endpoint to load a file where each line is an expected message. | false | boolean | *timeout* (producer) | The timeout to use when polling for message bodies from the URI | 2000 | long | *copyOnExchange* (producer) | Sets whether to make a deep copy of the incoming Exchange when received at this mock endpoint. Is by default true. | true | boolean | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). | false | boolean http://git-wip-us.apache.org/repos/asf/camel/blob/481aacfd/camel-core/src/main/docs/tokenize-language.adoc ---------------------------------------------------------------------- diff --git a/camel-core/src/main/docs/tokenize-language.adoc b/camel-core/src/main/docs/tokenize-language.adoc index b9fe05d..c950282 100644 --- a/camel-core/src/main/docs/tokenize-language.adoc +++ b/camel-core/src/main/docs/tokenize-language.adoc @@ -23,7 +23,7 @@ The Tokenize language supports 10 options which are listed below. [width="100%",cols="2,1m,1m,6",options="header"] |=== | Name | Default | Java Type | Description -| token | | String | The (start) token to use as tokenizer for example \n for a new line token. You can use simple language as the token to support dynamic tokens. +| token | | String | The (start) token to use as tokenizer for example you can use the new line token. You can use simple language as the token to support dynamic tokens. | endToken | | String | The end token to use as tokenizer if using start/end token pairs. You can use simple language as the token to support dynamic tokens. | inheritNamespaceTagName | | String | To inherit namespaces from a root/parent tag name when using XML You can use simple language as the tag name to support dynamic names. | headerName | | String | Name of header to tokenize instead of using the message body. http://git-wip-us.apache.org/repos/asf/camel/blob/481aacfd/camel-core/src/main/java/org/apache/camel/component/test/TestEndpoint.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/test/TestEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/test/TestEndpoint.java index 30fd39e..d86fcd3 100644 --- a/camel-core/src/main/java/org/apache/camel/component/test/TestEndpoint.java +++ b/camel-core/src/main/java/org/apache/camel/component/test/TestEndpoint.java @@ -137,7 +137,7 @@ public class TestEndpoint extends MockEndpoint { } /** - * If enabled the the messages loaded from the test endpoint will be split using \n\r delimiters (new lines) + * If enabled the the messages loaded from the test endpoint will be split using new line delimiters * so each line is an expected message. * <br/> * For example to use a file endpoint to load a file where each line is an expected message. http://git-wip-us.apache.org/repos/asf/camel/blob/481aacfd/camel-core/src/main/java/org/apache/camel/model/dataformat/Base64DataFormat.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/dataformat/Base64DataFormat.java b/camel-core/src/main/java/org/apache/camel/model/dataformat/Base64DataFormat.java index 5b3192b..b081548 100644 --- a/camel-core/src/main/java/org/apache/camel/model/dataformat/Base64DataFormat.java +++ b/camel-core/src/main/java/org/apache/camel/model/dataformat/Base64DataFormat.java @@ -82,7 +82,7 @@ public class Base64DataFormat extends DataFormatDefinition { /** * The line separators to use. * <p/> - * By default \r\n is used. + * Uses new line characters by default. */ public void setLineSeparator(String lineSeparator) { this.lineSeparator = lineSeparator; http://git-wip-us.apache.org/repos/asf/camel/blob/481aacfd/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java b/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java index d47ca7f..254c0e1 100644 --- a/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java +++ b/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java @@ -394,7 +394,7 @@ public class CsvDataFormat extends DataFormatDefinition { } /** - * Sets the record separator (aka new line) which by default is \r\n (CRLF) + * Sets the record separator (aka new line) which by default is new line characters (CRLF) */ public void setRecordSeparator(String recordSeparator) { this.recordSeparator = recordSeparator; http://git-wip-us.apache.org/repos/asf/camel/blob/481aacfd/camel-core/src/main/java/org/apache/camel/model/dataformat/FlatpackDataFormat.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/dataformat/FlatpackDataFormat.java b/camel-core/src/main/java/org/apache/camel/model/dataformat/FlatpackDataFormat.java index 6765ea5..ae80b36 100644 --- a/camel-core/src/main/java/org/apache/camel/model/dataformat/FlatpackDataFormat.java +++ b/camel-core/src/main/java/org/apache/camel/model/dataformat/FlatpackDataFormat.java @@ -109,7 +109,7 @@ public class FlatpackDataFormat extends DataFormatDefinition { } /** - * If the text is qualified with a char such as " + * If the text is qualified with a char such as double quote character */ public void setTextQualifier(String textQualifier) { this.textQualifier = textQualifier; http://git-wip-us.apache.org/repos/asf/camel/blob/481aacfd/camel-core/src/main/java/org/apache/camel/model/dataformat/UniVocityAbstractDataFormat.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/dataformat/UniVocityAbstractDataFormat.java b/camel-core/src/main/java/org/apache/camel/model/dataformat/UniVocityAbstractDataFormat.java index c66cb2e..3fab521 100644 --- a/camel-core/src/main/java/org/apache/camel/model/dataformat/UniVocityAbstractDataFormat.java +++ b/camel-core/src/main/java/org/apache/camel/model/dataformat/UniVocityAbstractDataFormat.java @@ -203,7 +203,7 @@ public abstract class UniVocityAbstractDataFormat extends DataFormatDefinition { /** * The normalized line separator of the files * <p/> - * The default value is \n + * The default value is a new line character. */ public void setNormalizedLineSeparator(String normalizedLineSeparator) { this.normalizedLineSeparator = normalizedLineSeparator; http://git-wip-us.apache.org/repos/asf/camel/blob/481aacfd/camel-core/src/main/java/org/apache/camel/model/dataformat/UniVocityFixedWidthDataFormat.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/dataformat/UniVocityFixedWidthDataFormat.java b/camel-core/src/main/java/org/apache/camel/model/dataformat/UniVocityFixedWidthDataFormat.java index d27d536..45c2bd6 100644 --- a/camel-core/src/main/java/org/apache/camel/model/dataformat/UniVocityFixedWidthDataFormat.java +++ b/camel-core/src/main/java/org/apache/camel/model/dataformat/UniVocityFixedWidthDataFormat.java @@ -36,7 +36,7 @@ public class UniVocityFixedWidthDataFormat extends UniVocityAbstractDataFormat { protected Boolean skipTrailingCharsUntilNewline; @XmlAttribute protected Boolean recordEndsOnNewline; - @XmlAttribute @Metadata(defaultValue = " ") + @XmlAttribute protected String padding; public UniVocityFixedWidthDataFormat() { http://git-wip-us.apache.org/repos/asf/camel/blob/481aacfd/camel-core/src/main/java/org/apache/camel/model/language/TokenizerExpression.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/language/TokenizerExpression.java b/camel-core/src/main/java/org/apache/camel/model/language/TokenizerExpression.java index c197fc7..89287ab 100644 --- a/camel-core/src/main/java/org/apache/camel/model/language/TokenizerExpression.java +++ b/camel-core/src/main/java/org/apache/camel/model/language/TokenizerExpression.java @@ -69,7 +69,7 @@ public class TokenizerExpression extends ExpressionDefinition { } /** - * The (start) token to use as tokenizer, for example \n for a new line token. + * The (start) token to use as tokenizer, for example you can use the new line token. * You can use simple language as the token to support dynamic tokens. */ public void setToken(String token) { http://git-wip-us.apache.org/repos/asf/camel/blob/481aacfd/camel-core/src/main/java/org/apache/camel/runtimecatalog/JSonSchemaHelper.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/runtimecatalog/JSonSchemaHelper.java b/camel-core/src/main/java/org/apache/camel/runtimecatalog/JSonSchemaHelper.java index d0e482d..25b0317 100644 --- a/camel-core/src/main/java/org/apache/camel/runtimecatalog/JSonSchemaHelper.java +++ b/camel-core/src/main/java/org/apache/camel/runtimecatalog/JSonSchemaHelper.java @@ -93,18 +93,16 @@ public final class JSonSchemaHelper { } newValue = csb.toString(); } - answer.put(rowEntry.getKey().toString(), newValue.toString()); + // ensure value is escaped + String value = escapeJson(newValue.toString()); + answer.put(rowEntry.getKey().toString(), value); } return answer; } - private static String decodeJson(String value) { - // json encodes a \ as \\ so we need to decode from \\ back to \ - if ("\\\\".equals(value)) { - value = "\\"; - } - return value; + private static String escapeJson(String value) { + return Jsoner.escape(value); } public static boolean isComponentLenientProperties(List<Map<String, String>> rows) { http://git-wip-us.apache.org/repos/asf/camel/blob/481aacfd/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java index 6e7fb1a..b85a6ec 100644 --- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java +++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java @@ -295,9 +295,7 @@ public abstract class RemoteFileConfiguration extends GenericFileConfiguration { /** * Sets optional site command(s) to be executed after successful login. * <p/> - * Multiple site commands can be separated using a new line character (\n). - * - * @param siteCommand the site command(s). + * Multiple site commands can be separated using a new line character. */ public void setSiteCommand(String siteCommand) { this.siteCommand = siteCommand; http://git-wip-us.apache.org/repos/asf/camel/blob/481aacfd/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/util/JSonSchemaHelper.java ---------------------------------------------------------------------- diff --git a/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/util/JSonSchemaHelper.java b/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/util/JSonSchemaHelper.java index 7babd1c..bd5395e 100644 --- a/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/util/JSonSchemaHelper.java +++ b/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/util/JSonSchemaHelper.java @@ -22,7 +22,7 @@ import java.net.URL; import java.util.Date; import java.util.Set; -import org.apache.camel.org.json.simple.Jsoner; +import org.apache.camel.json.simple.Jsoner; /** * A helper class for <a href="http://json-schema.org/">JSON schema</a>. http://git-wip-us.apache.org/repos/asf/camel/blob/481aacfd/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/JsonSchemaHelper.java ---------------------------------------------------------------------- diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/JsonSchemaHelper.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/JsonSchemaHelper.java index f27f95c..1128581 100644 --- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/JsonSchemaHelper.java +++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/JsonSchemaHelper.java @@ -379,18 +379,16 @@ public final class JsonSchemaHelper { } newValue = csb.toString(); } - answer.put(rowEntry.getKey().toString(), newValue.toString()); + // ensure value is escaped + String value = escapeJson(newValue.toString()); + answer.put(rowEntry.getKey().toString(), value); } return answer; } - private static String decodeJson(String value) { - // json encodes a \ as \\ so we need to decode from \\ back to \ - if ("\\\\".equals(value)) { - value = "\\"; - } - return value; + private static String escapeJson(String value) { + return Jsoner.escape(value); } /** http://git-wip-us.apache.org/repos/asf/camel/blob/481aacfd/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java index feafe5c..309336e 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java @@ -91,12 +91,18 @@ public final class JSonSchemaHelper { } newValue = csb.toString(); } - answer.put(rowEntry.getKey().toString(), newValue.toString()); + // ensure value is escaped + String value = escapeJson(newValue.toString()); + answer.put(rowEntry.getKey().toString(), value); } return answer; } + private static String escapeJson(String value) { + return Jsoner.escape(value); + } + /** * Gets the value with the key in a safe way, eg returning an empty string if there was no value for the key. */