jam01 commented on a change in pull request #4561: URL: https://github.com/apache/camel/pull/4561#discussion_r530545935
########## File path: components/camel-datasonnet/src/main/docs/datasonnet-language.adoc ########## @@ -0,0 +1,193 @@ +[[datasonnet-language]] += DataSonnet Language +:docTitle: DataSonnet +:artifactId: camel-datasonnet +:description: To use DataSonnet scripts in Camel expressions or predicates. +:since: 3.7 +:supportLevel: Preview +include::{cq-version}@camel-quarkus:ROOT:partial$reference/languages/datasonnet.adoc[opts=optional] + +*Since Camel {since}* + +Camel supports https://datasonnet.com/[DataSonnet] transformations to allow an Expression or Predicate to be used in the Java DSL or xref:manual::xml-configuration.adoc[XML +Configuration]. + +To use a DataSonnet expression use the following Java code: +[source,java] +--------------------------------------- +... datasonnet("someDSExpression") ... +--------------------------------------- + +== Example + +Here is a simple example using a DataSonnet expression as a predicate in a Message Filter: + +[source,java] +------------------------------------------------------------------------------------------------ +// lets route if a line item is over $100 +from("queue:foo") + .filter(datasonnet("ds.arrays.firstWith(body.lineItems, function(item) item > 100) != null")) + .to("queue:bar") +------------------------------------------------------------------------------------------------ + +And the Spring DSL: + +[source,xml] +----------------------------------------------------------------------------- +<route> + <from uri="queue:foo"/> + <filter> + <datasonnet>ds.arrays.firstWith(body.lineItems, function(item) item > 100) != null</datasonnet> + <to uri="queue:bar"/> + </filter> +</route> +----------------------------------------------------------------------------- + +Here is an example of a simple DataSonnet expression as a transformation EIP. This example will transform an XML body with +`lineItems` into JSON while filtering out lines that are under 100. + +[source,java] +------------------------------------------------------------------------------------------------ +from("queue:foo") + .transform(datasonnet("ds.filter(body.lineItems, function(item) item > 100)", String.class) + .bodyMediaType("application/xml").outputMediaType("application/json") + ) + .to("queue:bar") +------------------------------------------------------------------------------------------------ + +And the Spring DSL: + +[source,xml] +----------------------------------------------------------------------------- +<route> + <from uri="queue:foo"/> + <filter> + <datasonnet bodyMediaType="application/xml" outputMediaType="application/json" resultTypeName="java.lang.String" > + ds.filter(body.lineItems, function(item) item > 100) Review comment: marking as resolved for legibility as stated previously ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org