I am trying to copy file from one local folder to another when invoked via some http url but it is not working. In my destination folder some garbage file is getting created with .dat extension
Source folder - so1
Destination folder - so2
This is the message i get in the mule console on invoking the http endpoint
INFO 2017-10-27 14:02:45,346 [[each].HTTP_Listener_Configuration.worker.01] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'File.dispatcher.33168380'. Object is: FileMessageDispatcher
INFO 2017-10-27 14:02:45,467 [[each].HTTP_Listener_Configuration.worker.01] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'File.dispatcher.33168380'. Object is: FileMessageDispatcher
INFO 2017-10-27 14:02:45,488 [[each].HTTP_Listener_Configuration.worker.01] org.mule.transport.file.FileConnector: Writing file to: D:\so2\681cebe0-baf1-11e7-9534-0c7b20524153.dat
Here is the configuration XML
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:file="http://www.mulesoft.org/schema/mule/file"
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.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/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration" />
<file:connector name="File" writeToDirectory="D:\so2" readFromDirectory="D:\so1" autoDelete="false" streaming="true" validateConnections="true" doc:name="File" />
<flow name="eachFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/copy" doc:name="HTTP" />
<file:outbound-endpoint path="D:\so1" connector-ref="File" responseTimeout="10000" doc:name="File" />
<set-payload value="files copied" doc:name="Set Payload" />
</flow>
</mule>
No where your are reading the file in your configuration.
In your scenario, the file outbound endpoint just creates a new file with null payload with unknown file extension.
You can do in two ways,
1) Instead of HTTP inbound, you can use file inbound to read the file and then copy.
2) If you have to use HTTP inbound to copy the file on demand, use mule requester component in middle of configuration to read the file and then copy.
How to use mule requester, you can check here https://www.ricston.com/blog/reading-file-middle-flow-mule-requester/
UPDATE:
See the below configuration to read all the files from one folder and to copy to another folder using Mule requester.
<http:listener-config name="HTTP_Listener_Configuration"
host="localhost" port="8086" doc:name="HTTP Listener Configuration" />
<file:connector name="File"
autoDelete="true" streaming="false"
validateConnections="true" doc:name="File" moveToDirectory="C:\FilePOC\so2"/>
<flow name="Flow1">
<http:listener config-ref="HTTP_Listener_Configuration"
path="/copy" doc:name="HTTP" />
<mulerequester:request-collection resource="file:///C:/FilePOC/so1?connector=File" doc:name="Mule Requester"/>
<set-payload value="File copy has been successful." doc:name="Set Payload"/>
</flow>
Here, no need to use the File outbound component to copy the files. The moveToDirectory option on File connector moves the file once the file has been read.
The other example on how to use Mule requester with JMS can be found here https://www.slideshare.net/anir37/using-mule-requester-for-jms
Related
I am trying to read two simultaneously file in middle of the flow and combine them into one payload. To reading the files in middle of the flow I am using mule requester component. While triggering the flow (localhost:8081/requester/requester)I am getting error :
"Exception(s) were found for route(s):
0: The endpoint "src\main\resources\input1\employees.xml" is malformed and cannot be parsed. If this is the name of a global endpoint, check the name is correct, that the endpoint exists, and that you are using the correct configuration (eg the "ref" attribute). Note that names on inbound and outbound endpoints cannot be used to send or receive messages; use a named global endpoint instead. (org.mule.api.endpoint.MalformedEndpointException).
1: The endpoint "src\main\resources\input2\employees2.xml" is malformed and cannot be parsed. If this is the name of a global endpoint, check the name is correct, that the endpoint exists, and that you are using the correct configuration (eg the "ref" attribute). Note that names on inbound and outbound endpoints cannot be used to send or receive messages; use a named global endpoint instead. (org.mule.api.endpoint.MalformedEndpointException)."
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:mulerequester="http://www.mulesoft.org/schema/mule/mulerequester" xmlns:file="http://www.mulesoft.org/schema/mule/file" 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/mulerequester http://www.mulesoft.org/schema/mule/mulerequester/current/mule-mulerequester.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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<file:connector name="file-connector-config" autoDelete="false" streaming="true" validateConnections="true" doc:name="File" />
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" basePath="/requester" doc:name="HTTP Listener Configuration" />
<flow name="muleRequester">
<http:listener config-ref="HTTP_Listener_Configuration" path="/requester" doc:name="HTTP" />
<logger message="Invoking Mule Requester" level="INFO" doc:name="Logger" />
<scatter-gather doc:name="Scatter-Gather">
<mulerequester:request resource="src\main\resources\input1\employees.xml" returnClass="java.lang.String" doc:name="Retrieve File1"/>
<mulerequester:request resource="src\main\resources\input2\employees2.xml" returnClass="java.lang.String" doc:name="Retrieve File2"/>
</scatter-gather><dw:transform-message doc:name="Transform Message">
<dw:set-payload>< [CDATA[%dw 1.0 %output application/json
---
{
payload1: payload[0],
payload2: payload[1]
}]]></dw:set-payload>
</dw:transform-message>
<file:outbound-endpoint path="src/main/resources/output" responseTimeout="10000" doc:name="File"/>
<logger message="Payload after file requester #[payload]" level="INFO" doc:name="Logger" />
</flow>
I am not using maven. Do I need to download any other jar or where I can do the correction?
resource needs to be an Mule endpoint url. Mule requester module can work with many transports such as jms, file, ftp. So the path to the file is not enough. Here is an example of an endpoint url for reading a file:
<mulerequester:request resource="file://src/main/resources/in/ReadME.txt?connector=file-connector-config" doc:name="Retrieve File" returnClass="java.lang.String" />
You can also point to a global endpoint like you have defined like so:
<mulerequester:request config-ref="muleRequesterConfig" resource="myFileEndpoint" doc:name="Mule Requester" />
I am trying to move files with the help of MuleRequester. With large files (300MB>x) sometimes the while flow is blocking and I always get the error message below.
The file is locked by the java.exe process all the time.
With small files there is no problem.
The file remains in the folder "C:\itm\main\datafeeds\backup" and the "C:\itm\main\datafeeds\process\" is empty.
I don't have any idea how to fix this.
Error Message:
Message : Failed to move file "C:\itm\main\datafeeds\backup\my_file.xml" to "C:\itm\main\datafeeds\process\my_file.xml". The file might already exist.
Payload : [{numOfRecords=0}]
Payload Type : java.util.LinkedList
Endpoint : DefaultInboundEndpoint{endpointUri=file:///C:/itm/main/datafeeds/backup/?autoDelete=true, connector=FileConnector
{
name=File
lifecycle=start
this=300a38e7
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true
connected=true
supportedProtocols=[file]
serviceOverrides=<none>
}
, name='endpoint..C.itm.main.datafeeds.backup', mep=ONE_WAY, properties={autoDelete=true}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false}
Timeout : 1000
Element : /poller_product_parse_aff_file/processors/0/0/1 # product_2_parse_aff_file_to_db
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.api.DefaultMuleException: Failed to move file "C:\itm\main\datafeeds\backup\my_file.xml" to "C:\itm\main\datafeeds\process\my_file.xml". The file might already exist.
at org.mule.transport.file.FileMessageRequester.moveOrDelete(FileMessageRequester.java:222)
at org.mule.transport.file.FileMessageRequester.doRequest(FileMessageRequester.java:188)
at org.mule.transport.AbstractMessageRequester.request(AbstractMessageRequester.java:94)
at org.mule.transport.AbstractConnector.request(AbstractConnector.java:2259)
at org.mule.endpoint.DefaultInboundEndpoint.request(DefaultInboundEndpoint.java:80)
at org.mule.client.DefaultLocalMuleClient.request(DefaultLocalMuleClient.java:184)
at org.mule.module.MuleRequesterModule.request(MuleRequesterModule.java:64)
...
The mule-requester cfg:
<mulerequester:request resource="${file.RequesterUrl}" timeout="1000" doc:name="Mule Requester" />
Environment:
Operation System: Windows Server 2012R2
JRE: v1.7
Mule Requester: v1.5
Mule Anypoint Studio: Mule Server 3.8.0 CE
When working with such big files the problem mostly in memory available for java. Try to increase available (max) java heap size.
Thank you for your answer!
I've had such heap problems in the past and I guess that is not the problem in this case, because heap problems are throwing a specific error message.
My vm arguments are:
-Xms2048m
-Xmx4096m
-XX:MaxPermSize=2048m
I think you are copying the same file again to the same location.
org.mule.api.DefaultMuleException: Failed to move file "C:\itm\main\datafeeds\backup\my_file.xml" to "C:\itm\main\datafeeds\process\my_file.xml". The file might already exist.
Can You post your full xml config to help further.
Other alternative would be to use file outbound and write back the payload into output file. For just moving files there could be many other alternatives like batch/shell script etc.
Thank You for your help!
Here ist the whole flow:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:mulerequester="http://www.mulesoft.org/schema/mule/mulerequester" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:wmq="http://www.mulesoft.org/schema/mule/ee/wmq" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns:file="http://www.mulesoft.org/schema/mule/file" 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/file http://www.mulesoft.org/schema/mule/file/current/mule-file.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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/wmq http://www.mulesoft.org/schema/mule/ee/wmq/current/mule-wmq-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/mulerequester http://www.mulesoft.org/schema/mule/mulerequester/current/mule-mulerequester.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd">
<file:connector name="File" autoDelete="true" streaming="false" validateConnections="false" doc:name="File" outputAppend="true" moveToDirectory="${file.workingDir}" />
<flow name="poller_product_parse_aff_file" processingStrategy="synchronous">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="15" timeUnit="SECONDS"/>
<db:select config-ref="MYSQL_GENERIC_CFG" doc:name="Database">
<db:parameterized-query><![CDATA[SELECT COUNT(*) AS numOfRecords FROM mule_product]]></db:parameterized-query>
</db:select>
</poll>
<choice doc:name="Choice">
<when expression="#[payload.get(0).numOfRecords < 1000]">
<logger message="#[System.getProperty('line.separator')] ############################ Database is free, so start parsing next xml file ###########################:: #[flowVars.fileRequesterUrl]" level="TRACE" doc:name="Logger"/>
<mulerequester:request resource="${file.RequesterUrl}" timeout="30000" doc:name="Mule Requester"/>
<choice doc:name="Choice">
<when expression="#[payload != null && payload.size()>0]">
<logger message="#[System.getProperty('line.separator')] +++ DB is free and file was found" level="TRACE" doc:name="Logger"/>
<flow-ref name="product_parse_aff_file_to_dbFlow" doc:name="product_parse_aff_file_to_dbFlow"/>
</when>
<otherwise>
<logger message="#[System.getProperty('line.separator')] --- File not found or filesize is zero: #[payload]" level="TRACE" doc:name="Logger"/>
</otherwise>
</choice>
</when>
<when expression="">
<logger message="::::::::::::::: start of parsing the files:no fo records in db :::::>#[payload.get(0).numOfRecords]" level="TRACE" doc:name="Logger"/>
</when>
<otherwise>
<logger message="::::::::::file processing not started as the condition is not met i.e SELECT COUNT(*) AS numOfRecords FROM mule_product >1000" level="TRACE" doc:name="Logger"/>
</otherwise>
</choice>
</flow>
....
</mule>
I'm using the 3.0.0.201609092037 version (the latest one) of the Box connector as I don't find any documentation or sample code to get the refresh token, I wrote my own flow to get it.
I achieve to execute the Authorize action with the connector and then my intension is to send a request to Box API to this url: https://api.box.com/oauth2/token in order to get an access_token and also a refresh_token (I got the API info from here https://docs.box.com/reference#token).
The problem is, once my flow has been authorized and I get access_code, and I'm using it to send it to Box I always am receiving this:
{
"error": "invalid_grant",
"error_description": "The authorization code has expired"
}
I checked all the information and I it suppose to be good, the response I'm expecting is:
{
"access_token": "T9cE5asGnuyYCCqIZFoWjFHvNbvVqHjl",
"expires_in": 3600,
"restricted_to": [],
"token_type": "bearer",
"refresh_token": "J7rxTiWOHMoSC1isKZKBZWizoRXjkQzig5C6jFgCVJ9bUnsUfGMinKBDLZWP9BgR"
}
So I'll be able to store those properties and refresh the token if is needed.
Here how my flow looks like:
and Here my XML definition:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:tls="http://www.mulesoft.org/schema/mule/tls" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:objectstore="http://www.mulesoft.org/schema/mule/objectstore" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:box="http://www.mulesoft.org/schema/mule/box" 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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/box http://www.mulesoft.org/schema/mule/box/current/mule-box.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/objectstore http://www.mulesoft.org/schema/mule/objectstore/current/mule-objectstore.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/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/tls http://www.mulesoft.org/schema/mule/tls/current/mule-tls.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration" protocol="HTTPS">
<tls:context>
<tls:key-store type="jks" path="OBKeytore.jks" keyPassword="password" password="password"/>
</tls:context>
</http:listener-config>
<box:config-with-oauth name="Box__OAuth_2_0" clientId="my_client_id" clientSecret="My_secret" doc:name="Box: OAuth 2.0">
<box:oauth-callback-config domain="localhost" localPort="8081" remotePort="8081" path="callback" connector-ref="HTTP_Listener_Configuration"/>
<box:oauth-store-config objectStore-ref="_defaultInMemoryObjectStore"/>
</box:config-with-oauth>
<objectstore:config name="ObjectStore__Connector" partition="BoxAccessToken" persistent="true" doc:name="ObjectStore: Connector"/>
<http:request-config name="HTTP_Request_Configuration" host="api.box.com" port="443" basePath="/oauth2/" doc:name="HTTP Request Configuration" protocol="HTTPS"/>
<tls:context name="TLS_Context" doc:name="TLS Context">
<tls:trust-store path="OBKeytore.jks" password="password" type="jks"/>
<tls:key-store type="jks" path="OBKeystore.jks" keyPassword="password" password="password"/>
</tls:context>
<flow name="Authorize">
<http:listener config-ref="HTTP_Listener_Configuration" path="/authorize" doc:name="HTTP"/>
<box:authorize config-ref="Box__OAuth_2_0" doc:name="Box"/>
<flow-ref name="GenerateAcessToken" doc:name="GenerateAcessToken"/>
</flow>
<flow name="GenerateAcessToken">
<logger message="Acess Token: #[flowVars['_oauthVerifier']]" level="INFO" doc:name="Logger"/>
<set-payload value="#[[
'grant_type' :'authorization_code',
'code':flowVars['_oauthVerifier'],
'client_id':'my_client_id',
'client_secret':'my_secret'
]]" doc:name="Set Payload"/>
<http:request config-ref="HTTP_Request_Configuration" path="token" method="POST" doc:name="HTTP">
<http:success-status-code-validator values="200,400"/>
</http:request>
<object-to-string-transformer doc:name="Object to String"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<catch-exception-strategy doc:name="Catch Exception Strategy">
<object-to-string-transformer doc:name="Object to String"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</flow>
</mule>
I have to mention that I already tried to use POSTMAN with the same params, replacing the code (as far I know it is valid for 30 secs) and getting the same response.
Here some more information:
Anypoint Studio version: 6.1.1
Server Runtime: 3.8.1 EE
It sounds like the OAuth authorization configuration of the HTTP requester might be required as described for a Mule Server trying to access the resources that belong to a Box user and that are held in a Box server: https://docs.mulesoft.com/mule-user-guide/v/3.8/authentication-in-http-requests
http://mulesoft.github.io/box-connector/3.0.0/apidocs/box-apidoc.html#_oauth_2_0_server_to_server and this example of managing OAuth tokens that uses Box as an example might be worth a look if you haven't seen it.
I am setting some outbound properties in the message prior to sending the payload to a JMS queue, and I wanted to test that those properties are properly set in the message prior to sending it out to the JMS queue.
I thought about using an MUnit Spy before the JMS Outbound Endpoint, but the spy is only capable of validating the session properties, invocation properties, and the payload. Is there another way that I can achieve this using MUnit XML?
I created a mini mule project to illustrate the issue further. The code is provided below. Essentially it is just a flow that calls a sub-flow that sets outbound properties in a mule message, and the MUnit has a spy that asserts that the outbound properties are set in the mule message after the sub-flow is called. However, the MUnit Spy doesn't seem to have access to the mule outbound properties. I would like to know if there is another way around this at this time. I know that the docs specify that the spy is only capable of validating session and invocation properties, and the payload at this time. Any suggestion is welcome.
Sandbox.xml - Main Mule File
<?xml version="1.0" encoding="UTF-8"?>
<mule 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/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<flow name="outbound-props-flow">
<flow-ref name="outbound-props-sub-flow" doc:name="Call outbound-props-sub-flow"/>
<logger message="#[message]" level="INFO" doc:name="Log Message"/>
</flow>
<sub-flow name="outbound-props-sub-flow">
<set-property propertyName="outbound-prop-1" value="test1" doc:name="set-outbound-prop-1"/>
<set-property propertyName="outbount-prop-2" value="test2" doc:name="set-outbound-prop-2"/>
</sub-flow>
</mule>
MUnit File - Testing the Main Flow
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:mock="http://www.mulesoft.org/schema/mule/mock" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:munit="http://www.mulesoft.org/schema/mule/munit" 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" 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:sandbox.xml"/>
</spring:beans>
<munit:test name="outbound-props-flow-outbound-props-flowTest" description="Test">
<mock:spy messageProcessor="mule:sub-flow" doc:name="Spy">
<mock:with-attributes>
<mock:with-attribute name="name" whereValue="#[matchContains('outbound-props-sub-flow')]"/>
</mock:with-attributes>
<mock:assertions-after-call>
<logger message="Message in SPY Module: #[message]" level="INFO" doc:name="Log Message in Spy"/>
<munit:assert-on-equals message="outbound-props-1 is not set properly" expectedValue="test1" actualValue="#[message.outboundProperties['outbound-prop-1']]" doc:name="Assert outbound-props-1 is set properly"/>
<munit:assert-on-equals message="outbound-props-2 is not set properly" expectedValue="test1" actualValue="#[message.outboundProperties['outbound-prop-2']]" doc:name="Assert outbound-props-2 is set properly"/>
</mock:assertions-after-call>
</mock:spy>
<flow-ref name="outbound-props-flow" doc:name="Flow-ref to outbound-props-flow"/>
</munit:test>
</mule>
Thanks,
Juan
Don't use 'Spy' for this, it has some limitations. Take a look to the documentation:
https://docs.mulesoft.com/mule-user-guide/v/3.7/the-spy-message-processor#defining-spy-actions
You could simply add the asserts after the flow ref.
<munit:test name="outbound-props-flow-outbound-props-flowTest" description="Test">
<flow-ref name="outbound-props-flow" doc:name="Flow-ref to outbound-props-flow"/>
<munit:assert-on-equals message="outbound-props-1 is not set properly" expectedValue="test1" actualValue="#[message.outboundProperties['outbound-prop-1']]" doc:name="Assert outbound-props-1 is set properly"/>
<munit:assert-on-equals message="outbound-props-2 is not set properly" expectedValue="test2" actualValue="#[message.outboundProperties['outbound-prop-2']]" doc:name="Assert outbound-props-2 is set properly"/>
</munit:test>
Hi I'm playing around with a SOAP request, I am having trouble with the cxf proxy client. I'm basically sending a soap request to the http endpoint, removing the SOAP envelope, then trying to add it back it back on with the proxy client.
I'm expecting to get an unathorized response (as I'm removing the wsse headers).
However, I get the following soap response: "Response code 500 mapped as failure. Message payload is of type: BufferInputStream"
and the console logs the following (Note this is only the start of it)
WARN 2015-05-13 12:38:28,886 [[sandbox2].HTTP_Listener_Configuration.worker.01] org.apache.cxf.phase.PhaseInterceptorChain: Interceptor for {http://support.cxf.module.mule.org/}ProxyService#{http://support.cxf.module.mule.org/}invoke has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Response code 500 mapped as failure. Message payload is of type: BufferInputStream
at org.mule.module.cxf.transport.MuleUniversalConduit$2.handleMessage(MuleUniversalConduit.java:194) ~[mule-module-cxf-3.6.1.jar:3.6.1]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263) ~[cxf-api-2.5.9.jar:2.5.9]
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:531) ~[cxf-rt-core-2.5.9.jar:2.5.9]
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:462) ~[cxf-rt-core-2.5.9.jar:2.5.9]
Here is my flow
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" 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.6.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/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8086" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" host="localhost" port="8080" basePath="my-app/RetrieveAct.svc" doc:name="HTTP Request Configuration"/>
<flow name="myFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<logger message="message received #[payload] " level="INFO" doc:name="Logger"/>
<cxf:proxy-service namespace="PfPolicyService" payload="body" doc:name="CXF"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<cxf:proxy-client payload="body" doc:name="CXF"/>
<response>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</response>
<http:request config-ref="HTTP_Request_Configuration1" path="http://localhost:8080/my-app/RetrieveAct.svc" method="POST" doc:name="HTTP">
<http:request-builder>
<http:header headerName="soapAction" value="getUserAcct"/>
</http:request-builder>
</http:request>
</flow>
</mule>
Can anyone explain what I am doing wrong and how to correct the issue?
Thanks
The issue you're experiencing is because your modification of the SOAP request is ending up as an invalid SOAP request, therefore the server cannot parse it and it is returning a 500 http status code.
You can use CXF's logging interceptors to be able to inspect the final result of what you're sending.
Your mule flow seems okey to me, the proxied service might blow up for all sorts of reasons.
Add logging interceptors to the proxy client and see whether this enables you to pinpoint the issue:
<cxf:proxy-client payload="body">
<cxf:inInterceptors>
<spring:bean class="org.apache.cxf.interceptor.LoggingInInterceptor">
<spring:property name="prettyLogging" value="true" />
</spring:bean>
</cxf:inInterceptors>
<cxf:outInterceptors>
<spring:bean class="org.apache.cxf.interceptor.LoggingOutInterceptor">
<spring:property name="prettyLogging" value="true" />
</spring:bean>
</cxf:outInterceptors>
</cxf:proxy-client>
Or alternatively, use TPCMon to capture network traffic.
Setting up a service mock and proper test case first would be a good sanity check, before doing integration testing.