Is there a Mule 4/Dataweave 2 equivalent for dw:input-variable in a transform message - mule-component

I'm trying to manually translate a program from Mule 3 to Mule 4, and a lot of the transforms have something like
<dw:input-variable doc:sample="sample_data\json_63.json" variableName="dsRespPayloads"/>
I don't know what the equivalent is in Mule 4 or if there is one. This is leading me to a problem where a flow defines a variable calls another flow, and in that second flow it tries to transform the message using the variable defined in the first.
In Mule 4 it keeps saying Property: dsRespPayloads was not found.
and it's giving me errors over it. Also the tree on the left just says Unknown for Payload and Attributes
Any help or explanation about what's going on would be appreciated.

Are you saying you define a variable in flowOne and in the flowTwo, you calls this variable
something like that ???
<flow name="flow1" doc:id="29ba6da8-7458-4f35-adff-1d9db5738fbc" >
<set-variable value="Hello" doc:name="Set Variable" doc:id="055abd42-b240-4113-b08d-dde00b8ea590" variableName="dsRespPayloads"/>
</flow>
<flow name="dataweaveLabFlowTwo" doc:id="ae122a1a-b9d0-490d-a7e4-2c138e5d4c01" >
<logger level="INFO" doc:name="Logger" doc:id="e4f4bf3a-29f9-4d4e-b2c9-d4a86bd2eb29" message='#[" $(vars.dsRespPayloads)"]' />
</flow>

In Mule 4 you can not set the mime types for inputs at the transformer level. You need to set them in the connector where they are generated, in set-payload or set-variable, before they reach the transformer.
Example:
<set-variable variableName="x" value='{"a":"b", "c":1}' mimeType="application/json" doc:name="Set Variable" />

Related

Spring integration : Facing issue while updating the header value again

Trying to place a file in multiple directories using single outbound adapter using spring-integration-file.
In order to achieve that, having a loop in front of the file:outbound-gateway to modify message header target directory on each iteration and send all of them to the same channel again and again till the target count decreases to 0.
Able to loop back to the header enricher channel.but Since we are enriching the header value for the same header name again. the value is not getting updated for header name TARGET_DIR. There is no exception also.
Would like to know some solution if its possible to update the header value again and again for the same header name or is it possible to give the dynamic header name at runtime.
Have tried to delete the TARGET_DIR header using header:filter while looping back. But did not work out.
!-- header enricher -->
<integration:header-enricher input-channel="filesHeaderEnricherChannel" output-channel="filesOut">
<integration:header name="TARGET_COUNT" method="getTargetCount" ref="headerEnricher"/>
<integration:header name="TARGET_DIR" method="getTargetPath" ref="headerEnricher"/>
</integration:header-enricher>
<integration:chain id="filesOutChain" input-channel="filesOut" output-channel="filesOutChainChannel">
<integration:transformer expression="headers.FILE"/>
<file:outbound-channel-adapter id="fileMover"
auto-create-directory="true"
directory-expression="headers.TARGET_DIR"
mode="REPLACE">
<file:request-handler-advice-chain>
<ref bean="retryAdvice" />
</file:request-handler-advice-chain>
</file:outbound-channel-adapter>
</integration:chain>
<!-- decreasing the count on each loop -->
<!-- looping to header enricher channel again as output channel to update the target directory -->
<integration:filter input-channel="filesOutChainChannel" expression="headers.TARGET_COUNT != 0" output-channel="filesHeaderEnricherChannel"
discard-channel="filesArchiveChannel">
</<integration:filter>
You are missing the fact that header-enricher has an extra option:
<xsd:attribute name="default-overwrite">
<xsd:annotation>
<xsd:documentation>
Specify the default boolean value for whether to overwrite existing
header values. This will
only
take effect for
sub-elements that do not provide their own 'overwrite' attribute. If the
'default-overwrite'
attribute is not
provided, then the specified header values will NOT overwrite any
existing ones with the same
header
names.
</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:union memberTypes="xsd:boolean xsd:string" />
</xsd:simpleType>
</xsd:attribute>
As well as the sub-element header has its own:
<xsd:attribute name="overwrite">
<xsd:annotation>
<xsd:documentation>
Boolean value to indicate whether this header value should overwrite an
existing header value for
the same name.
</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:union memberTypes="xsd:boolean xsd:string" />
</xsd:simpleType>
</xsd:attribute>
See also docs on the matter: https://docs.spring.io/spring-integration/docs/current/reference/html/message-transformation.html#header-enricher

Replace element by XPath

I try to replace some element of my input XML in Citrus Framework.
My Spring context contains:
<citrus:namespace-context>
<citrus:namespace prefix="def" uri="http://sample.com/xmlns/2005"/>
</citrus:namespace-context>
My input file starts with:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<ns0:canonicalMessageHeader xmlns:ns0="http://sample.com/xmlns/2005">
<ns0:headerVersion>1.0</ns0:headerVersion>
<ns0:bodyVersion>1.0</ns0:bodyVersion>
<ns0:trackingInfo>
<ns0:eventHandlerInitInfo>
<ns0:processInfo>
<ns0:adapterTrackingId>214F27DF-E1FB-4E84-9122-390C5876ABD2:1</ns0:adapterTrackingId>
...
My endpoint is configured in that way:
<send endpoint="jms:topic:Order.Request?timeout=10000&connectionFactory=DEVconnectionFactoryFrom">
<message>
<resource file="com/sample/citrus/messages/input/SalesOrderTo.xml"/>
<element value="${track}" path="SOAP-ENV:Envelope/SOAP-ENV:Header/def:canonicalMessageHeader/def:trackingInfo/def:eventHandlerInitInfo/def:processInfo/def:adapterTrackingId"/>
I have the following error:
Can not evaluate xpath expression 'SOAP-ENV:Envelope/SOAP-ENV:Header/def:canonicalMessageHeader/def:trackingInfo/def:eventHandlerInitInfo/def:processInfo/def:adapterTrackingId'
at com/sample/citrus/SalesOrderToIT(sequential:45)
at com/sample/citrus/SalesOrderToIT(send:48-82)
Caused by: javax.xml.xpath.XPathExpressionException: org.apache.xpath.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace: def
What's the possible cause of this error?
Best Regards
Global namespace declaration support is missing in Citrus when overwriting message elements in a send operation via XPath. This issue has been tracked: https://github.com/christophd/citrus/issues/331
In the meantime you have to use the exact same namespace prefix as in the message template file - in your case ns0:
Also you could throw away XPath overwrite and use the dot notated Node overwrite like this:
<send endpoint="jms:topic:Order.Request?timeout=10000&connectionFactory=DEVconnectionFactoryFrom">
<message>
<resource file="com/sample/citrus/messages/input/SalesOrderTo.xml"/>
<element value="${track}" path="Envelope.Header.canonicalMessageHeader.trackingInfo.eventHandlerInitInfo.processInfo.adapterTrackingId"/>
</message>
</send>
The dot notation is not based on namespaces but uses the local element names for finding the element in the message template. Obviously not as powerful as XPath but it works with current version of the framework.
You defined nso as namespace prefix in XML but then use def on the XPath, should be nso.

Using "Mule Requester" and FTP loses originalFilename

I am working on a flow that will, when triggered by an HTTP request, download files from an FTP server. In order to do this on request, instead of on polling, I am using the Mule Requester.
I have found that without the requestor, FTP connector will set the "incomingFilename" on the inboundProperties collection for each of the files. When used with the Mule Requester, the filename property is not set, therefore I have no idea what file I am processing... or in this case saving to the file system. In the code below I am using the 'counter' variable for thefilename in the case the the filename doesn't come through.
Any idea how to fix this issue? Here is the flow below:
<ftp:connector name="FTPConfig" pollingFrequency="3000" validateConnections="true" doc:name="FTP"></ftp:connector>
<flow name="FileRequestFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="csvfilesready" allowedMethods="GET" doc:name="HTTP"></http:listener>
<mulerequester:request-collection config-ref="Mule_Requester" resource="ftp://username:pswd#127.0.0.1:21/Incoming?connector=FTPConfig" doc:name="Mule Requester"></mulerequester:request-collection>
<foreach collection="#[payload]" doc:name="For Each">
<set-variable variableName="thefilename" value="#[message.inboundProperties.originalFilename==null ? counter.toString()+'.csv' : message.inboundProperties.originalFilename] " doc:name="Variable"/>
<file:outbound-endpoint path="/IncomingComplete" outputPattern="#[flowVars.thefilename]" responseTimeout="10000" doc:name="File"></file:outbound-endpoint>
<logger message="#['File saved as: ' + payload]" level="INFO" doc:name="Logger"></logger>
</foreach>
<logger message="#[payload]" level="INFO" doc:name="Logger"></logger>
</flow>
UPDATE:
Below is an option for working with the requester, however, you can use the request-collection. The key is to realize that it will return a MuleMessageCollection and to use the Collection Splitter directly after the Requester, which will then returning individually the ftp file messages with the originalFilename.
After playing with this a while, I have found that with FTP in the mule requester you can get the filename only if you use it as a request, not request-collection.
Have not been able to get the request-collection to work if you need filenames associated.
So.... If you need multiple files, you need do something like loop on the requester until the payload is null.
If you have alternate methods please let me know.
I have written an alternate ftp-connector, it allows to issue a list-command in the flow, followed by a loop to read the files.
See: https://github.com/rbutenuth/ftp-client-connector/

How to move property value from Properties file to payload object using spring integration elements

Sample.properties
=================
http.header.amisys.accept.value=arun/vnd.dsths.services-v1+xml
1)Above XSL automatically loaded when my server starts.
2)I have tried <int:enricher> element but it is not helped me.
Sample Code : Below is bit of code I have tried, Can any one suggest me on this.
<int:channel id="PQLegacySecurity-InputChannel" />
<int:chain input-channel="PQLegacySecurity-InputChannel" >
<!-- Split the Search Request Params from Xml -->
<int-xml:xpath-splitter>
<int-xml:xpath-expression expression="//LegacySecurity" namespace map="xmlMessageNamespace" />
</int-xml:xpath-splitter>
<int:enricher >
<int:payload name="testPayload" expression="${http.header.amisys.accept.value}"/>
</int:enricher>
</int:chain>
Actual Payload Object:Below is the xml which does not contain testPayload property.
<?xml version="1.0" encoding="UTF-8"?><LegacySecurity>
<businessArea>%%%%%%</businessArea>
<LegacySystem>%%%%%</LegacySystem>
<LegacyUserID>%%%%%</LegacyUserID>
<LegacyPassword>%%%%%</LegacyPassword>
<OtherLogin/>
<OtherPassword/>
<AddSecurLogin/>
<AddSecurPassword/>
</LegacySecurity>
Expected Payload Object: Below Object contains new element testPayload node which I should able to add
<?xml version="1.0" encoding="UTF-8"?><LegacySecurity>
<businessArea>%%%%%%</businessArea>
<LegacySystem>%%%%%</LegacySystem>
<LegacyUserID>%%%%%</LegacyUserID>
<LegacyPassword>%%%%%</LegacyPassword>
<OtherLogin/>
<OtherPassword/>
**<testPayload>arun/vnd.dsths.services-v1+xml</testPayload>**
<AddSecurLogin/>
<AddSecurPassword/>
</LegacySecurity>
You can use an xslt transformer. Something like the below, though you will need to figure out correct use of the transformer from the spring docs.
Notice you can pass a parameter through to the XSLT
<int-xml:xslt-transformer result-transformer="toDocumentTransformer" result-type="StringResult" xsl-resource="/xslt/addTestPayload.xslt">
<int-xml:xslt-param name="testPayload" value="${http.header.amisys.accept.value}"/>
</int-xml:xslt-transformer>
In the XSLT file, use this to pick up the parameter:
<xsl:param name="testPayload" />
If you have other changes you need to make to the message you can use the same xslt.

Mule ESB simple jdbc insert

I'm trying to force Mule ESB Studio, to perform some simple insert into a jdbc. My goal is to open a page in my webbrowser, let's say it's http://localhost:8081/, and then Mule ESB performs insert 'foobar' value into database.
Here's my code:
<jdbc-ee:mssql-data-source name="MS_SQL_Data_Source" user="esbtest" password="Test123" transactionIsolation="NONE" doc:name="MS SQL Data Source" loginTimeout="10000"
url="jdbc:sqlserver://10.1.212.42:1433;databaseName=test"></jdbc-ee:mssql-data-source>
<jdbc-ee:connector name="Database" dataSource-ref="MS_SQL_Data_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"/>
<flow name="Test_PierwszyFlow1" doc:name="Test_PierwszyFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP" mimeType="text/plain"></http:inbound-endpoint>
<object-to-string-transformer doc:name="Object to String"/>
<jdbc-ee:outbound-endpoint exchange-pattern="one-way" queryTimeout="-1" doc:name="Database" connector-ref="Database" queryKey="insertQuery">
<jdbc-ee:query key="insertQuery" value="INSERT INTO t_Login (login) VALUES ('foo bar')"/>
</jdbc-ee:outbound-endpoint>
</flow>
I've not specified any beans or such things. In logs, I see these lines:
INFO 2013-07-02 11:20:37,550 [[test_pierwszy].connector.http.mule.default.receiver.02] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'Database.dispatcher.1938839184'. Object is: EEJdbcMessageDispatcher
INFO 2013-07-02 11:20:37,550 [[test_pierwszy].connector.http.mule.default.receiver.02] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'Database.dispatcher.1938839184'. Object is: EEJdbcMessageDispatcher
INFO 2013-07-02 11:20:37,670 [[test_pierwszy].connector.http.mule.default.receiver.02] com.mulesoft.mule.transport.jdbc.sqlstrategy.UpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
INFO 2013-07-02 11:20:37,730 [[test_pierwszy].connector.http.mule.default.receiver.02] com.mulesoft.mule.transport.jdbc.sqlstrategy.UpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
...but my database is empty! I must say, I am totally new in Mule ESB area and have no idea what is wrong. Please - help.
Edit: Funny thing is, that when I change talbe or column name to something, that does not exist, I get JDBC error corresponding to that matter.
Second question is, how to inject to DB value I've specified in URL? For example, when I type in browser http://localhost:8081/foo, the value foo is passed to jdbc outcome connector, and 'foo' value is inserted.
Thanks in advance.
I'm guessing uncommitted transaction here. Try adding transactionPerMessage="true" to your <jdbc-ee:connector...
I noticed similar issue in Mule-EE, Mule-CE works fine...
When you call jdbc:outbound-endpoint with an ArrayList payload but use SESSION/INVOCATION variables as params in your SQL query, I noticed it has no effect on the table in question (no Insert/Update) yet logger records "Record Updated".
Changing payload to other type of an Object for this jdbc call solved the issue.
To keep an open mind, consider:
-passing SQL query parameters via a Payload instead
-consider message enrichers

Resources