Apache Camel - EL evaluate element in array - apache-camel

I'm trying to evaluate a value in an array using camel el, but this doesn't work. How can I do to get the evaluation right?
<c:choice>
<c:when>
**<c:el>${ in.body.system.id in [34, 35]}</c:el>**
<c:bean ref="transformUtils" method="removeUser(${in.body}, '99999')"/>
</c:when>
<c:otherwise>
<c:to uri="activemq:queue:systemOk"/>
</c:otherwise>
</c:choice>

If you are using java config use
simple("${in.body.system.id} in [34, 35]")
use this for xml config
<c:simple>${in.body.system.id} in '34,35,36'</c:simple>

Related

Set variable to array in Escape Velocity

I'm trying to set a variable to an array in Escape Velocity like they do in the documentation:
#set ($my = "blah")
#set ($say = ["not", $my, "fault"])
However, I get the following error:
error: An error occurred in the #AutoProtoModel processor while processing com.google.protobuf.contrib.autoprotomodel.prototype.AlbumModel:
com.google.escapevelocity.ParseException: Expected an expression, on line 46, at text starting: ["not", $my, "fault"...
com.google.escapevelocity.Parser.parseException(Parser.java:1093)
com.google.escapevelocity.Parser.parsePrimary(Parser.java:923)
com.google.escapevelocity.Parser.parseUnaryExpression(Parser.java:890)
com.google.escapevelocity.Parser.parseExpression(Parser.java:797)
com.google.escapevelocity.Parser.parseSet(Parser.java:401)
com.google.escapevelocity.Parser.parseDirective(Parser.java:328)
com.google.escapevelocity.Parser.parseNode(Parser.java:218)
com.google.escapevelocity.Parser.parseTokens(Parser.java:126)
com.google.escapevelocity.Parser.parse(Parser.java:118)
com.google.escapevelocity.Template.parseFrom(Template.java:112)
com.google.escapevelocity.Template.parseFrom(Template.java:94)
com.google.protobuf.contrib.autoprotomodel.prototype.BackingClassGenerator.loadTemplate(BackingClassGenerator.java:97)
...
Why doesn't this work?
Is this a bug in the Escape Velocity project?
It seems that Escape Velocity doesn't support to set Java array (from docs):
Unlike Velocity, EscapeVelocity does not allow $indexme to be a Java array.
Why not using Velocity? EscapeVelocity uses old version 1.7 instead of new 2.0, and you have extra tools for velocity
EscapeVelocity is a templating engine that can be used from Java. It is a reimplementation of a subset of functionality from Apache Velocity.
This is not an official Google product.

Get the values from the <xd:doc/>

I want to access the version information which I store in the
<xsl:stylesheet>
<xd:doc scope="stylesheet">
<xd:ul>
<xd:li>
<xd:i>Updates</xd:i>: <xd:ul>
<xd:li>20.11.2018, version: <xd:i>1.1.0</xd:i></xd:li>
<xd:li>08.03.2019, version: <xd:i>2.0.0</xd:i></xd:li>
<xd:li>11.03.2019, version: <xd:i>2.0.1</xd:i></xd:li>
</xd:ul>
</xd:li>
</xd:ul>
</xd:doc>
</xsl:stylesheet>
Normally the XPath of the #select is evaluated to the xml-file which is currently transforming. But how refer XPath to the (main) XSL-stylesheet?
Another option would be to use fn:doc(). But I want to place the version-writing-functionality in an external module, so there will be dynamic file names and I don't know how to get the xsl-file name
I use oXygen XML editor 20.1 where I define the transformation scenarios.
#MartinHonnen Thank you. I updated the code in the question. As you may see I store the version in the docs of the stylesheet.
The document('') / doc('') was what I needed. So I implemented the following:
I put the document-node of the main stylesheet in the variable which is placed in this stylesheet:
<xsl:variable name="currentStylesheet" select="doc('')"/>
then refer to it in the external module
<xsl:variable as="xs:string" name="versionXSLT" select="$currentStylesheet//xd:li[xd:i = 'Updates']/xd:ul/xd:li[last()]/xd:i/string()"/>
I also use it to get the name of the stylesheet:
<xsl:variable as="xs:string" name="currentStylesheetName" select="tokenize(document-uri($currentStylesheet), '/')[last()]"/>
Are there maybe better solutions?

MuleSoft 4 http request

I am new to MuleSoft
when i am giving output expression like below i am getting an data sense error, can you please help
#[output application/json --- {errorType:error.errorType, error:error.description}]
Description Resource Path Location Type Scripting language error on
expression '#[output application/json --- {errorType:error.errorType,
error:error.descrip...'. Reason: Invalid input '#', expected using,
if, ???, unless or not (line 1, column 1): . validations.xml
/validations/src/main/mule Listener Message Flow Error
It is hard to know without a snippet from the configuration XML exactly what your issue is, but one problem I see is that your dataweave does not start with a
"%dw 2.0" In mule 4 there are two languages. Mule Expression language, which is default in most components (ie #[vars.name] is MEL), and dataweave 2.0 which is default in Transform Message components. You can however, as you've attempted to do, use dataweave inside of Mule Expressions. You have it mostly right, but it must start with "%dw 2.0" at the beginning. So it should look like this.
#[%dw 2.0 output application/json --- {errorType:error.errorType, error:error.description}]
However, judging by the error message, it looks like you're attempting to use MEL in a place where it is not allowed. If you provide a snippet of the configuration XML for this component, I can be more helpful.
There is no MEL in Mule 4. It is migrated to DW2.0. Please refer link https://docs.mulesoft.com/mule-runtime/4.2/migration-mel

Apache Camel Stateful Bean

Based on below example , how to make my Add bean as Stateful:
from("direct:firstRoute")
.bean(Add.class)
.bean(Add.class,"setIntA(1)")
.bean(Add.class,"setIntB(1)")
.log("${body}")
.setHeader(SpringWebserviceConstants.SPRING_WS_SOAP_ACTION,simple("http://tempuri.org/Add"))
.to("spring-ws:http://www.dneonline.com/calculator.asmx")
.convertBodyTo(AddResponse.class)
.log("${body}");
That mean first i need to create the bean then Calling the setIntA method then setIntB without loosing the value in each step .

apache camel spring dsl check if body contains string

I am trying to check :
<simple>${body} contains 'verification'</simple>
Body is the json:
{"verification": {"email": "bb#wp.pl", "code": "1234"}}
But this condition doesn't work. I've tried as well:
<simple>${body} contains 'verification'</simple>
<simple>${bodyAs(String)} contains 'verification'</simple>
<simple>${body.verification} != null</simple>
Could you please suggest me something?
I guess the body is maybe not a String, then try with
<simple>${bodyAs(String)} contains 'verification'</simple>
And btw what version of Camel do you use?
Actually this case:
<simple>${bodyAs(String)} contains 'verification'</simple>
didn't work cause:
In Camel the message body can be of any types. Some types are safely readable multiple times, and therefore do not 'suffer' from becoming 'empty'.
It fixes by Stream caching

Resources