MuleESB flow, why do I get two files outputted? - mule

I'm trying to get one record from MongoDB and put it into a file, but I get two files, why is that? I thought that these would execute in a sequence and each step in the flow would take the data from the previous step, am I wrong?
<flow name="test1Flow2" doc:name="test1Flow2">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<mongo:find-one-object
config-ref="Mongo_DB" collection="my_collection" doc:name="Mongo DB"
query-ref="#[string:{ }]" >
</mongo:find-one-object>
<mongo:dbobject-to-json doc:name="Mongo DB"/>
<file:outbound-endpoint path="/somewhere" responseTimeout="10000" doc:name="Mongo DB"/>
</flow>
I go to this URL to trigger its execution.
http://localhost:8081/
Thanks, Philip

Try setting a path attribute for the http inbound endpoint, you are quite likely experiencing a favicon.ico request sent by your browser along with the http request you actually want to do.

Related

Mule file inbound connector with poll scope

I'm trying to use mule inbound file connector with poll scope got error saying couldn't start endpoint. If I remove poll scope and use file connector with default polling and its working fine without any file path changes.
I was wondering why is Poll scope giving error? If file inbound connector not allowed to wrapped in poll scope, why anypoint studio showing poll scope in the wrap in option ?
I found similar question, but I didn't see detailed explanations.
Mule won't allow POLL message processor to read file using file Inbound?
Advance thanks for your response.
Use mule-module-requester https://github.com/mulesoft/mule-module-requester, together with the Poll Scheduler.
relevant posts: http://blogs.mulesoft.com/dev/mule-dev/introducing-the-mule-requester-module/
Another way is,
Set the FTP flow initialState="stopped", and let the poll scheduler start the flow. After the FTP processing, stop the flow again.
see sample code:
<ftp:connector name="FTP" pollingFrequency="1000"
validateConnections="true" moveToDirectory="/work/ftp/processed"
doc:name="FTP" />
<flow name="scheduleStartFTPFlow">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="1"
timeUnit="MINUTES" />
<expression-component doc:name="START FTP FLOW"><![CDATA[if(app.registry.processFTPFlow.isStopped()){
app.registry.processFTPFlow.start();
}]]></expression-component>
</poll>
<logger message="Poll Logging: #[payload]" level="INFO"
doc:name="Logger" />
</flow>
<flow name="processFTPFlow" initialState="stopped">
<ftp:inbound-endpoint host="localhost" port="21"
path="/data/ftp" user="Sanjeet" password="sanjeet123" responseTimeout="10000"
doc:name="FTP" connector-ref="FTP" />
<logger message="Logging FTP #[payload]" level="INFO" doc:name="Logger" />
<expression-component doc:name="STOP FTP FLOW"><![CDATA[app.registry.processFTPFlow.stop();]]></expression-component>
</flow>
Please, provide SSCCE.
Based on your question you do not need Poll at all. File Connector already has this feature to check file periodically. Here is example which polls file every 0.123 seconds
<file:inbound-endpoint path="/tmp" responseTimeout="10000" doc:name="File" pollingFrequency="123"/>
My suggestion is to use the quartz connector beside the file connector and set the interval in the quartz connector. Or use the file connector itself having the poll frequency so no need to wrap the file in poll scope.
you can create a file endpoint in the global element section and then use mule requester to invoke that endpoint inside a poll scope.
<file:connector name="File1" autoDelete="true" streaming="true" validateConnections="true" doc:name="File"/>
<file:endpoint connector-ref="File1" name="File" responseTimeout="10000" doc:name="File" path="/"/>
<flow name="pocforloggingFlow1">
<poll doc:name="Poll">
<mulerequester:request resource="File" doc:name="Mule Requester"/>
</poll>
</flow>

Mule Filter by IP is not working

I have a minor issue using Mule IP filter ... As per the Mule documentation http://www.mulesoft.org/documentation/display/34X/Mule+Filter+Processor I have tried to implement
Here is my following Mule Config :-
<filters:config name="Filters" doc:name="Filters"/>
<flow name="testFlow2" doc:name="testFlow2">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="filter" doc:name="HTTP"/>
<filters:filter-by-ip config-ref="Filters" regex="192.168.2.100" doc:name="Filters"/>
<set-payload value="test data after filter" doc:name="Set Payload"/>
<logger level="INFO" doc:name="Logger"/>
</flow>
My IP is 192.168.2.100 but still it's unable to pass the filter Strangely
But at the same time if I use the following filter-by-ip-range :-
<filters:filter-by-ip-range config-ref="Filters" doc:name="Filters" mask="192.168.2.100" net="255.255.255.0"/>
It is able to pass the filter ... Please suggest what wrong am I doing ??
Use the address 127.0.0.1 if you are hitting your Service (deployed locally) from your machine.
Hope this helps.

Timed Mule Web Service Client Flow

I've searched the forums for an answer to this. I found one almost identical question, though the answer left me still wondering.
An almost identical post was found here:
Mule - Schedule a flow to consume a web service
This poster stated the problem I am having very well.
I am also new to Mule and am trying to do the very same thing. I didnt realize I needed a payload since I thought the operation specification was essentially the payload.
Notice that I have a flow that includes cxf:jaxws-client and that client specifies a URL for the service and an operation "listTest".
What other payload do i need to specify in order to actually execute the service request?
I tried to add a dummy payload to the event generator (as suggested in referenced post), and that doesnt make a difference.
When I execute the mule application, and monitor the "test auditor web service" (using wireshark) i see four requests go out for the wsdl, and i see that wsdl returned, but i dont actually see the listTest operation getting invoked.
My flow is:
<http:connector name="HTTP_HTTPS" cookieSpec="netscape"
validateConnections="true" sendBufferSize="0" receiveBufferSize="0"
receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000"
socketSoLinger="0" doc:name="HTTP\HTTPS" />
<flow name="TestAuditorClient_CheckerFlow1" doc:name="TestAuditorClient_CheckerFlow1">
<quartz:outbound-endpoint jobName="GetTestList"
repeatInterval="10000" responseTimeout="10000" doc:name="Quartz">
<quartz:event-generator-job jobGroupName="GetTestList" />
</quartz:outbound-endpoint>
<cxf:jaxws-client operation="listTest"
clientClass="server.TestService_Service" port="TestServicePort"
wsdlLocation="http://192.168.66.7:8080/TestAuditorWebApp/TestService?wsdl"
doc:name="SOAPY" />
<outbound-endpoint
address="http://192.168.66.7:8080/TestAuditorWebApp/TestService"
doc:name="HTTP" />
<logger message="Received HTTP Response #[payload]" level="INFO"
doc:name="Logger" />
<!-- <outbound-endpoint exchange-pattern="request-response" address="http://192.168.66.17:8080/TestAuditorWebApp/TestService"
doc:name="HTTP"/> -->
<file:outbound-endpoint path="C:\tmp"
outputPattern="#[function:datestamp:dd-MM-yy]_#[function:systime].txt"
responseTimeout="10000" doc:name="Output File" />
</flow>
I am not only new to mule, but as well to stack overflow. So if there was a better way for me to ask a related question, please advise and excuse.
Thanks in advance.
Instead of Quartz, you can use a poll message processor to generate the instances of ListTest you need.
Assuming this class FQDN is server.TestService.ListTest (you didn't tell), the following should work:
<flow name="TestAuditorClient_CheckerFlow1">
<poll frequency="10000">
<set-payload value="#[lt=new server.TestService.ListTest(); lt.aField='aValue'; lt]" />
</poll>
...
Notice how you can set values on the POJO directly from the expression that creates it.

How to upload multiple files via REST over HTTP using Mule?

I have a folder say "MyFiles" where I have lots of files. Now I need to upload those file via REST over HTTP . What will be the approach?
I tried the below but it is wrong
<flow name="testFlow1" doc:name="testFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<http:rest-service-component
serviceUrl="http://localhost:8280/rest/xyz"
httpMethod="POST">
</http:rest-service-component>
<http:endpoint host="localhost" port="5430" encoding="UTF-8"
method="POST" connector-ref="fileHttp" path="fileuploader" name="muleFileUploader">
</http:endpoint>
</flow>
Please help. Since the input folder will have multiple files, how can we achieve that also?
Thanks
Your flow doesn't use a file inbound endpoint and uses a generic (non-in non-out) HTTP endpoint so there's no way this can work.
Below is a configuration that successfully uploads files to an HTTP endpoint. I can not make it work without the object-to-byte-array-transformer (the same file gets polled over and over again - bug?), so I hope your files are not huge...
<flow name="fileUploader">
<file:inbound-endpoint path="/tmp/mule/in"
pollingFrequency="5000" moveToDirectory="/tmp/mule/done" />
<object-to-byte-array-transformer />
<http:outbound-endpoint address="http://..."
method="POST" exchange-pattern="request-response" />
</flow>

editing response in mule flow before it gets sent back to the request-response endpoint

I'm kinda new to mule esb, and I can't resolve one trouble I got. Here is what happens:
I have a flow in mule 3.2.0, which receives object with request to a ws. I send it to ws with cxf:jaxws-client and. At the beginning of this flow I have vm:inbound endpoint with request-response pattern. What I want is to apply transformation to the object returned as response from the "vmIn endpoint" before it gets send back to the caller from the "vm.logService endpoint" of the flow. I actually get the response, but it's null payload. The "vm.logService" is the endpoint to witch I send MuleMessage from the Java code with MuleClient.send(url, message, properties).I've read that this should be done with the "response" block, but it seems that this is not happening.
Here is my configuration
<vm:endpoint name="vmOut" path="vmOut" exchange-pattern="request-response"/>
<vm:endpoint name="vmIn" path="vmIn" exchange-pattern="request-response"/>
<pattern:web-service-proxy
name="name"
inboundEndpoint-ref="vmIn"
transformer-refs="logging"
responseTransformer-refs="logging"
outboundEndpoint-ref="vmOut" />
<flow name="logService">
<vm:inbound-endpoint path="vm.logService"/>
<vm:outbound-endpoint ref="vmIn">
<cxf:jaxws-client serviceClass="my.WSClass" operation="operation"
enableMuleSoapHeaders="false"/>
<object-to-string-transformer/>
</vm:outbound-endpoint>
<response>
<custom transformer name="myTransformer" class="someclass" />
</response>
<flow name="genericTransformer">
<vm:inbound-endpoint path="vmOut"/>
<custom-transformer class="mypkg.GenericServiceTransformer">
</custom-transformer>
</flow>
<flow name="import">
<vm:inbound-endpoint path="vm.import" exchange-pattern="request-response"/>
<http:outbound-endpoint address="${Service}" responseTimeout="${ws.timeout}" exchange-pattern="request-response" />
<object-to-string-transformer/>
</flow>
Well, after sending with jaxws-client I have few more flows where this request message is processed, but I don't think that this is the reason why it's not working. Thanks in advance for any help
The "vm.logService" VM endpoint doesn't look request-response to me: since you don't specify an exchange pattern, it is actually one-way by default. That could explain why you don't get anything back.
Also we don't see the definition of the "vmIn" so we can't be sure it's correctly request-response, which could be another reason for not reaching the response block.
Actually: if your response block is the last element in the flow, you don't need it: it's OK if "myTransformer" is applied in the request phase since there's nothing after.
after sending with jaxws-client I have few more flows where this request message is processed
I really don't understand what you mean by that.