I have an Database connector from the selected data i use to create a file and I want to do HTTP post with file (created from the selected data in csv) along with other data (text) as attached in the screenshot. According to the mule documentation, the payload must be an outbound attachment which I am doing by using Set Attachment property. With this approach, I am setting the Content-Type for one of my attachment as application/CVS (as my file is of CVS type) and as text/plain for the other parameter. Any thoughts on achieving this? I have attached the screenshot of how the request looks like in Postman.
Below is the config XML..!!
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd">
<spring:beans>
<spring:bean id="CSFMDataSource" name="CSFMDataSource" class="oracle.jdbc.pool.OracleDataSource">
<spring:property name="user" value="XXCCS_OSB_O"/>
<spring:property name="password" value="OrG2_BtN"/>
<spring:property name="dataSourceName" value="ds"/>
<spring:property name="URL" value="jdbc:oracle:thin:#(DESCRIPTION=(CONNECT_TIMEOUT=5)(TRANSPORT_CONNECT_TIMEOUT=3)(RETRY_COUNT=1)(ADDRESS_LIST=(LOAD_BALANCE=ON)(FAILOVER=ON)(ADDRESS=(PROTOCOL=TCP)(HOST=scan-nprd-2023)(PORT=1541)))(CONNECT_DATA=(SERVICE_NAME=DV3CSF_SRVC_OTH.cisco.com)(SERVER=DEDICATED)))"/>
</spring:bean>
</spring:beans>
<db:oracle-config name="Oracle_Configuration" dataSource-ref="CSFMDataSource" doc:name="Oracle Configuration"/>
<http:request-config name="HTTP_Request_Configuration" host="tools-stage.cisco.com" port="80" doc:name="HTTP Request Configuration"/>
<flow name="testFlow">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="1" timeUnit="MINUTES"/>
<logger message="Log-1" level="INFO" doc:name="Logger"/>
</poll>
<db:select config-ref="Oracle_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[SELECT sol.SW_UPG_CONTRACT_NUMBER,
sol.service_level,
sol.BILL_TO_SITE_USE_ID,
sol.SERVICE_BEGIN_DATE,
sol.SERVICE_END_DATE,
0 Net_Price,
sol.PRODUCT_ORDER_NUMBER,
sol.SERIAL_NUMBER,
sol.SW_UPG_FULFILLMENT_PID,
sol.INSTALL_SITE_USE_ID,
sii.INSTANCE_ID,
DECODE (sii.INSTANCE_ID, 'Yes', 'No') softline,
'1232' cs_cse_number,
lg.error_message
FROM apps.XXCSS_SFM_ORDER_LINES sol,
apps.XXCSS_SFM_ERROR_LOG lg,
apps.XXCSS_SFM_INSTANCE_INTERFACE sii
WHERE 1 = 1
AND sol.order_type = 'INNVO_LINE'
AND sol.entitlement_status IN ('CSFM_ERROR', 'QA_FAILED')
--AND lg.so_header_id = sol.header_id
--AND lg.so_line_id = sol.line_id
AND lg.ERROR_TYPE = 'ERROR'
AND sol.header_id = sii.so_header_id(+)
AND sol.line_id = sii.so_line_id(+)
AND lg.sfdc_case_req = 'Y'
AND lg.sfdc_case_no IS NULL]]></db:parameterized-query>
</db:select>
<dw:transform-message doc:name="Transform Message" metadata:id="38e67a04-7f03-4261-a450-72b69ae0fff1">
<dw:set-payload><![CDATA[%dw 1.0
%output application/csv
---
payload map ((payload01 , indexOfPayload01) -> {
BILL_TO_SITE_USE_ID: payload01.BILL_TO_SITE_USE_ID as :number,
CS_CSE_NUMBER: payload01.CS_CSE_NUMBER,
ERROR_MESSAGE: payload01.ERROR_MESSAGE,
INSTALL_SITE_USE_ID: payload01.INSTALL_SITE_USE_ID as :number,
INSTANCE_ID: payload01.INSTANCE_ID,
NET_PRICE: payload01.NET_PRICE as :number,
PRODUCT_ORDER_NUMBER: payload01.PRODUCT_ORDER_NUMBER,
SERIAL_NUMBER: payload01.SERIAL_NUMBER,
SERVICE_BEGIN_DATE: payload01.SERVICE_BEGIN_DATE,
SERVICE_END_DATE: payload01.SERVICE_END_DATE,
SERVICE_LEVEL: payload01.SERVICE_LEVEL,
SOFTLINE: payload01.SOFTLINE,
SW_UPG_CONTRACT_NUMBER: payload01.SW_UPG_CONTRACT_NUMBER,
SW_UPG_FULFILLMENT_PID: payload01.SW_UPG_FULFILLMENT_PID
})]]></dw:set-payload>
</dw:transform-message>
<byte-array-to-object-transformer doc:name="Byte Array to Object"/>
<set-attachment attachmentName="filedata" value="#[payload]" contentType="application/csv" doc:name="Attachment"/>
<set-attachment attachmentName="casedata" value="{ "Origin":"Web", "CaseNumber":"33315931584", "SearchCCOID":"vimerugu"}" contentType="text/plain" doc:name="Attachment"/>
<set-payload value="#[null]" doc:name="Set Payload"/>
<http:request config-ref="HTTP_Request_Configuration" path="/cvcm/was70/pwc036/caseApi/updateCaseAttach/33315931584" method="POST" doc:name="HTTP" parseResponse="false">
<http:request-builder>
<http:header headerName="Authorization" value="Basic Q1BFQ2FzZUFQSS5nZW46Y2FzZTFnZW4="/>
</http:request-builder>
</http:request>
<logger message="#[flowVars.varCaseUpdate]" level="INFO" doc:name="Logger"/>
<catch-exception-strategy doc:name="Catch Exception Strategy">
<db:insert config-ref="Oracle_Configuration" doc:name="Log_DB">
<db:parameterized-query><![CDATA[insert into XXCSS_SFM_OSB_EXECUTION_LOG (PROCESS_STATUS) values ('SFDCCaseCreationService-Exception')]]></db:parameterized-query>
</db:insert>
<db:insert config-ref="Oracle_Configuration" doc:name="SFDCCaseCreation- Exception">
<db:parameterized-query><![CDATA[insert into XXCSS_SFM_CESB_LOG_ERROR ( LOG_ERROR_ID,SERVICE_NAME,SERVICE_TYPE,SERVICE_ACTIVITY,SERVICE_PAYLOAD,LOG_ERROR_STATUS,
LOG_ERROR_MESSAGE,ERROR_CODE,ERROR_MESSAGE,ERROR_DETAILS,LOG_ERROR_SEVERITY,SUGGESTED_ACTION,NOTIFY_MAIL,NOTIFY_COUNT,ATTRIBUTE_1,
ATTRIBUTE_2,ATTRIBUTE_3,ATTRIBUTE_4,ATTRIBUTE_5,ATTRIBUTE_6,ATTRIBUTE_7,ATTRIBUTE_8,ATTRIBUTE_9,ATTRIBUTE_10,CREATED_BY,CREATION_DATE,LAST_UPDATED_BY,LAST_UPDATE_DATE,BATCH_ID)
values ('1000','SFDCCaseCreationService','SFDCCaseCreationServiceType','SFDCCaseCreationServiceActivity','SFDCCaseCreationServicePayload','ERROR','','Error_Code','Error_Message',
#[exception.getSummaryMessage()],'Critical','','NA',3,'','','','','','','','','','','SFDCCaseCreationService',sysdate,'SFDCCaseCreationService',sysdate,'1000')]]></db:parameterized-query>
</db:insert>
</catch-exception-strategy>
</flow>
</mule>
Please check if below link helps you.It tells how to read multiple files and process them.You can send them to required endpoint instead of FTP
How send a file in an HTTP request and upload it to file server via FTP in Mule
I'm using an IMAP connector to connect to an inbox and download messages. I have the checkFrequency parameter set to 30000 (default is 60000). I've tried other values as well. With the exact code below, if I launch the flow it never checks the email on its own. Not even when it first starts and not after 30 seconds. The only way I can get it to work is by simply adding a whitespace to the XML and saving it again. This causes the connector to connect and download the email message. What am I missing?
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:imap="http://www.mulesoft.org/schema/mule/imap"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:email="http://www.mulesoft.org/schema/mule/email"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.6/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/3.6/mule-file.xsd
http://www.mulesoft.org/schema/mule/imap http://www.mulesoft.org/schema/mule/imap/3.6/mule-imap.xsd
http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/3.6/mule-email.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/3.6/mule-vm.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd" version="EE-3.6.0">
<imap:connector name="imapConnector" checkFrequency="30000" doc:name="IMAP" />
<expression-transformer name="returnAttachments" doc:name="Expression">
<return-argument evaluator="attachments-list" expression="*"/>
</expression-transformer>
<file:connector name="fileName" doc:name="File">
<file:expression-filename-parser/>
</file:connector>
<flow name="incoming-orders">
<imap:inbound-endpoint host="server" port="143" user="user" password="pass" disableTransportTransformer="true" transformer-refs="returnAttachments" doc:name="IMAP" responseTimeout="10000">
</imap:inbound-endpoint>
<foreach doc:name="For Each" collection="#[message.inboundAttachments]" >
<expression-component doc:name="Expression"><![CDATA[key == "test.xml"]]></expression-component>
<file:outbound-endpoint path="c:\Mule\in" outputPattern="#[key]" doc:name="File" responseTimeout="10000">
<expression-transformer>
<return-argument expression="payload.inputStream" evaluator="groovy"/>
</expression-transformer>
</file:outbound-endpoint>
</foreach>
</flow>
</mule>
Add the following attribute to connector definition:
mailboxFolder="INBOX"
You have created a imapConnector config which is not used.
Add to your configuration the last attribute
<imap:inbound-endpoint host="server" port="143" user="user" password="pass" disableTransportTransformer="true" transformer-refs="returnAttachments" doc:name="IMAP" responseTimeout="10000" connector-ref="imapConnector">
Here is what my flow looks like.
In the "Expression" settings, I simply have the following:
key != 0
The filename/pattern for the file connector is #[key]
It is still outputting a file named 0 which contains the email body. It does also output all other attachments properly. I just don't want it to write the email body to a file. What am I doing wrong?
Full code:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:imap="http://www.mulesoft.org/schema/mule/imap"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:email="http://www.mulesoft.org/schema/mule/email"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.6/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/3.6/mule-file.xsd
http://www.mulesoft.org/schema/mule/imap http://www.mulesoft.org/schema/mule/imap/3.6/mule-imap.xsd
http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/3.6/mule-email.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/3.6/mule-vm.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd" version="EE-3.6.0">
<imap:connector name="imapConnector" checkFrequency="10000" doc:name="IMAP" />
<expression-transformer name="returnAttachments" doc:name="Expression">
<return-argument evaluator="attachments-list" expression="*"/>
</expression-transformer>
<file:connector name="fileName" doc:name="File">
<file:expression-filename-parser/>
</file:connector>
<flow name="incoming-orders">
<imap:inbound-endpoint host="server" port="143" user="user" password="pass" disableTransportTransformer="true" transformer-refs="returnAttachments" doc:name="IMAP"/>
<foreach doc:name="For Each" collection="#[message.inboundAttachments]" counterVariableName="i" rootMessageVariableName="msg">
<expression-component doc:name="Expression">key != 0</expression-component>
<file:outbound-endpoint path="c:\Mule\in" outputPattern="#[key]" doc:name="File" responseTimeout="10000">
<expression-transformer>
<return-argument expression="payload.inputStream" evaluator="groovy"/>
</expression-transformer>
</file:outbound-endpoint>
</foreach>
</flow>
</mule>
It looks like the foreach is processing the values of the inboundAttachmentsmap so you don't get keys. I suggest something like:
<foreach doc:name="For Each" collection="#[message.inboundAttachments.entrySet()]">
<expression-transformer doc:name="Expression" expression="#[payload.key != 0]"/>
...
</foreach>
Now you'll process key-value pairs so you might need to use a set-payload to send just payload.value, saving the key before in a variable to use in the file endpoint.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<mulexml:namespace-manager includeConfigNamespaces="true">
<mulexml:namespace prefix="ns0" uri="http://www.cpscreen.com/schemas"/>
</mulexml:namespace-manager>
<configuration doc:name="Configuration">
<expression-language autoResolveVariables="true">
<import class="org.mule.util.StringUtils" />
<import class="org.mule.util.ArrayUtils" />
</expression-language>
</configuration>
<flow name="user_provisions_-_xml_postFlow1" doc:name="user_provisions_-_xml_postFlow1">
<file:inbound-endpoint path="E:/temp/mule" responseTimeout="10000" doc:name="File">
<file:filename-regex-filter pattern="in_(.*).csv" caseSensitive="true"/>
</file:inbound-endpoint>
<file:file-to-string-transformer doc:name="File to String"/>
<expression-component doc:name="Expression"><![CDATA[java.util.List items = new java.util.ArrayList( Arrays.asList( payload.split("\n") ));
items.remove(0);;
java.lang.String listString = '';
for (String s : items) {
listString += s + "\n";
}
payload=listString.trim();]]></expression-component>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="46908" path="userprovision" method="POST" doc:name="HTTP"/>
<object-to-string-transformer mimeType="text/xml" doc:name="Object to String"/>
<splitter expression="#[xpath('//UpdateUserRequest')]" doc:name="Splitter"/>
<logger message="Here is #[payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
I am getting like,
WARN 2014-09-10 15:30:27,181 [[user_provisions_-_xml_post].user_provisions_-_xml_postFlow1.stage1.02] org.mule.routing.ExpressionSplitter: Splitter returned no results. If this is not expected, please check your split expression
Update :
I got where the issue is but I could resolve the split issue. Because of namespace in the XML splitter does not evaluate the split expression...
<?xml version="1.0" encoding="UTF-8"?>
<UpdateUserRequests xmlns="http://www.cpscreen.com/schemas">
<UpdateUserRequest userId="Test" account="Test" password="Test">
<User>
<Account id="4">34567</Account>
<UserId>Test</UserId>
<Profile>Admin</Profile>
<PersonName>
<GivenName>Sahak</GivenName>
<FamilyName>Kn</FamilyName>
</PersonName>
</User>
</UpdateUserRequest>
<UpdateUserRequest userId="Test" account="Test" password="Test">
<User>
<Account id="5">12345</Account>
<UserId>Test</UserId>
<Profile>Admin</Profile>
<PersonName>
<GivenName>Arun</GivenName>
<FamilyName>Kumar</FamilyName>
</PersonName>
</User>
</UpdateUserRequest>
</UpdateUserRequests>
If I remove xmlns="http://www.cpscreen.com/schemas" it is splitting to multiple
How do I add the spit expression if there is a namespace in the xml ?
Use the following expression to split the xml with namespace.
<splitter expression="#[xpath('//ns0:UpdateUserRequest')]" doc:name="Splitter"/>
The above expression works considering the "ns0" namespace is added in the Mule MXL namespace manager.
Hope this helps.
You should directly use the splitter after the file inbound endpoint ...
This expression works for splitting CSV file :-
<splitter expression="#[StringUtils.split(message.payload, '\n\r')]" doc:name="Splitter_For_MultipleRow"/>
And if your CSV files have a column headers like Name, Age etc .. you can use this :-
<splitter expression="#[rows=StringUtils.split(message.payload, '\n\r');ArrayUtils.subarray(rows,1,rows.size())]" doc:name="Splitter_For_MultipleRow"></splitter>
I am trying to utilize the xml to object transformer in mule while transfroming an xml payload to a Java Bean (Customer). Here is my simple flow. The exception I am seeing is below
Exception stack is:
1. CUSTOMER (com.thoughtworks.xstream.mapper.CannotResolveClassException)
com.thoughtworks.xstream.mapper.DefaultMapper:56 (null)
2. CUSTOMER (com.thoughtworks.xstream.mapper.CannotResolveClassException) (org.mule.api.transformer.TransformerException)
org.mule.module.xml.transformer.XmlToObject:76 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
com.thoughtworks.xstream.mapper.CannotResolveClassException: CUSTOMER
at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:56)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)
at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:55)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
FLOW
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
<flow name="alternateFlow1" doc:name="alternateFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8999" doc:name="HTTP"/>
<http:outbound-endpoint exchange-pattern="request-response" host="www.thomas-bayer.com" port="80" path="sqlrest/CUSTOMER/3/" method="GET" doc:name="HTTP"/>
<mulexml:xml-to-object-transformer returnClass="com.abc.dto.CUSTOMER" doc:name="XML to Object"/>
<logger level="INFO" doc:name="Logger"/>
</flow>
</mule>
XML:
<CUSTOMER xmlns:xlink="w3.org/1999/xlink">
;
<ID>4</ID>
<FIRSTNAME>Sylvia</FIRSTNAME>
<LASTNAME>Ringer</LASTNAME>
<STREET>365 College Av.</STREET>
<CITY>Dallas</CITY>
</CUSTOMER>
You need to add an alias in the mulexml:xml-to-object-transformer:
<mulexml:alias name="CUSTOMER" class="com.abc.dto.CUSTOMER" />
Also there's no reason to go all caps with the class name so rename your class and alias it:
<mulexml:alias name="CUSTOMER" class="com.abc.dto.Customer" />