I'm developing an integration using Mule ESB which needs to read a binary file (.zip) from the file system and create it as an attachment in Salesforce. However, I'm not able to get this work and I'm getting the following error:
INFO 2016-03-11 13:55:47,338 [[sfdc].File.receiver.01] org.mule.transport.file.FileMessageReceiver: Lock obtained on file: /Users/aaa/Desktop/temp/files/test.zip
INFO 2016-03-11 13:55:47,345 [[sfdc].sfdcFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: Payload = org.mule.transport.file.ReceiverFileInputStream#4f0870aa
INFO 2016-03-11 13:55:47,348 [[sfdc].sfdcFlow.stage1.02] com.mulesoft.weave.mule.utils.MuleWeaveFactory$: MimeType was not resolved 'application/zip' delegating to Java.
ERROR 2016-03-11 13:55:47,367 [[sfdc].sfdcFlow.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy:
Message : Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*', encoding='null'}" to "CollectionDataType{type=java.util.List, itemType=java.lang.Object, mimeType='*/*'}".
Type : org.mule.api.transformer.TransformerException
Code : MULE_ERROR-236
JavaDoc : http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html
Exception stack is:
1. Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*', encoding='null'}" to "CollectionDataType{type=java.util.List, itemType=java.lang.Object, mimeType='*/*'}". (org.mule.api.transformer.TransformerException)
org.mule.registry.MuleRegistryHelper:248 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
Root Exception stack trace:
org.mule.api.transformer.TransformerException: Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*', encoding='null'}" to "CollectionDataType{type=java.util.List, itemType=java.lang.Object, mimeType='*/*'}".
Here is the configuration file.
<sfdc:config name="Salesforce__Basic_Authentication" username="test#test.com.staging" password="password" securityToken="token" url="https://test.salesforce.com/services/Soap/u/34.0" doc:name="Salesforce: Basic Authentication"/>
<file:connector name="File" readFromDirectory="/Users/aaa/Desktop/temp/files" autoDelete="true" streaming="true" validateConnections="true" doc:name="File"/>
<flow name="sfdcFlow">
<file:inbound-endpoint path="/Users/aaa/Desktop/temp/files" connector-ref="File" responseTimeout="10000" doc:name="File"/>
<logger message="Payload = #[payload]" level="INFO" doc:name="Logger"/>
<object-to-byte-array-transformer doc:name="Object to Byte Array"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
ParentId: "b2U7A0B01054OyZ",
Name: "Test Name",
Description: "Test Descr",
Body: payload
}]]></dw:set-payload>
</dw:transform-message>
<sfdc:create config-ref="Salesforce__Basic_Authentication" type="Attachment" doc:name="Salesforce" />
</flow>
I checked the Anypoint exchange and googled, but all the pointers that I'm getting is geared towards text files (like CSVs). Appreciate if someone can share a working example to read a binary file and create it as an attachment in Salesforce (can attach to any object like case object).
I'm using Anypoint Studio 5.4.1 with Mule runtime 3.7.3 EE.
Edit: I was able to resolve the issue. Basically, as #david said, the create method takes a collection and I was not passing it as a collection. Here is the updated code (just the dataweave part):
[
{
ParentId: "b2U7AB010540yZ",
Name: "Test Name",
Description: "Test Descr",
Body: payload
}
]
Note the open and close square brackets. Thanks #david.
What I understand from the SFDC Connector doc, is that the create method expects a collection of objects.
But you're passing a map to it, thus this exception:
Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*', encoding='null'}" to "CollectionDataType{type=java.util.List, itemType=java.lang.Object, mimeType='*/*'}"
Try adding the map you create in dw:transform-message to a list, using a transformer for this, and it should work.
Related
Requirement is to bring CXF service in mule.
As per my knowledge i tried creating the configuration in mule but getting an error as shown below.
Exception while executing:
(payload.ns0#ValidateVIN.*ns0#VIN map ((vIN , indexOfVIN) -> {
^
Type mismatch for 'map' operator
found :null, :function
required :array, :function.
Attaching the code below.
<?xml version="1.0" encoding="UTF-8"?>
<mule ... >
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="9009" basePath="Mule" doc:name="HTTP Listener Configuration"/>
<cxf:configuration name="Autoprefill_CXF_Configuration" enableMuleSoapHeaders="true" initializeStaticBusInstance="true" doc:name="CXF Configuration"/>
<flow name="autoprefillFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/VINService" allowedMethods="POST" doc:name="HTTP"/>
<logger message="#[message.payloadAs(String)]" level="INFO" doc:name="Logger"/>
<dw:transform-message doc:name="Transform Message" metadata:id="566ab616-f256-4763-af42-82d4cbbcc277">
<dw:input-payload mimeType="application/xml"/>
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace ns0 http://www.pwc.com/vin
---
{
ns0#ValidateVIN: {
(payload.ns0#ValidateVIN.*ns0#VIN map ((vIN , indexOfVIN) -> {
ns0#VIN: vIN
}))
}
}]]></dw:set-payload>
</dw:transform-message>
<cxf:simple-client operation="validateVIN" serviceClass="autoprefill.VINPort" doc:name="CXF"/>
<logger message="#[message.payloadAs(String)]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
I tried removing the message transform property, but that time i got the below error
java.lang.String cannot be cast to java.util.Collection. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor
The service is expecting a list of string. Im not sure how that can be done in mule. Any help will be much appreciated.
The problem is in the Transform Message component.
The map function is expecting an array of data (collection of data), but it did not receive any value.
I suggest to check the payload before Transform Message component. Perhaps payload is not in expected format. If you can share the payload (or full logs at least) here, I can help you with the transformation.
Hej,
I'm new in MULE, I try to learn "how to" following examples from Mule's sida: https://www.mulesoft.com/exchange#!/sending-csv-email-smtp?searchTerm=email
I think I did everything well, project is deploing good, but when file is taken exception is thrown and I'v got communicate:
Exception stack is:
1. Cannot coerce a :binary to a :array (com.mulesoft.weave.model.values.coercion.exception.UnsupportedTypeCoercionException)
com.mulesoft.weave.model.values.formatting.ArrayFormatTypeCoercionValue:31 (null)
2. Exception while executing:
payload map {
^
Cannot coerce a :binary to a :array (com.mulesoft.weave.mule.exception.WeaveExecutionException)
com.mulesoft.weave.mule.WeaveMessageProcessor:124 (null).
Abybody have idea what's happened. Anybody had same problem with that example?
Use the following mimeType in your DataWeave :- <dw:input-payload doc:sample="list_csv.csv" mimeType="application/csv"/>
So, the full code will be some thing like as follows:-
<smtp:gmail-connector doc:name="Gmail" name="Gmail" validateConnections="true"/>
<flow name="csv-to-smtpFlow">
<file:inbound-endpoint doc:name="Poll files" metadata:id="a75d5954-7fb4-4721-85f6-7ee66b793750" path="E:\test" responseTimeout="10000"/>
<dw:transform-message doc:name="Transform CSV to Map" metadata:id="84d175de-b3c6-4480-af9d-150e736f051e">
<dw:input-payload doc:sample="list_csv.csv" mimeType="application/csv"/>
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
payload map {
name: $.name,
orderId: $.orderId,
pricePerUnit: $.pricePerUnit as :number,
units: $.units as :number,
totalPrice: ($.units * $.pricePerUnit ) as :number
}]]></dw:set-payload>
</dw:transform-message>
<logger doc:name="Log the processed objects" level="INFO" message="Processing objects: #[payload]"/>
<smtp:outbound-endpoint connector-ref="Gmail" doc:name="Send an email via SMTP" from="${mail.from}" host="${smtp.host}" password="${smtp.password}" port="587" responseTimeout="10000" subject="${mail.subject}" to="${mail.to}" user="${smtp.user}"/>
</flow>
This will solve your issue
I am receiving a JSON request with 3 attribute and one of the attribute is content of image which is base64 in string format. After receiving this request I am creating a Salesforce attachment using Salesforce connector.
Now when I test this via my local Anypoint Studio everything is fine, however after deploying to Cloudhub the fileContent (Image content) is getting truncated to 8192 bytes and creating the attachment as corrupted.
I can see API is receiving the content since message content length is 38820 (both local and Cloudhub), and it looks like message is getting lost after the Message Transformation, and code is as follows:
<processor-chain doc:name="Processor Chain">
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
accountId : payload.accountId,
name : 'MyProfilePicture',
ContentType: payload.contentType,
fileContent : payload.fileContent
}]]></dw:set-payload>
</dw:transform-message>
<set-session-variable variableName="accountId" value="#[payload.accountId]" doc:name="Session Variable - accountId"/>
<set-session-variable variableName="contentType" value="#[payload.ContentType]" doc:name="Session Variable - contentType"/>
<logger message="payload.fileContent Before Conversion size #[payload.fileContent.length()], data:#[payload.fileContent] " level="INFO" doc:name="Logger"/>
<set-session-variable variableName="fileContent" value="#[(org.apache.commons.codec.binary.Base64.decodeBase64(payload.fileContent))]" mimeType="binary/octet-stream" doc:name="Session Variable - fileContent"/>
<dw:transform-message metadata:id="1676949a-75ba-4e51-82ac-b5788a8e87dc" doc:name="Transform Message">
<dw:input-payload/>
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
[{
Name: 'MyProfilePicture',
ParentId: sessionVars.accountId,
ContentType: sessionVars.contentType,
Body: sessionVars.fileContent
}]]]></dw:set-payload>
</dw:transform-message>
<logger message="Payload after Transform Message: #[payload]" level="INFO" doc:name="Logger"/>
<sfdc:create config-ref="Salesforce__Cfg" type="Attachment" doc:name="Salesforce">
<sfdc:objects ref="#[payload]"/>
</sfdc:create>
</processor-chain>
Could anyone please help on this? why when I deploy to Cloudhub it is only processing 8192 bytes?
Thanks,
Thomas
This can be fixed by switching to the deprecated DataMapper for the huge base64 transforms.
In mule 3.8, when I use file connector to process text file , I am getting exception as below, please help.
Here is flow xml
file:connector name="File" autoDelete="true" streaming="true" validateConnections="true" doc:name="File"/>
flow name="DW-FixedWidth-Processing">
file:inbound-endpoint path="D:/mule/input" connector-ref="File" responseTimeout="10000" doc:name="File"/>
file:file-to-string-transformer doc:name="File to String"/>
dw:transform-message doc:name="Transform Message">
dw:input-payload />
dw:set-payload><![CDATA[%dw 1.0
%output application/csv header=false
---
((payload splitBy /\n/)[0..8]) map {
location:trim $[0..14],
sku:trim $[15..39],
dtc:trim $[40..42],
tt:trim $[43..44],
txnqty:trim $[45..54],
um:trim $[55..56],
rcd:trim $[57..59],
te:trim $[60..89],
ul:trim $[90..104],
date:trim $[105..114],
time:trim $[115..120]
} ]]>
dw:set-payload>
dw:transform-message>
logger message="#[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
file:outbound-endpoint path="D:/mule/output" responseTimeout="10000" doc:name="File"/>
Exception
Root Exception stack trace:
java.lang.IllegalStateException: No schema set at
com.mulesoft.weave.module.flatfile.FlatFileSettings.loadSchema(FlatFileSettings.scala:45)
at
com.mulesoft.weave.module.flatfile.FlatFileReader.ffParser(FlatFileReader.scala:42)
When you disable streaming in the file connector, you no longer need the
<object-to-string/>
You can configure DataWeave to use a flat file schema, as already said in the other answer.
When you want to use it the way, you have to tell the correct mime type, in this case it is
application/java
You can do this on any message processor before the DataWeave, in this case the file:inbound-endpoint. Or you can do this in the DataWeave itself (unfortunately this is only visible when you switch Studio to XML).
For me everything worked with the following flow:
<file:connector name="File" autoDelete="false" streaming="false" validateConnections="true" doc:name="File"/>
<flow name="dw-testFlow">
<file:inbound-endpoint path="in" moveToDirectory="processed" connector-ref="File" responseTimeout="10000" mimeType="application/java" doc:name="File">
<file:filename-regex-filter pattern=".*\.txt" caseSensitive="true"/>
</file:inbound-endpoint>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
((payload splitBy /\n/)) map {
location:trim $[0..14],
sku:trim $[15..39],
dtc:trim $[40..42],
tt:trim $[43..44],
txnqty:trim $[45..54],
um:trim $[55..56],
rcd:trim $[57..59],
te:trim $[60..89],
ul:trim $[90..104],
date:trim $[105..114],
time:trim $[115..120]
}
]]></dw:set-payload>
</dw:transform-message>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>
The result of the DataWeave is a List of HashMap.
DW does not currently support mapping from an unstructured string, even if you declare MIME Type = text/plain upstream and you set the input payload metadata to String in the Transform Message processor.
The data formats supported (as per Mule documentation) are Java, XML, JSON, CSV, Flat File, Excel, Fixed Width, and Cobol copybook.
The case here is clearly a Fixed Width format.
#Prasad, generally the error No Schema Set at throws when the input mime type is no set. In your case, it seems like you are dealing with fixed width data hence you either define a fixed width schema. this article might help.
Instead of going to dataweave just use an groovy component to split payload by new line('\n').
Don't use file to string transformer it kills the Java-VM.
Also kindly brief what you need to achieve finally in your question.
Cheers!
I tried to integrate linkedin with mule. I successfully authorize user and also get my profile information.
But I couldn't change my current status.. And I couldn't get user updates.
I got following error
Message : Could not find a transformer to transform "SimpleDataType{type=java.lang.String, mimeType='*/*'}" to "CollectionDataType{type=java.util.List, itemType=java.lang.Object, mimeType='*/*'}".
Code : MULE_ERROR-65237
--------------------------------------------------------------------------------
Exception stack is:
1. Could not find a transformer to transform "SimpleDataType{type=java.lang.String, mimeType='*/*'}" to "CollectionDataType{type=java.util.List, itemType=java.lang.Object, mimeType='*/*'}". (org.mule.api.transformer.TransformerException)
org.mule.registry.MuleRegistryHelper:268 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.api.transformer.TransformerException: Could not find a transformer to transform "SimpleDataType{type=java.lang.String, mimeType='*/*'}" to "CollectionDataType{type=java.util.List, itemType=java.lang.Object, mimeType='*/*'}".
at org.mule.registry.MuleRegistryHelper.lookupTransformer(MuleRegistryHelper.java:268)
at org.mule.module.linkedin.processors.AbstractExpressionEvaluator.transform(AbstractExpressionEvaluator.java:279)
at org.mule.module.linkedin.processors.AbstractExpressionEvaluator.evaluateAndTransform(AbstractExpressionEvaluator.java:202)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
My flow is as follow
<flow name="linkedinFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8090" path="auth" doc:name="HTTP"/>
<linkedin:authorize config-ref="LinkedIn" doc:name="LinkedIn"/>
</flow>
<flow name="linkedinFlow2">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8090" path="userupdates" doc:name="HTTP"/>
<linkedin:get-user-updates config-ref="LinkedIn" doc:name="LinkedIn">
<linkedin:update-types ref="#[payload]"/>
</linkedin:get-user-updates>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
How can I get user user updates??
I also Tried following code
<flow name="linkedinFlow3">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8090" path="userupdates1" doc:name="HTTP" />
<linkedin:get-network-updates config-ref="LinkedIn" start="10"
count="20"
showHiddenMembers="true"
startDate="2011-08-10T00:00:00-00:00"
endDate="2015-05-10T00:00:00-00:00">
<linkedin:update-types>
<linkedin:update-type>PROFILE_UPDATE</linkedin:update-type>
<linkedin:update-type>RECOMMENDATION_UPDATE</linkedin:update-type>
</linkedin:update-types>
</linkedin:get-network-updates>
</flow>
Then I got following error
Exception stack is:
1. Access to network denied (com.google.code.linkedinapi.client.LinkedInApiClientException)
com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient:2088 (null)
2. Failed to invoke getNetworkUpdates. Message payload is of type: String (org.mule.api.MessagingException)
org.mule.module.linkedin.processors.GetNetworkUpdatesMessageProcessor:189 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
I also change the scope rw_nus+r_basicprofile but got 403 error my page didn't authenticate
If I used rw_company_admin scope I can authenticate succesfully but didn't get success in geting user updates
How can I solve this problem?please help