mule send email as an attachment - mule

My below code perfectly send email as an attachment, but the problem is
1) payload is copying to the mail body. I want mail to be sent only as an attachment, don't want to include attachment in body part of the mail.
2) email triggers twice always. I have given thread count as 1. Not sure from where the second event is triggering.
Code:
<mule xmlns:email="http://www.mulesoft.org/schema/mule/email" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:context="http://www.springframework.org/schema/context" xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" 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/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.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/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/current/mule-email.xsd">
<spring:beans>
<context:property-placeholder location="accord.properties"/>
<spring:bean id="transmission" class="com.creativeworld.service.InvokeTransmission"/>
</spring:beans>
<quartz:connector name="ABCQuartz" validateConnections="true" doc:name="ABC Quartz">
<quartz:factory-property key="org.quartz.scheduler.instanceName" value="ABC_XYZKReport"/>
<quartz:factory-property key="org.quartz.threadPool.class" value="org.quartz.simpl.SimpleThreadPool"/>
<quartz:factory-property key="org.quartz.threadPool.threadCount" value="1"/>
<quartz:factory-property key="org.quartz.scheduler.rmi.proxy" value="false"/>
<quartz:factory-property key="org.quartz.scheduler.rmi.export" value="false"/>
</quartz:connector>
<smtp:connector name="ABCSMTP" validateConnections="true" doc:name="SMTP" subject="ABC_XYZK Report"/>
<flow name="flow1" doc:name="flow1" processingStrategy="synchronous">
<quartz:inbound-endpoint jobName="ABCQuartz" repeatInterval="180000" responseTimeout="10000" connector-ref="ABCQuartz" doc:name="ABC XYZK">
<quartz:event-generator-job groupName="creativeworld" jobGroupName="creativeworld">
<quartz:payload>Creative World Quartz Scheduler.</quartz:payload>
</quartz:event-generator-job>
</quartz:inbound-endpoint>
<scripting:component doc:name="Python">
<scripting:script engine="jython" file="ABC_XYZK.py"/>
</scripting:component>
<set-session-variable variableName="outputfilepath" value="${OUTPUT_FILE}${FILE_NAME}-#[server.dateTime.format('${DATETIME_FORMAT}')]${FILE_TYPE}" doc:name="File Name" />
<set-payload value="${COMMAND_PATH}#[' ']${DB_NAME}${OUTPUT_FILE}${URL}" doc:name="Transmission Commands"/>
<set-payload value="#[message.payload]#[' -outputpath ']#[outputfilepath]" doc:name="Output Config"/>
<invoke object-ref="transmission" method="invoke" methodArgumentTypes="java.lang.String" methodArguments="#[payload]" name="transmissionAPI"/>
<vm:outbound-endpoint exchange-pattern="one-way" path="smtp" doc:name="VM"/>
</flow>
<flow name="smtp" doc:name="smtp" processingStrategy="synchronous">
<vm:inbound-endpoint exchange-pattern="one-way" path="smtp" doc:name="VM"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[new File(sessionVars['outputfilepath']).text]]></scripting:script>
</scripting:component>
<set-attachment attachmentName="${FILE_NAME}-#[server.dateTime.format('${DATETIME_FORMAT}')]${FILE_TYPE}" value="#[payload]" contentType="text/plain" doc:name="ABC_XYZK Report"/>
<smtp:outbound-endpoint host="mailrelay.ad.corp.local" responseTimeout="10000" doc:name="SMTP" connector-ref="ABCSMTP" mimeType="text/plain" from="mymailid#mycompany.com" subject="ABC_XYZK" to="mymailid#mycompany.com">
<!-- <email:email-to-string-transformer/> -->
</smtp:outbound-endpoint>
</flow>

Simple solution :- If you don't want the same payload in the mail body simply put <set-payload value="Hi this is the mail content " doc:name="Output Config"/> just after <set-attachment > tag with the content you like to have as mail body eg :-
<set-attachment attachmentName="${FILE_NAME}-#[server.dateTime.format('${DATETIME_FORMAT}')]${FILE_TYPE}" value="#[payload]" contentType="text/plain" doc:name="ABC_XYZK Report"/>
<set-payload value="Hi this is the mail content " doc:name="Output Config"/>
<smtp:outbound-endpoint host="mailrelay.ad.corp.local" responseTimeout="10000" doc:name="SMTP" connector-ref="ABCSMTP" mimeType="text/plain" from="mymailid#mycompany.com" subject="ABC_XYZK" to="mymailid#mycompany.com">
<!-- <email:email-to-string-transformer/> -->
</smtp:outbound-endpoint>
The payload you set after attachment will be in your mail body

Related

Mocking SubFlow in Mule

I am trying to create MUnit for the below flow.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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.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/db http://www.mulesoft.org/schema/mule/db/current/mule-db.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/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<db:oracle-config name="Oracle_Configuration" host="127.0.0.1" port="1521" instance="xe" user="system" password="madhu" doc:name="Oracle Configuration"/>
<flow name="munitFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/munit" doc:name="HTTP"/>
<object-to-string-transformer doc:name="Object to String"/>
<set-payload value="#[payload]" doc:name="Set Payload"/>
<flow-ref name="SubFlow1" doc:name="SubFlow1"/>
<choice doc:name="Choice">
<when expression="#[flowVars.temp == '1']">
<set-payload value="Hello from madhu" doc:name="Set Payload"/>
</when>
<otherwise>
<set-payload value="Hello from mitha" doc:name="Set Payload"/>
</otherwise>
</choice>
</flow>
<sub-flow name="SubFlow1">
<choice doc:name="Choice">
<when expression="#[payload=='1']">
<set-variable variableName="temp" value="1" doc:name="set temp to 1"/>
</when>
<otherwise>
<set-variable variableName="temp" value="2" doc:name="set temp to 2"/>
</otherwise>
</choice>
</sub-flow>
</mule>
I have create two test flows for subflow, which is working fine.
Eventhough I mocked subflow to test the main flow, the flow is executing the sub flow. Any ideas if I am missing something while mocking the sub flow. Any help will be highly appreciated.
This is my testsuite
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:munit="http://www.mulesoft.org/schema/mule/munit" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:mock="http://www.mulesoft.org/schema/mule/mock" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/munit http://www.mulesoft.org/schema/mule/munit/current/mule-munit.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/mock http://www.mulesoft.org/schema/mule/mock/current/mule-mock.xsd">
<munit:config name="munit" doc:name="MUnit configuration"/>
<spring:beans>
<spring:import resource="classpath:munit.xml"/>
</spring:beans>
<munit:test name="munit-test-suite-munitSub_FlowTest" description="Test">
<munit:set payload="1" doc:name="Set Message"/>
<flow-ref name="SubFlow1" doc:name="SubFlow1"/>
<mock:verify-call messageProcessor="mule:set-variable" doc:name="Verify Call">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#['set temp to 1']"/>
</mock:with-attributes>
</mock:verify-call>
</munit:test>
<munit:test name="munit-test-suite-munitSub_FlowTest1" description="Test">
<munit:set payload="2" doc:name="Set Message"/>
<flow-ref name="SubFlow1" doc:name="SubFlow1"/>
<mock:verify-call messageProcessor="mule:set-variable" doc:name="Verify Call">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#['set temp to 2']"/>
</mock:with-attributes>
</mock:verify-call>
</munit:test>
<munit:test name="munit-test-suite-munitFlowTest" description="Test">
<mock:when messageProcessor=".*:.*" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#['Set Payload']"/>
</mock:with-attributes>
<mock:then-return payload="#[samePayload()]"/>
</mock:when>
<mock:when messageProcessor="mule:sub-flow" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#[matchContains('SubFlow1')]"/>
</mock:with-attributes>
<mock:then-return payload="#[samePayload()]">
<mock:invocation-properties>
<mock:invocation-property key="temp" value="1"/>
</mock:invocation-properties>
</mock:then-return>
</mock:when>
<flow-ref name="munitFlow" doc:name="munitFlow"/>
<munit:assert-payload-equals message="Wrong payload" expectedValue="Hello from madhu" doc:name="Assert Payload"/>
</munit:test>
</mule>
The culprit is this
<mock:with-attribute name="doc:name" whereValue="#[matchContains('SubFlow1')]"/>
The name should be name not doc:name

How to map DB Map to XLS file in mule datamapper?

I was trying to query a DB using an excel sheet values as a select parameter. I was getting the result set perfectly but I can't map it to an XLS using data mapper.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:batch="http://www.mulesoft.org/schema/mule/batch" 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.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/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.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/batch http://www.mulesoft.org/schema/mule/batch/current/mule-batch.xsd
http://www.mulesoft.org/schema/mule/ee/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.xsd">
<data-mapper:config name="MS_Excel_To_Map" transformationGraphPath="ms_excel_to_map.grf" doc:name="MS_Excel_To_Map"/>
<db:generic-config name="Generic_Database_Configuration" url="jdbc:as400://awh400.awh.com.au/wsprdp;user=AWSTEST;password=TESTUSER" driverClassName="com.ibm.as400.access.AS400JDBCDriver" doc:name="Generic Database Configuration"/>
<data-mapper:config name="List_Map__To_MS_Excel" transformationGraphPath="list_map__to_ms_excel.grf" doc:name="List_Map__To_MS_Excel"/>
<batch:job name="wettenhalls_finalBatch">
<batch:input>
<file:inbound-endpoint path="C:\Users\pd00h\Desktop\Wettenhalls\Inbound" responseTimeout="10000" doc:name="File"/>
<file:file-to-byte-array-transformer doc:name="File to Byte Array"/>
<data-mapper:transform config-ref="MS_Excel_To_Map" doc:name="MS Excel To Map"/>
</batch:input>
<batch:process-records>
<batch:step name="Batch_Step">
<db:select config-ref="Generic_Database_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[SELECT DELODNBR, DELODNBLS FROM wsprdd.wsdlvlod WHERE DELODNBR = #[payload.'cus_ref']]]></db:parameterized-query>
</db:select>
<data-mapper:transform config-ref="List_Map__To_MS_Excel" doc:name="List<Map> To MS Excel"/>
<logger level="INFO" doc:name="Logger"/>
<file:outbound-endpoint path="C:\Users\pd00h\Desktop\Wettenhalls\Outbound" outputPattern="#[message.id].xls" responseTimeout="10000" doc:name="File"/>
</batch:step>
</batch:process-records>
<batch:on-complete>
<logger level="INFO" doc:name="Logger"/>
</batch:on-complete>
</batch:job>
</mule>
I keep on getting Null Pointer errors
org.mule.api.MessagingException: null (java.lang.NullPointerException). Message payload is of type: LinkedList
null (java.lang.NullPointerException)
Im not sure if I missed a step. I need to populate the matching values from the input xls to the output xls.
thanks

Making call to Rest services in mule ESB

I have made a web app which call mule server which is listening to http inbound point at 8081 for accessing the database.I am accessing the database successfully and getting a message. But I want to access the other rest services after I get the object from the database and run some operations.
I don't know how to achieve this.
Please give me example. I am posting my flow.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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" version="EE-3.5.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/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/current/mule-jersey.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
<http:endpoint exchange-pattern="request-response" host="localhost" port="8081" method="POST" name="HTTP" doc:name="HTTP"/>
<db:mysql-config name="MySQL_Configuration" host="localhost" port="3306" user="root" password="123456" database="Customer" doc:name="MySQL Configuration"/>
<flow name="muleesbintegrationFlow1" doc:name="muleesbintegrationFlow1">
<http:inbound-endpoint exchange-pattern="request-response" path="crud" doc:name="HTTP" ref="HTTP"/>
<set-session-variable variableName="input" value="#[message.inboundProperties.'http.query.params'.input]" doc:name="input"/>
<set-session-variable variableName="cid" value="#[message.inboundProperties.'http.query.params'.cid]" doc:name="cid"/>
<set-session-variable variableName="fname" value="#[message.inboundProperties.'http.query.params'.fname]" doc:name="fname"/>
<set-session-variable variableName="lname" value="#[message.inboundProperties.'http.query.params'.fname]" doc:name="lname"/>
<choice doc:name="ChoicerOfCrud">
<when expression="#[sessionVars['input']== "insert"]">
<db:insert config-ref="MySQL_Configuration" doc:name="insert">
<db:parameterized-query><![CDATA[INSERT INTO `Customer`.`customer` (`customer_id`, `fname`, `lname`) VALUES (#[sessionVars['cid']], #[sessionVars['fname']], #[sessionVars['lname']]);]]></db:parameterized-query>
</db:insert>
</when>
<when expression="#[sessionVars['input']]=="update"]">
<db:update config-ref="MySQL_Configuration" doc:name="update">
<db:parameterized-query><![CDATA[UPDATE `Customer`.`customer` set
fname = #[sessionVars['fname']],
lname= #[sessionVars['lname']]
where customer_id = #[sessionVars['cid']];]]></db:parameterized-query>
</db:update>
</when>
<when expression="#[sessionVars['input']=="select"]">
<db:select config-ref="MySQL_Configuration" doc:name="selected">
<db:parameterized-query><![CDATA[SELECT * FROM Customer.customer where customer_id =#[sessionVars['cid']];]]></db:parameterized-query>
</db:select>
</when>
<otherwise>
<db:delete config-ref="MySQL_Configuration" doc:name="delete">
<db:dynamic-query><![CDATA[DELETE FROM `Customer`.`customer` WHERE `customer_id`=#[sessionVars['cid']];]]></db:dynamic-query>
</db:delete>
</otherwise>
</choice>
</flow>
</mule>
I recommend to use http:outbound-endpoint to consume a REST service (GET,POST, PUT or DELETE). In this example you can see a flow to invoke a services GET:
<flow name="invoke-ws" doc:name="invoke-ws">
<vm:inbound-endpoint exchange-pattern="request-response" path="vm-ws" doc:name="VM"/>
<logger message="payload is: #[payload]" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" method="GET" address="http://ip:port/service/#[payload]" doc:name="HTTP">
<set-property propertyName="Accept" value="application/json"/>
</http:outbound-endpoint>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<logger message="payload is: #[payload]" level="INFO" doc:name="Logger"/>
</flow>
If the service is SOAP over HTTP, I recommend using http://www.mulesoft.org/documentation/display/current/Web+Service+Consumer

Mule ESB Until-Successful Not Working Properly

I have spent the past few hours trying to get until-successful to work properly, but to no avail even after following the model here: "http://blogs.mulesoft.org/meet-until-successful-store-and-forward-for-mule/". The main flow that uses until-successful is SEND_TO_POST_SERVICE. I want until-successful to continue running the referenced flow until the max retries. Below are my flows and relevant information. The internal Mule server version is 3.4, and the Mule Studio version is 3.4.0
################## Flow
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:json="http://www.mulesoft.org/schema/mule/json"
xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:core="http://www.mulesoft.org/schema/mule/core"
version="EE-3.4.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.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/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<choice-exception-strategy name="Post_Exception_Strategy">
<catch-exception-strategy when="exception.causedBy(java.net.SocketTimeoutException) or exception.causedBy(java.net.ConnectException)" doc:name="Catch Exception Strategy">
<logger message="Network exception occurred" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
<catch-exception-strategy when="exception.causedBy(java.lang.Throwable)" doc:name="Catch Exception Strategy">
<logger message="General exception occurred" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</choice-exception-strategy>
<flow name="compositeFlow1"
doc:name="compositeFlow1">
<composite-source doc:name="Comp Source">
<inbound-endpoint doc:name="DTCOM"
ref="SUBMISSION_REQUEST_EP"/>
</composite-source>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<flow-ref name="POST_TO_SERVICES"
doc:name="POST_TO_SERVICES_ref"/>
<exception-strategy ref="Post_Exception_Strategy"
doc:name="Reference Exception Strategy"/>
</flow>
<flow name="POST_TO_SERVICES" doc:name="POST_TO_SERVICES" processingStrategy="synchronous">
<!-- Send to the POST Service -->
<async>
<flow-ref name="SEND_TO_POST_SERVICE" doc:name="SEND_TO_POST_SERVICE_ref"/>
</async>
<outbound-endpoint ref="HTTP_EP_1" doc:name="HTTP_EP_1"/>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<set-variable variableName="statusCode" value="#[message.inboundProperties['http.status']]" doc:name="statusCode"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
<logger message="Data submitted to Endpoint HTTP_STATUS_CODE: #[statusCode]" level="INFO" doc:name="Logger"/>
<exception-strategy ref="Post_Exception_Strategy" doc:name="Reference Exception Strategy"/>
</flow>
<spring:beans>
<spring:bean id="myListableObjectStore" class="org.mule.util.store.SimpleMemoryObjectStore"/>
</spring:beans>
<flow name="SEND_TO_POST_SERVICE" doc:name="Send to POST Service">
<choice doc:name="Choice">
<when expression="${send_to_post} == 'true'">
<until-successful objectStore-ref="myListableObjectStore" maxRetries="3" secondsBetweenRetries="2" doc:name="Until_Success">
<flow-ref name="CONNECT_TO_POST_SERVICE" doc:name="CONNECT_TO_POST_SERVICE_ref"/>
</until-successful>
</when>
<otherwise>
<logger message="NOT Posting to SERVICE" level="DEBUG" doc:name="Send_Logger"/>
</otherwise>
</choice>
</flow>
<flow name="CONNECT_TO_POST_SERVICE" doc:name="CONNECT_TO_POST_SERVICE">
<logger message="$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$In Until-Successful for POST" level="INFO" doc:name="USLogger"/>
<processor-chain doc:name="Processor Chain">
<logger message="Sending JSON to POST Service" level="INFO" doc:name="JSON_POST_Logger"/>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<message-properties-transformer doc:name="Message Properties">
<add-message-property key="Content-Type" value="application/json"/>
</message-properties-transformer>
<outbound-endpoint ref="POST_SERVICE_EP" doc:name="POST_SERVICE" exchange-pattern="request-response"></outbound-endpoint>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<logger message="Status Code response from Sending POST JSON = #[message.inboundProperties['http.status']]" level="INFO" doc:name="StatusCodeLog"/>
<logger message="Message from POST Service for #[payload]" level="INFO" doc:name="LoggerMessageOutput"/>
</processor-chain>
</flow>
</mule>
################## Endpoints
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
xmlns:https="http://www.mulesoft.org/schema/mule/https"
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.3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.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:endpoint name="POST_SERVICE_EP" exchange-pattern="request-response" address="http://127.0.0.1:8900/post/service/" connector-ref="http_connector" contentType="application/json" doc:name="HTTP"/>
<http:endpoint name="HTTP_EP_1" method="PUT" contentType="application/json" connector-ref="http_connector_2" address="http://127.0.0.1:8900/put/service/" doc:name="HTTP"/>
</mule>
################## Connectors
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:https="http://www.mulesoft.org/schema/mule/https"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" version="EE-3.3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.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:connector name="http_connector" clientSoTimeout="1000000" serverSoTimeout="1000000" doc:name="http_connector" keepAlive="true">
<receiver-threading-profile maxThreadsActive="10" doThreading="true" threadWaitTimeout="-1" maxBufferSize="10000" maxThreadsIdle="5" poolExhaustedAction="WAIT"/>
<dispatcher-threading-profile maxThreadsActive="10" doThreading="true" threadWaitTimeout="-1" maxBufferSize="10000" maxThreadsIdle="5" poolExhaustedAction="WAIT"/>
</http:connector>
<http:connector name="http_connector_2" doc:name="http_connector" keepAlive="true">
<receiver-threading-profile maxThreadsActive="10" doThreading="true" threadWaitTimeout="-1" maxBufferSize="10000" maxThreadsIdle="5" poolExhaustedAction="WAIT"/>
<dispatcher-threading-profile maxThreadsActive="10" doThreading="true" threadWaitTimeout="-1" maxBufferSize="10000" maxThreadsIdle="5" poolExhaustedAction="WAIT"/>
</http:connector>
</mule>
The flow you are flow-refing (ie CONNECT_TO_POST_SERVICE) is a private flow not a sub-flow.
This means that exceptions thrown in it will not be propagated to the caller. Change it to a sub-flow and it should work.
PS. Also remove the processor-chain in CONNECT_TO_POST_SERVICE: it's completely useless.

Mule file download with HTTP Endpoint

My HTTP Endpoint responsible for downloading the file at the end of the flow is erroring out. It keeps trying to communicate with http://:80/ instead of the URL passed in. What am I doing wrong here?
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:https="http://www.mulesoft.org/schema/mule/https" 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="CE-3.3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.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/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd
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/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd ">
<flow name="BingFlow1" doc:name="BingFlow1">
<http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8081" doc:name="HTTP"/>
<https:outbound-endpoint exchange-pattern="request-response" host="api.datamarket.azure.com" port="443" path="Data.ashx/Bing/Search/v1/Web?Query=%27contract%20california%27&WebFileType=%27PDF%27&$top=50&$format=Json" user="*****" password="*****" doc:name="Bing"/>
<json:json-to-object-transformer returnClass="java.util.Map" doc:name="JSON to Object"/>
<expression-transformer expression="#[message.payload.d.results]" doc:name="Expression"/>
<collection-splitter doc:name="Collection Splitter"/>
<expression-transformer expression="#[org.mule.util.StringUtils.substringAfter(message.payload.Url, 'http://')]" doc:name="Expression"/>
<logger message="Payload is: #[message.payload]" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" host="#[org.mule.util.StringUtils.substringBefore(message.payload, '/')]" port="80" method="GET" doc:name="HTTP" contentType="application/pdf" mimeType="application/pdf" path="#[org.mule.util.StringUtils.substringAfter(message.payload, '/')]"/>
<file:outbound-endpoint responseTimeout="10000" doc:name="File" outputPattern="#[org.mule.util.StringUtils.replace(message.payload, '/','.')]" path="/home/user/Documents/output" mimeType="application/pdf"/>
</flow>
</mule>
When changed to match the first answer, I get this exception:
********************************************************************************
Message : Failed to invoke REST service "http://santaclaraca.gov/modules/ShowDocument.aspx?documentid=108?followRedirects=true". Message payload is of type: LinkedHas
hMap
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Failed to invoke REST service "http://santaclaraca.gov/modules/ShowDocument.aspx?documentid=108?followRedirects=true". Message payload is of type: LinkedHashMap (org.mule.transp
ort.http.components.RestServiceException)
org.mule.transport.http.components.RestServiceWrapper:219 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/transport/http/components/RestServiceException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.transport.http.components.RestServiceException: Failed to invoke REST service "http://santaclaraca.gov/modules/ShowDocument.aspx?documentid=108?followRedirects=true". Mess
age payload is of type: LinkedHashMap
at org.mule.transport.http.components.RestServiceWrapper.doInvoke(RestServiceWrapper.java:219)
at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:126)
at org.mule.component.AbstractComponent.access$000(AbstractComponent.java:61)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
--- SOLVED ---
Big thanks to David. This is my final solution:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json"
xmlns:https="http://www.mulesoft.org/schema/mule/https" 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="CE-3.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.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/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd
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 ">
<configuration doc:name="Configuration">
<expression-language>
<import class="org.mule.util.StringUtils" />
</expression-language>
</configuration>
<flow name="BingQuery" doc:name="BingQuery">
<http:inbound-endpoint exchange-pattern="one-way"
host="localhost" port="8082" doc:name="HTTP" />
<https:outbound-endpoint exchange-pattern="request-response"
host="api.datamarket.azure.com" port="443"
path="Data.ashx/Bing/Search/v1/Web?Query=%27california%20school%20district%20contract%27&WebFileType=%27PDF%27&$top=10&$format=Json"
user="*****" password="*****"
doc:name="Bing" />
<json:json-to-object-transformer
returnClass="java.util.Map" doc:name="JSON to Object" />
<expression-transformer expression="#[message.payload.d.results]"
doc:name="Expression" />
<collection-splitter doc:name="Collection Splitter" />
<vm:outbound-endpoint exchange-pattern="one-way"
doc:name="VM" path="fileWriter" />
</flow>
<flow name="RestProcessor" doc:name="RestProcessor">
<vm:inbound-endpoint exchange-pattern="one-way"
doc:name="VM" path="fileWriter" />
<set-variable variableName="fileName" value="#[message.payload.ID].pdf"
doc:name="Variable" />
<http:rest-service-component
serviceUrl="#[joinChar=message.payload.Url.contains('?')?'&':'?' ; StringUtils.join(new String[]{message.payload.Url,(String)joinChar,'followRedirects=true'})]"
httpMethod="GET">
<http:error-filter>
<expression-filter
expression="#[Integer.valueOf(message.inboundProperties['http.status']) >= 400]"></expression-filter>
</http:error-filter>
</http:rest-service-component>
<file:outbound-endpoint responseTimeout="10000"
doc:name="File" outputPattern="#[flowVars.fileName]" path="/home/ken/Documents/output"
mimeType="application/pdf" />
</flow>
</mule>
I can't spot the error: your flow looks good (except a problem I'll detail below) so, alternatively to using an http:outbound-endpoint, which can be finicky at times, you could use the http:rest-service-component.
Your next problem will be in the outputPattern of the file endpoint: remember at this point message.payload will be the response from the HTTP endpoint not the (partial) URL anymore. You need to pre-compute the file name and store it in a flow variable, then use it.
This would give:
<configuration>
<expression-language>
<import class="org.mule.util.StringUtils" />
</expression-language>
</configuration>
<flow name="BingFlow1" doc:name="BingFlow1">
<http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8081" doc:name="HTTP"/>
<https:outbound-endpoint exchange-pattern="request-response" host="api.datamarket.azure.com" port="443" path="Data.ashx/Bing/Search/v1/Web?Query=%27contract%20california%27&WebFileType=%27PDF%27&$top=50&$format=Json" user="*****" password="*****" doc:name="Bing"/>
<json:json-to-object-transformer returnClass="java.util.Map" doc:name="JSON to Object"/>
<expression-transformer expression="#[message.payload.d.results]" doc:name="Expression"/>
<collection-splitter doc:name="Collection Splitter"/>
<set-variable variableName="fileName" value="#[org.mule.util.StringUtils.substringAfter(message.payload.Url, 'http://').replace('/','.')]" />
<http:rest-service-component serviceUrl="#[joinChar=message.payload.Url.contains('?')?'&':'?' ; StringUtils.join(new String[]{message.payload.Url,(String)joinChar,'followRedirects=true'})]" httpMethod="GET">
<http:error-filter>
<expression-filter expression="#[Integer.valueOf(message.inboundProperties['http.status']) >= 400]" />
</http:error-filter>
</http:rest-service-component>
<file:outbound-endpoint responseTimeout="10000" doc:name="File" outputPattern="#[flowVars.fileName]" path="/home/user/Documents/output" mimeType="application/pdf"/>
</flow>