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/8b7c86a5 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8b7c86a5 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8b7c86a5 Branch: refs/heads/json-simple Commit: 8b7c86a54f24e5e0c57107b819961c47372ef880 Parents: 481aacf Author: Claus Ibsen <davscl...@apache.org> Authored: Sun Sep 24 16:06:01 2017 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sun Sep 24 16:27:04 2017 +0200 ---------------------------------------------------------------------- camel-core/src/main/docs/eips/aggregate-eip.adoc | 8 +++----- .../camel/model/dataformat/Base64DataFormat.java | 4 ++-- .../model/dataformat/FlatpackDataFormat.java | 6 ++++-- .../camel/runtimecatalog/JSonSchemaHelper.java | 8 +++++++- .../apache/camel/catalog/JSonSchemaHelper.java | 18 +++++++++++------- .../camel/tools/apt/helper/JsonSchemaHelper.java | 8 +++++++- .../camel/maven/packaging/JSonSchemaHelper.java | 8 +++++++- 7 files changed, 41 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/8b7c86a5/camel-core/src/main/docs/eips/aggregate-eip.adoc ---------------------------------------------------------------------- diff --git a/camel-core/src/main/docs/eips/aggregate-eip.adoc b/camel-core/src/main/docs/eips/aggregate-eip.adoc index cb66b02..59b8866 100644 --- a/camel-core/src/main/docs/eips/aggregate-eip.adoc +++ b/camel-core/src/main/docs/eips/aggregate-eip.adoc @@ -16,7 +16,7 @@ single correlation key into a single message exchange. === Aggregator options // eip options: START -The Aggregate EIP supports 26 options which are listed below: +The Aggregate EIP supports 24 options which are listed below: [width="100%",cols="2,5,^1,2",options="header"] @@ -24,8 +24,8 @@ The Aggregate EIP supports 26 options which are listed below: | Name | Description | Default | Type | *correlationExpression* | *Required* The expression used to calculate the correlation key to use for aggregation. The Exchange which has the same correlation key is aggregated together. If the correlation key could not be evaluated an Exception is thrown. You can disable this by using the ignoreBadCorrelationKeys option. | | NamespaceAware Expression | *completionPredicate* | A Predicate to indicate when an aggregated exchange is complete. If this is not specified and the AggregationStrategy object implements Predicate the aggregationStrategy object will be used as the completionPredicate. | | NamespaceAware Expression -| *completionTimeout* | Time in millis that an aggregated exchange should be inactive before its complete (timeout). This option can be set as either a fixed value or using an Expression which allows you to evaluate a timeout dynamically - will use Long as result. If both are set Camel will fallback to use the fixed value if the Expression result was null or 0. You cannot use this option together with completionInterval only one of the two can be used. By default the timeout checker runs every second you can use the completionTimeoutCheckerInterval option to configure how frequently to run the checker. The timeout is an approximation and there is no guarantee that the a timeout is triggered exactly after the timeout value. It is not recommended to use very low timeout values or checker intervals. | | NamespaceAware Expression -| *completionSize* | Number of messages aggregated before the aggregation is complete. This option can be set as either a fixed value or using an Expression which allows you to evaluate a size dynamically - will use Integer as result. If both are set Camel will fallback to use the fixed value if the Expression result was null or 0. | | NamespaceAware Expression +| *completionTimeout* | Time in millis that an aggregated exchange should be inactive before its complete (timeout). This option can be set as either a fixed value or using an Expression which allows you to evaluate a timeout dynamically - will use Long as result. If both are set Camel will fallback to use the fixed value if the Expression result was null or 0. You cannot use this option together with completionInterval only one of the two can be used. By default the timeout checker runs every second you can use the completionTimeoutCheckerInterval option to configure how frequently to run the checker. The timeout is an approximation and there is no guarantee that the a timeout is triggered exactly after the timeout value. It is not recommended to use very low timeout values or checker intervals. | | Long +| *completionSize* | Number of messages aggregated before the aggregation is complete. This option can be set as either a fixed value or using an Expression which allows you to evaluate a size dynamically - will use Integer as result. If both are set Camel will fallback to use the fixed value if the Expression result was null or 0. | | Integer | *optimisticLockRetryPolicy* | Allows to configure retry settings when using optimistic locking. | | OptimisticLockRetry PolicyDefinition | *parallelProcessing* | When aggregated are completed they are being send out of the aggregator. This option indicates whether or not Camel should use a thread pool with multiple threads for concurrency. If no custom thread pool has been specified then Camel creates a default pool with 10 concurrent threads. | false | Boolean | *optimisticLocking* | Turns on using optimistic locking which requires the aggregationRepository being used is supporting this by implementing org.apache.camel.spi.OptimisticLockingAggregationRepository. | false | Boolean @@ -35,9 +35,7 @@ The Aggregate EIP supports 26 options which are listed below: | *strategyRef* | A reference to lookup the AggregationStrategy in the Registry. Configuring an AggregationStrategy is required and is used to merge the incoming Exchange with the existing already merged exchanges. At first call the oldExchange parameter is null. On subsequent invocations the oldExchange contains the merged exchanges and newExchange is of course the new incoming Exchange. | | String | *strategyMethodName* | This option can be used to explicit declare the method name to use when using POJOs as the AggregationStrategy. | | String | *strategyMethodAllowNull* | If this option is false then the aggregate method is not used for the very first aggregation. If this option is true then null values is used as the oldExchange (at the very first aggregation) when using POJOs as the AggregationStrategy. | false | Boolean -| *completionSize* | Number of messages aggregated before the aggregation is complete. This option can be set as either a fixed value or using an Expression which allows you to evaluate a size dynamically - will use Integer as result. If both are set Camel will fallback to use the fixed value if the Expression result was null or 0. | | Integer | *completionInterval* | A repeating period in millis by which the aggregator will complete all current aggregated exchanges. Camel has a background task which is triggered every period. You cannot use this option together with completionTimeout only one of them can be used. | | Long -| *completionTimeout* | Time in millis that an aggregated exchange should be inactive before its complete (timeout). This option can be set as either a fixed value or using an Expression which allows you to evaluate a timeout dynamically - will use Long as result. If both are set Camel will fallback to use the fixed value if the Expression result was null or 0. You cannot use this option together with completionInterval only one of the two can be used. By default the timeout checker runs every second you can use the completionTimeoutCheckerInterval option to configure how frequently to run the checker. The timeout is an approximation and there is no guarantee that the a timeout is triggered exactly after the timeout value. It is not recommended to use very low timeout values or checker intervals. | | Long | *completionTimeoutChecker Interval* | Interval in millis that is used by the background task that checks for timeouts (org.apache.camel.TimeoutMap). By default the timeout checker runs every second. The timeout is an approximation and there is no guarantee that the a timeout is triggered exactly after the timeout value. It is not recommended to use very low timeout values or checker intervals. | 1000 | Long | *completionFromBatchConsumer* | Enables the batch completion mode where we aggregate from a org.apache.camel.BatchConsumer and aggregate the total number of exchanges the org.apache.camel.BatchConsumer has reported as total by checking the exchange property link org.apache.camel.ExchangeBATCH_COMPLETE when its complete. | false | Boolean | *groupExchanges* | *Deprecated* Enables grouped exchanges so the aggregator will group all aggregated exchanges into a single combined Exchange holding all the aggregated exchanges in a java.util.List. | false | Boolean http://git-wip-us.apache.org/repos/asf/camel/blob/8b7c86a5/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 b081548..d6b2e13 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 @@ -38,7 +38,7 @@ public class Base64DataFormat extends DataFormatDefinition { @XmlAttribute @Metadata(defaultValue = "76") private Integer lineLength; - @XmlAttribute @Metadata(defaultValue = "\\r\\n") + @XmlAttribute private String lineSeparator; @XmlAttribute private Boolean urlSafe; @@ -82,7 +82,7 @@ public class Base64DataFormat extends DataFormatDefinition { /** * The line separators to use. * <p/> - * Uses new line characters by default. + * Uses new line characters (CRLF) by default. */ public void setLineSeparator(String lineSeparator) { this.lineSeparator = lineSeparator; http://git-wip-us.apache.org/repos/asf/camel/blob/8b7c86a5/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 ae80b36..6a71d56 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 @@ -44,7 +44,7 @@ public class FlatpackDataFormat extends DataFormatDefinition { private Boolean fixed; @XmlAttribute @Metadata(defaultValue = "true") private Boolean ignoreFirstRecord; - @XmlAttribute @Metadata(defaultValue = "\"") + @XmlAttribute private String textQualifier; @XmlAttribute @Metadata(defaultValue = ",") private String delimiter; @@ -109,7 +109,9 @@ public class FlatpackDataFormat extends DataFormatDefinition { } /** - * If the text is qualified with a char such as double quote character + * If the text is qualified with a character. + * <p/> + * Uses quote character by default. */ public void setTextQualifier(String textQualifier) { this.textQualifier = textQualifier; http://git-wip-us.apache.org/repos/asf/camel/blob/8b7c86a5/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 25b0317..65a63b6 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 @@ -102,7 +102,13 @@ public final class JSonSchemaHelper { } private static String escapeJson(String value) { - return Jsoner.escape(value); + // need to safe encode \r as \\r so its escaped + // need to safe encode \n as \\n so its escaped + // need to safe encode \t as \\t so its escaped + return value + .replaceAll("\\\\r", "\\\\\\r") + .replaceAll("\\\\n", "\\\\\\n") + .replaceAll("\\\\t", "\\\\\\t"); } public static boolean isComponentLenientProperties(List<Map<String, String>> rows) { http://git-wip-us.apache.org/repos/asf/camel/blob/8b7c86a5/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java ---------------------------------------------------------------------- diff --git a/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java index bec8e27..8fc80ea 100644 --- a/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java +++ b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java @@ -93,18 +93,22 @@ 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) { + // need to safe encode \r as \\r so its escaped + // need to safe encode \n as \\n so its escaped + // need to safe encode \t as \\t so its escaped + return value + .replaceAll("\\\\r", "\\\\\\r") + .replaceAll("\\\\n", "\\\\\\n") + .replaceAll("\\\\t", "\\\\\\t"); } public static boolean isComponentLenientProperties(List<Map<String, String>> rows) { http://git-wip-us.apache.org/repos/asf/camel/blob/8b7c86a5/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 1128581..19398d3 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 @@ -388,7 +388,13 @@ public final class JsonSchemaHelper { } private static String escapeJson(String value) { - return Jsoner.escape(value); + // need to safe encode \r as \\r so its escaped + // need to safe encode \n as \\n so its escaped + // need to safe encode \t as \\t so its escaped + return value + .replaceAll("\\\\r", "\\\\\\r") + .replaceAll("\\\\n", "\\\\\\n") + .replaceAll("\\\\t", "\\\\\\t"); } /** http://git-wip-us.apache.org/repos/asf/camel/blob/8b7c86a5/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 309336e..7e537da 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 @@ -100,7 +100,13 @@ public final class JSonSchemaHelper { } private static String escapeJson(String value) { - return Jsoner.escape(value); + // need to safe encode \r as \\r so its escaped + // need to safe encode \n as \\n so its escaped + // need to safe encode \t as \\t so its escaped + return value + .replaceAll("\\\\r", "\\\\\\r") + .replaceAll("\\\\n", "\\\\\\n") + .replaceAll("\\\\t", "\\\\\\t"); } /**