Google calendar mule connector is not working - mule

I'm working with Mule and Google Connectors.
I've tried the following code:
<mule xmlns:objectstore="http://www.mulesoft.org/schema/mule/objectstore" xmlns:json="http://www.mulesoft.org/schema/mule/json"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:google-calendars="http://www.mulesoft.org/schema/mule/google-calendars" 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.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/objectstore http://www.mulesoft.org/schema/mule/objectstore/1.0/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/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/google-calendars http://www.mulesoft.org/schema/mule/google-calendars/current/mule-google-calendars.xsd">
<google-calendars:config-with-oauth name="Google_Calendars"
consumerKey="CUNSUMER_KEY" consumerSecret="CONSUMER_SECRET" doc:name="Google Calendars"
applicationName="My Project">
<google-calendars:oauth-callback-config domain="localhost" localPort="8082" path="oauth2callback"
remotePort="8082" />
<google-calendars:oauth-store-config objectStore-ref="ObjectStoreBean" />
</google-calendars:config-with-oauth>
<spring:beans>
<spring:bean id="ObjectStoreBean" name="ObjectStoreBean" class="org.mule.util.store.SimpleMemoryObjectStore" />
</spring:beans>
<objectstore:config name="ObjectStore" doc:name="ObjectStore" objectStore-ref="ObjectStoreBean" />
<flow name="authorizationAndAuthenticationFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8080" path="oauth-authorize"
doc:name="HTTP" />
<google-calendars:authorize config-ref="Google_Calendars" doc:name="Google Calendars" />
<objectstore:store config-ref="ObjectStore" doc:name="ObjectStore" key="accessTokenId" overwrite="true"
value-ref="#[flowVars['OAuthAccessTokenId']]" />
<set-payload value="You have successfully authorized the connector" doc:name="Set Payload" />
<catch-exception-strategy doc:name="Catch Exception Strategy">
<set-payload value="An error has occurred authorizing the connector" doc:name="Set Payload" />
</catch-exception-strategy>
</flow>
<flow name="getAcl">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="get" doc:name="HTTP" />
<logger level="INFO" doc:name="Logger" />
<enricher target="#[flowVars['accessTokenId']]" doc:name="Message Enricher">
<objectstore:retrieve config-ref="ObjectStore" key="accessTokenId" defaultValue-ref="#['']" doc:name="Get AccessToken" />
</enricher>
<expression-filter expression="#[flowVars['accessTokenId'] != '']" doc:name="Is Access Token Set" />
<google-calendars:get-calendar-by-id id="CALENDAR_ID" config-ref="Google_Calendars" doc:name="Google Calendars" accessTokenId="#[flowVars['accessTokenId']]" />
<json:object-to-json-transformer doc:name="Object to JSON" />
</flow>
</mule>
I can get the OAuth2 Authorization just fine, but when I try to get a Calendar I get:
Exception stack is:
1. com.google.common.primitives.UnsignedInteger.asUnsigned(I)Lcom/google/common/primitives/UnsignedInteger; (java.lang.NoSuchMethodError)
com.google.api.client.util.Data:81 (null)
2. com.google.common.primitives.UnsignedInteger.asUnsigned(I)Lcom/google/common/primitives/UnsignedInteger; (java.lang.NoSuchMethodError). Message payload is of type: NullPayload (org.mule.api.MessagingException)
org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
********************************************************************************
Root Exception stack trace:
java.lang.NoSuchMethodError: com.google.common.primitives.UnsignedInteger.asUnsigned(I)Lcom/google/common/primitives/UnsignedInteger;
at com.google.api.client.util.Data.<clinit>(Data.java:81)
at com.google.api.client.util.FieldInfo.<init>(FieldInfo.java:131)
at com.google.api.client.util.FieldInfo.of(FieldInfo.java:104)
at com.google.api.client.util.ClassInfo.<init>(ClassInfo.java:181)
at com.google.api.client.util.ClassInfo.of(ClassInfo.java:92)
at com.google.api.client.util.ClassInfo.<init>(ClassInfo.java:175)
at com.google.api.client.util.ClassInfo.of(ClassInfo.java:92)
at com.google.api.client.util.GenericData.<init>(GenericData.java:79)
at com.google.api.client.util.GenericData.<init>(GenericData.java:61)
at com.google.api.client.http.json.JsonHttpRequest.<init>(JsonHttpRequest.java:69)
at com.google.api.services.calendar.CalendarRequest.<init>(CalendarRequest.java:44)
at com.google.api.services.calendar.Calendar$Calendars$Get.<init>(Calendar.java:1372)
at com.google.api.services.calendar.Calendar$Calendars.get(Calendar.java:1358)
at org.mule.module.google.calendar.GoogleCalendarConnector.getCalendarById(GoogleCalendarConnector.java:273)
at org.mule.module.google.calendar.processors.GetCalendarByIdMessageProcessor$1.process(GetCalendarByIdMessageProcessor.java:119)
at org.mule.security.oauth.process.ProcessCallbackProcessInterceptor.execute(ProcessCallbackProcessInterceptor.java:24)
at org.mule.security.oauth.process.RefreshTokenProcessInterceptor.execute(RefreshTokenProcessInterceptor.java:55)
at org.mule.security.oauth.process.RefreshTokenProcessInterceptor.execute(RefreshTokenProcessInterceptor.java:24)
at org.mule.security.oauth.process.ManagedAccessTokenProcessInterceptor.execute(ManagedAccessTokenProcessInterceptor.java:75)
at org.mule.security.oauth.process.ManagedAccessTokenProcessInterceptor.execute(ManagedAccessTokenProcessInterceptor.java:24)
at org.mule.security.oauth.process.ManagedAccessTokenProcessTemplate.execute(ManagedAccessTokenProcessTemplate.java:42)
at org.mule.module.google.calendar.processors.GetCalendarByIdMessageProcessor.doProcess(GetCalendarByIdMessageProcessor.java:105)
at org.mule.devkit.processor.DevkitBasedMessageProcessor.process(DevkitBasedMessageProcessor.java:88)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.processor.AbstractFilteringMessageProcessor.process(AbstractFilteringMessageProcessor.java:40)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.processor.AsyncInterceptingMessageProcessor.process(AsyncInterceptingMessageProcessor.java:102)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.construct.DynamicPipelineMessageProcessor.process(DynamicPipelineMessageProcessor.java:54)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.interceptor.AbstractEnvelopeInterceptor.process(AbstractEnvelope...
*******************************************************************************`
I've tried with Mule 3.5.2 and the Google Calendar Connector v.1.1.1 and also the v.1.2.4 but still not working
Edit:
Actually I found out that Google Connectors are referring to guava-12.0.jar but the Mule Server Library refers to guava-16.0.1.jar, so I think when I'm running the app the actual jar that is been use is guava-16.0.1.jar where the method doesn't exist anymore.

Some code somewhere (see my comment below your question) depends on pre-15.0 Guava, where the deprecated asUnsigned has been removed from UnsignedInteger.
You can try to force Guava to 14.0.1 by adding this into your project's pom.xml:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>14.0.1</version>
</dependency>
This downgrade may of course break other things elsewhere, but it's worth a shot (until we figure out where is the code that requires this removed method and file an issue with the relevant project).
EDIT: It turns out Mule brings a more recent version of Guava to the classpath. So you'll need to configure the application classloader to use the version of Guava you embed in the app zip itself. Add the following in mule-deploy.properties:
loader.override=-com.google.common.primitives.UnsignedInteger
Reference: https://developer.mulesoft.com/docs/display/35X/Classloader+Control+in+Mule

Related

How to read file in middle of the flow

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" />

Sending Multipart Requests in mule

I have an Database connector from the selected data i use to create a file and I want to do HTTP post with file (created from the selected data in csv) along with other data (text) as attached in the screenshot. According to the mule documentation, the payload must be an outbound attachment which I am doing by using Set Attachment property. With this approach, I am setting the Content-Type for one of my attachment as application/CVS (as my file is of CVS type) and as text/plain for the other parameter. Any thoughts on achieving this? I have attached the screenshot of how the request looks like in Postman.
Below is the config XML..!!
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd">
<spring:beans>
<spring:bean id="CSFMDataSource" name="CSFMDataSource" class="oracle.jdbc.pool.OracleDataSource">
<spring:property name="user" value="XXCCS_OSB_O"/>
<spring:property name="password" value="OrG2_BtN"/>
<spring:property name="dataSourceName" value="ds"/>
<spring:property name="URL" value="jdbc:oracle:thin:#(DESCRIPTION=(CONNECT_TIMEOUT=5)(TRANSPORT_CONNECT_TIMEOUT=3)(RETRY_COUNT=1)(ADDRESS_LIST=(LOAD_BALANCE=ON)(FAILOVER=ON)(ADDRESS=(PROTOCOL=TCP)(HOST=scan-nprd-2023)(PORT=1541)))(CONNECT_DATA=(SERVICE_NAME=DV3CSF_SRVC_OTH.cisco.com)(SERVER=DEDICATED)))"/>
</spring:bean>
</spring:beans>
<db:oracle-config name="Oracle_Configuration" dataSource-ref="CSFMDataSource" doc:name="Oracle Configuration"/>
<http:request-config name="HTTP_Request_Configuration" host="tools-stage.cisco.com" port="80" doc:name="HTTP Request Configuration"/>
<flow name="testFlow">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="1" timeUnit="MINUTES"/>
<logger message="Log-1" level="INFO" doc:name="Logger"/>
</poll>
<db:select config-ref="Oracle_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[SELECT sol.SW_UPG_CONTRACT_NUMBER,
sol.service_level,
sol.BILL_TO_SITE_USE_ID,
sol.SERVICE_BEGIN_DATE,
sol.SERVICE_END_DATE,
0 Net_Price,
sol.PRODUCT_ORDER_NUMBER,
sol.SERIAL_NUMBER,
sol.SW_UPG_FULFILLMENT_PID,
sol.INSTALL_SITE_USE_ID,
sii.INSTANCE_ID,
DECODE (sii.INSTANCE_ID, 'Yes', 'No') softline,
'1232' cs_cse_number,
lg.error_message
FROM apps.XXCSS_SFM_ORDER_LINES sol,
apps.XXCSS_SFM_ERROR_LOG lg,
apps.XXCSS_SFM_INSTANCE_INTERFACE sii
WHERE 1 = 1
AND sol.order_type = 'INNVO_LINE'
AND sol.entitlement_status IN ('CSFM_ERROR', 'QA_FAILED')
--AND lg.so_header_id = sol.header_id
--AND lg.so_line_id = sol.line_id
AND lg.ERROR_TYPE = 'ERROR'
AND sol.header_id = sii.so_header_id(+)
AND sol.line_id = sii.so_line_id(+)
AND lg.sfdc_case_req = 'Y'
AND lg.sfdc_case_no IS NULL]]></db:parameterized-query>
</db:select>
<dw:transform-message doc:name="Transform Message" metadata:id="38e67a04-7f03-4261-a450-72b69ae0fff1">
<dw:set-payload><![CDATA[%dw 1.0
%output application/csv
---
payload map ((payload01 , indexOfPayload01) -> {
BILL_TO_SITE_USE_ID: payload01.BILL_TO_SITE_USE_ID as :number,
CS_CSE_NUMBER: payload01.CS_CSE_NUMBER,
ERROR_MESSAGE: payload01.ERROR_MESSAGE,
INSTALL_SITE_USE_ID: payload01.INSTALL_SITE_USE_ID as :number,
INSTANCE_ID: payload01.INSTANCE_ID,
NET_PRICE: payload01.NET_PRICE as :number,
PRODUCT_ORDER_NUMBER: payload01.PRODUCT_ORDER_NUMBER,
SERIAL_NUMBER: payload01.SERIAL_NUMBER,
SERVICE_BEGIN_DATE: payload01.SERVICE_BEGIN_DATE,
SERVICE_END_DATE: payload01.SERVICE_END_DATE,
SERVICE_LEVEL: payload01.SERVICE_LEVEL,
SOFTLINE: payload01.SOFTLINE,
SW_UPG_CONTRACT_NUMBER: payload01.SW_UPG_CONTRACT_NUMBER,
SW_UPG_FULFILLMENT_PID: payload01.SW_UPG_FULFILLMENT_PID
})]]></dw:set-payload>
</dw:transform-message>
<byte-array-to-object-transformer doc:name="Byte Array to Object"/>
<set-attachment attachmentName="filedata" value="#[payload]" contentType="application/csv" doc:name="Attachment"/>
<set-attachment attachmentName="casedata" value="{ "Origin":"Web", "CaseNumber":"33315931584", "SearchCCOID":"vimerugu"}" contentType="text/plain" doc:name="Attachment"/>
<set-payload value="#[null]" doc:name="Set Payload"/>
<http:request config-ref="HTTP_Request_Configuration" path="/cvcm/was70/pwc036/caseApi/updateCaseAttach/33315931584" method="POST" doc:name="HTTP" parseResponse="false">
<http:request-builder>
<http:header headerName="Authorization" value="Basic Q1BFQ2FzZUFQSS5nZW46Y2FzZTFnZW4="/>
</http:request-builder>
</http:request>
<logger message="#[flowVars.varCaseUpdate]" level="INFO" doc:name="Logger"/>
<catch-exception-strategy doc:name="Catch Exception Strategy">
<db:insert config-ref="Oracle_Configuration" doc:name="Log_DB">
<db:parameterized-query><![CDATA[insert into XXCSS_SFM_OSB_EXECUTION_LOG (PROCESS_STATUS) values ('SFDCCaseCreationService-Exception')]]></db:parameterized-query>
</db:insert>
<db:insert config-ref="Oracle_Configuration" doc:name="SFDCCaseCreation- Exception">
<db:parameterized-query><![CDATA[insert into XXCSS_SFM_CESB_LOG_ERROR ( LOG_ERROR_ID,SERVICE_NAME,SERVICE_TYPE,SERVICE_ACTIVITY,SERVICE_PAYLOAD,LOG_ERROR_STATUS,
LOG_ERROR_MESSAGE,ERROR_CODE,ERROR_MESSAGE,ERROR_DETAILS,LOG_ERROR_SEVERITY,SUGGESTED_ACTION,NOTIFY_MAIL,NOTIFY_COUNT,ATTRIBUTE_1,
ATTRIBUTE_2,ATTRIBUTE_3,ATTRIBUTE_4,ATTRIBUTE_5,ATTRIBUTE_6,ATTRIBUTE_7,ATTRIBUTE_8,ATTRIBUTE_9,ATTRIBUTE_10,CREATED_BY,CREATION_DATE,LAST_UPDATED_BY,LAST_UPDATE_DATE,BATCH_ID)
values ('1000','SFDCCaseCreationService','SFDCCaseCreationServiceType','SFDCCaseCreationServiceActivity','SFDCCaseCreationServicePayload','ERROR','','Error_Code','Error_Message',
#[exception.getSummaryMessage()],'Critical','','NA',3,'','','','','','','','','','','SFDCCaseCreationService',sysdate,'SFDCCaseCreationService',sysdate,'1000')]]></db:parameterized-query>
</db:insert>
</catch-exception-strategy>
</flow>
</mule>
Please check if below link helps you.It tells how to read multiple files and process them.You can send them to required endpoint instead of FTP
How send a file in an HTTP request and upload it to file server via FTP in Mule

How to get refresh_token with the Box Connector in 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.

JDBC Transaction is not working as expected while using Flow-ref

In mule flow, am unable to run JDBC transactions while using Flow-Ref. The same transactional scope works, if no flow-ref is used.
any ideas ?
Here is my configuration xml.
<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:jbossts="http://www.mulesoft.org/schema/mule/jbossts" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc" 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/ee/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/jbossts http://www.mulesoft.org/schema/mule/jbossts/current/mule-jbossts.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/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
<spring:beans>
<spring:bean id="JdbcBean1" name="JdbcBean1" class="oracle.jdbc.xa.client.OracleXADataSource">
<spring:property name="user" value="${sample.db.user}"/>
<spring:property name="URL" value="jdbc:oracle:thin:#//${sample.db.host.name}:1521/${sample.db.instance.name}"/>
<spring:property name="password" value="${sample.db.password}"/>
</spring:bean>
</spring:beans>
<jbossts:transaction-manager doc:name="Transaction Manager"/>
<jdbc-ee:connector name="Database" dataSource-ref="JdbcBean1" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"/>
<flow name="jdbctransactionFlow1" doc:name="jdbctransactionFlow1">
<file:inbound-endpoint path="src/test/resources/input" moveToDirectory="src/test/resources/output" responseTimeout="10000" doc:name="File"/>
<file:file-to-string-transformer doc:name="File to String"/>
<flow-ref name="jdbctransactionFlow2" doc:name="Flow Reference"/>
<file:outbound-endpoint path="src/test/resources/outputResult" outputPattern="output.xml" responseTimeout="10000" doc:name="File"/>
</flow>
<flow name="jdbctransactionFlow2" doc:name="jdbctransactionFlow2">
<logger message="xa start" level="INFO" doc:name="Logger"/>
<transactional action="BEGIN_OR_JOIN" doc:name="Transactional">
<jdbc-ee:outbound-endpoint exchange-pattern="one-way" queryKey="updateTPCCounterType_TPC410" queryTimeout="-1" connector-ref="Database" doc:name="Database">
<jdbc-ee:transaction action="ALWAYS_JOIN"/>
<jdbc-ee:query key="updateTPCCounterType_TPC410" value="${sample.db.query.updateTPCCounterType_TPC}"/>
</jdbc-ee:outbound-endpoint>
<jdbc-ee:outbound-endpoint exchange-pattern="one-way" queryKey="insert_TPCM_POC_HEADER" queryTimeout="-1" connector-ref="Database" doc:name="Database">
<jdbc-ee:transaction action="ALWAYS_JOIN"/>
<jdbc-ee:query key="insert_TPCM_POC_HEADER" value="${sample.db.query.insert_TPCM_POC_HEADER}"/>
</jdbc-ee:outbound-endpoint>
<jdbc-ee:outbound-endpoint exchange-pattern="one-way" queryKey="insert_TPCM_POC_DETAIL" queryTimeout="-1" connector-ref="Database" doc:name="Database">
<jdbc-ee:transaction action="ALWAYS_JOIN"/>
<jdbc-ee:query key="insert_TPCM_POC_DETAIL" value="${sample.db.query.insert_TPCM_POC_DETAIL}"/>
</jdbc-ee:outbound-endpoint>
</transactional>
<logger message="xa end" level="INFO" doc:name="Logger"/>
</flow>
</mule>
The error I get:
ERROR 2013-11-22 19:07:45,781 [main] org.mule.module.launcher.application.DefaultMuleApplication: null
org.mule.api.lifecycle.InitialisationException: Component has not been initialized properly, no flow constuct.
...
INFO 2013-11-22 19:07:45,783 [main] org.mule.module.launcher.application.DefaultMuleApplication: App 'Receiver' never started, nothing to dispose of
Exception in thread "main" org.mule.module.launcher.DeploymentInitException: InitialisationException: Component has not been initialized properly, no flow constuct.
...
Caused by: org.mule.api.config.ConfigurationException: Error creating bean with name 'testTranscationFlowFlow1': Invocation of init method failed; nested exception is org.mule.api.lifecycle.InitialisationException: Component has not been initialized properly, no flow constuct.
...
...
Caused by: org.mule.api.config.ConfigurationException: Error creating bean with name 'testTranscationFlowFlow1': Invocation of init method failed; nested exception is org.mule.api.lifecycle.InitialisationException: Component has not been initialized properly, no flow constuct.Caused by: org.mule.api.lifecycle.InitialisationException: Error creating bean with name 'testTranscationFlowFlow1': Invocation of init method failed; nested exception is org.mule.api.lifecycle.InitialisationException: Component has not been initialized properly, no flow constuct.
...
Try the following for your flow 2
<flow name="jdbctransactionFlow2"
processingStrategy="synchronous"
doc:name="jdbctransactionFlow2">
The above solution is for the issue mentioned in the post that the Code works in single flow. But not working when tried using flow-ref.
Hope this helps.

Mule Studio How to create global variable

click hear to see my flow Image
My test mule application.
I use curl json post data to the http-end-point and tranforms json to object and insert on my database with name (#[message.payload.name])
I use catch-exception-strategy for keep error log (case Unique name)
I want to update my table with condition in field #[message.payload.name]
- mean Update mytable set Firstname = #[message.payload.name]
but in catch-exception-strategy can't access #[message.payload.name]
My configuration
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:json="http://www.mulesoft.org/schema/mule/json"
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.2" 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/ee/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.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.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 ">
<data-mapper:config name="Mapper" transformationGraphPath="mapper.grf" doc:name="DataMapper"></data-mapper:config>
<jdbc-ee:mysql-data-source name="MySQL_Data_Source1" url="jdbc:mysql://localhost:3306/mule" user="root" password="1234" transactionIsolation="UNSPECIFIED" doc:name="MySQL Data Source"/>
<jdbc-ee:connector name="Database" dataSource-ref="MySQL_Data_Source1" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"/>
<flow name="httpPostTestFlow1" doc:name="httpPostTestFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="httpPost" doc:name="httpPost"></http:inbound-endpoint>
<json:json-to-object-transformer doc:name="JSON to Object" returnClass="java.util.Map"></json:json-to-object-transformer>
<jdbc-ee:outbound-endpoint exchange-pattern="one-way" queryKey="INSERT_TOKEN" connector-ref="Database" doc:name="Database">
<jdbc-ee:query key="INSERT_TOKEN" value="insert into users(FirstName) values(#[message.payload.name]);"/>
</jdbc-ee:outbound-endpoint>
<!-- <http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="80" path="post-debug.php" contentType="application/x-www-form-urlencoded" doc:name="post-debug.php"/> -->
<catch-exception-strategy doc:name="Catch Exception Strategy">
<expression-component doc:name="Create error response">#[message.payload = "{\"status\":\"error\", \"message\":\"" + exception.cause.message + "\"}"]</expression-component>
<jdbc-ee:outbound-endpoint exchange-pattern="one-way" connector-ref="Database" doc:name="Database" queryTimeout="-1" queryKey="UPDATE_TOKEN">
<jdbc-ee:query key="UPDATE_TOKEN" value="update users SET fail_message = #[message.payload]"/>
</jdbc-ee:outbound-endpoint>
</catch-exception-strategy>
</flow>
</mule>
Based on the title you want to have a some sort of global variable, one way is you can try using flowVars as a quick fix. Using Mule Studio it is the same as Variable (under Transformers).
The message you get inside the catch exception strategy is the exception.