HTTP Request Connector Payload (POST) in Mule 3.7 - http-post

I have an async flow with JSON payload (Payload Type as java.lang.String) and trying to do a POST to HTTP Request Connector but I am getting a 400 error. When I run the app in debugger, the payload type changes to org.glassfish.grizzly.utils.BufferInputStream from JSON string which I believe is the issue.
How do I resolve this issue?
Thanks

If you use a Dataweave transformer, using JAVA output returns that Object of type "org.glassfish.grizzly.utils.BufferInputStream", e.g:
%dw 1.0
%output application/java
---
payload
Try adding the Object to JSON after your Dataweave transformation!
<object-to-string-transformer doc:name="Object to String"/>

<flow name="createFlow">
<vm:inbound-endpoint exchange-pattern="one-way" path="createApi" connector-ref="VMConfiguration" doc:name="VM"/>
<enricher doc:name="Message Enricher" source="payload" target="#[flowVars.createApiPayload]">
<flow-ref name="createBomCollection" doc:name="createBomCollection"/>
</enricher>
<logger message="Payload after Create Api Call: #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
<set-payload value="#[message.payload]" mimeType="application/json" doc:name="Set Payload"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
(createApi: payload.createApi) when (payload.createApi != null)
}]]></dw:set-payload>
</dw:transform-message>
</flow>
<sub-flow name="createApiCollection">
<set-session-variable variableName="retryCount" value="#[new java.util.concurrent.atomic.AtomicInteger(0)]" doc:name="initialize retryCount"/>
<logger message="Payload before system Post: #[message.payload]" level="INFO" doc:name="Logger"/>
<http:request config-ref="System_HTTP_Request_Configuration" path="/bom1" method="POST" doc:name="HTTP">
<http:request-builder>
<http:header headerName="Content-Type" value="application/json"/>
<http:header headerName="requestID" value="#[sessionVars.requestID]"/>
<http:header headerName="transactionID" value="#[sessionVars.transactionID]"/>
<http:header headerName="quoteID" value="#[sessionVars.quoteID]"/>
<http:header headerName="operationName" value="#[sessionVars.operationName]"/>
</http:request-builder>
</http:request>
</sub-flow>

Related

Mule Https request response timeout

Im trying to config a response timeout for https request component.
My http connector is calling a URL, I want to set a time for example after 5 second if there is no response back from the URL close this https connection.
But I've been searched on google and mule site there are no related information.
This webservice i am calling resets password, if after certain time I don't get response I want to close it and DO NOT want to reset it.
Here is the sample code:
<http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="10.255.255.1." port="2446" doc:name="HTTP Request Configuration" responseTimeout="1" usePersistentConnections="false">
The responseTimeout is not doing anything, I've tried using SOAPUI to test the time is still the same no matter what I put.
Thanks in advance
I have set the responseTimeout property in the Http- request config and it works for me.
Please find the code below
<!--Http Listener Config for calling Service-->
<http:listener-config name="HTTP_Listener_Configuration1" host="0.0.0.0" port="8092" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" host="localhost" port="8092" doc:name="HTTP Request Configuration" responseTimeout="5000"/>
<flow name="testtimeoutFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<http:request config-ref="HTTP_Request_Configuration" path="/test" method="GET" doc:name="HTTP"/>
<catch-exception-strategy doc:name="Catch Exception Strategy">
<logger message="#[message.exception]" level="INFO" doc:name="Logger"/>
<set-payload value="#['Time out Error']" doc:name="Set Payload"/>
</catch-exception-strategy>
</flow>
<!-- Flow which has delay in responding the data-->
<flow name="testtimeoutFlow1">
<http:listener config-ref="HTTP_Listener_Configuration1" path="/test" doc:name="HTTP" allowedMethods="GET"/>
<set-payload value="#['HelloWorld']" doc:name="Set Payload"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<!-- Delay for 10 seconds-->
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[sleep(10000);
return message.payload;]]>
</scripting:script>
</scripting:component>
<logger message="After Script : #[payload]" level="INFO" doc:name="Logger"/>
</flow>
Hope this helps.

Managed Store Cache not working

My cache block never works, always the http request is made for same values.
<ee:object-store-caching-strategy name="eventIdCachingStrategy" doc:name="Autobulk EventID Caching Strategy" keyGenerationExpression="#[flowVars['ablMapEventToListingParameters']]">
<managed-store storeName="${xyz.eventid.cache.store.name}" persistent="true" maxEntries="${xyz.eventid.cache.max.entries}" entryTTL="${xyz.eventid.cache.entry.timetolive}" expirationInterval="${xyz.eventid.cache.expiration.interval}" />
</ee:object-store-caching-strategy>
<sub-flow name="mapEventsForListings" doc:name="mapEventsForListings">
<logger message="Entering mapEventsForListings flow..." level="INFO" doc:name="Logger"/>
<set-variable variableName="mapEventsForListingsTimeInMillis" value="#[new java.util.Date().getTime()]" doc:name="Set Entry Time In Millis"/>
<foreach doc:name="Map Event ID to each listing">
<choice doc:name="Choice">
<when expression="#[payload.getEvent().getVenue().isEmpty() || payload.getEvent().getDate().isEmpty() || payload.getExternalListingId().isEmpty() || payload.getPricePerProduct().getAmount()==0]">
<logger message="Missing input data for Payload" level="INFO" doc:name="Listing Missing Data Fields"/>
<set-variable variableName="noOfIncompleteListings" value="#[noOfIncompleteListings + 1]" doc:name="Increment Incomplete Listings Error Count"/>
</when>
<otherwise>
<set-variable variableName="ablMapEventToListingParameters" value="/?locale=en_US&venueName=#[payload.getEvent().getVenue()]&eventDateLocal=#[payload.getEvent().getDate()]" doc:name="Autobulk Event Search Parameters"/>
<set-variable variableName="originalListingRequest" value="#[payload]" doc:name="Variable"/>
<set-payload value="#[null]" doc:name="Set Payload"/>
<ee:cache doc:name="Cache" cachingStrategy-ref="eventIdCachingStrategy">
<https:outbound-endpoint exchange-pattern="request-response" method="GET" connector-ref="HttpsClientConnector" address="${xyz.search.catalog.events.ship.api.url}#[flowVars['ablMapEventToListingParameters']]" contentType="application/json" doc:name="HTTP Outbound Call to BulkCreateListing API">
<message-properties-transformer scope="outbound">
<add-message-property key="TARGET_HOST" value="${target.host}"/>
<add-message-property key="Authorization" value="#[flowVars['shUserBearerToken']]"/>
<add-message-property key="Content-Type" value="application/json"/>
</message-properties-transformer>
</https:outbound-endpoint>
<echo-component doc:name="Echo"/>
</ee:cache>
</otherwise>
</choice>
</flow>
Value of flowVars['ablMapToListingParameters'] = www.api-dev.xyz.com/search/catalog/events/ship/v3/?locale=en_US&venueName=SAPCenter&eventDateLocal=2015-07-16T20:00
Try with the following config :-
<ee:object-store-caching-strategy name="cachingStrategy" doc:name="cachingStrategy">
<managed-store storeName="myNonPersistentManagedObjectStore" maxEntries="-1" entryTTL="20000" expirationInterval="5000"/>
</ee:object-store-caching-strategy>
Also, you are setting the payload null before your cache scope ... cache scope require the payload to determine if the response can be cached or not.
For same payload it will make a cache-hit and provide the response from cache else it will process the message and store it in cache
ref:- https://docs.mulesoft.com/mule-user-guide/v/3.7/cache-scope

How to Transform JMS message to JSON for DataMapper

I am sending the following json message to a flow via JMS:
[{"salesOrderId":"00001-2-3","saleName":"Car Sale","status":"processing"}, {"salesOrderId":"00004-5-6","saleName":"House Sale","status":"processing"}]
this is my strategy:
<flow name="integration-consumer-client2" doc:name="integration-consumer-client2">
<jms:inbound-endpoint queue="client2.queue" connector-ref="Active_MQ" doc:name="JMS"/>
<logger message="Consumes Client 2 = #[payload]" level="INFO" doc:name="Logger"/>
<logger message="Client 2 Correlation = #[message.correlationId]" level="INFO" doc:name="Logger"/>
<vm:outbound-endpoint exchange-pattern="one-way" path="response" doc:name="VM"/>
</flow>
<flow name="integration-consumer-client" doc:name="integration-consumer-client">
<jms:inbound-endpoint doc:name="JMS" connector-ref="Active_MQ" queue="client1.queue">
</jms:inbound-endpoint>
<logger message="Consumes Client = #[payload]" level="INFO" doc:name="Logger"/>
<logger message="Client Correlation = #[message.correlationId]" level="INFO" doc:name="Logger"/>
<vm:outbound-endpoint exchange-pattern="one-way" path="response" doc:name="VM"/>
</flow>
<flow name="integration-flow" doc:name="integration-flow">
<vm:inbound-endpoint path="response" doc:name="VM">
<message-properties-transformer>
<add-message-property key="MULE_CORRELATION_GROUP_SIZE" value="2" />
</message-properties-transformer>
<collection-aggregator/>
</vm:inbound-endpoint>
<logger message="after vm = #[payload]" level="INFO" doc:name="Logger"/>
<request-reply doc:name="Request-Reply">
<jms:outbound-endpoint queue="queue.validation" connector-ref="Active_MQ" doc:name="JMS">
<jms:object-to-jmsmessage-transformer doc:name="Object to JMSMessage"/>
</jms:outbound-endpoint>
<jms:inbound-endpoint queue="queue.validation.response" connector-ref="Active_MQ" doc:name="JMS"/>
</request-reply>
<logger message="Siebel Response in ESB = #[payload]" level="INFO" doc:name="Logger"/>
</flow>
So two consumers messages are aggregated and then sent to another flow via the request reply using JMS. in that flow the message comes through as
[{"salesOrderId":"00001-2-3","saleName":"Car Sale","status":"processing"}, {"salesOrderId":"00004-5-6","saleName":"House Sale","status":"processing"}]
and the flow:
<jms:activemq-connector name="Active_MQ" username="admin" password="admin" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>
<data-mapper:config name="JSON_To_JSON" transformationGraphPath="json_to_json.grf" doc:name="JSON_To_JSON"/>
<flow name="validation-flow" doc:name="validation-flow">
<jms:inbound-endpoint doc:name="JMS" connector-ref="Active_MQ" queue="queue.validation" >
<jms:jmsmessage-to-object-transformer doc:name="JMSMessage to Object"/>
</jms:inbound-endpoint>
<logger message="Payload = #[payload]" level="INFO" doc:name="Logger"/>
<data-mapper:transform config-ref="JSON_To_JSON" doc:name="JSON To JSON"/>
<logger message="inside siebel after mapper = #[payload]" level="INFO" doc:name="Logger"/>
</flow>
I want to send the data through a mapper because i would like to change the status to "Complete". but after the json to json mapper the result is [B#2b9f82b. How can i transform the jms message to be more readable for the mapper?
What you have is a perfectly valid bytearray. You can convert it to String again using a object-to-string-transformer or even better a byte-array-to-string-transformer.

How to use variable values from another flow on mule?

Im trying to access a value from session variable set into another flow
code:
<flow name="test" doc:name="test" >
<http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/services/autocomplete" connector-ref="" transformer-refs="transform" doc:name="HTTP">
</http:inbound-endpoint>
<set-variable variableName="req" value="#[message.inboundProperties['http.query.string']]" doc:name="Variable"/>
<set-session-variable variableName="message" value="test" doc:name="Set Message ID"/>
<http:outbound-endpoint host="teste.local" path="newlocation/autocomplete?#[groovy:return req.toString();]" port="8080" user="login" password="1234" exchange-pattern="request-response" doc:name="HTTP">
</http:outbound-endpoint>
</flow>
and another flow trying to print it:
<flow name="test2" doc:name="test2" >
<http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/services/autocomplete2" connector-ref="" transformer-refs="transform" doc:name="HTTP">
</http:inbound-endpoint>
<set-variable variableName="req" value="#[message.inboundProperties['http.query.string']]" doc:name="Variable"/>
<logger message="#[sessionVars.message]" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint host="teste.local" path="newlocation/autocomplete?#[groovy:return req.toString();]" port="8080" user="login" password="1234" exchange-pattern="request-response" doc:name="HTTP">
</http:outbound-endpoint>
</flow>
But there is an error saing there is no variable set into that flow even when i first try to access the first url them i change to the seccond where it was supose to have the session.
-> mule version 3.4
Session variables need to be passed from one flow to another. They are serialized and deserialized on the event. You're setting it in the first flow and calling /autocomplete but the flow thats reading it is listening on /autocomplete2.
You cannot hit /autocomplete2 separately after /autocomplete and expect the session variable to be there as it was set on a different event. If you are looking to store state between separate flow invocations take a look at the mule objectstore module
http://mulesoft.github.io/mule-module-objectstore/mule/objectstore-config.html
And info on Mule object stores here:
http://www.mulesoft.org/documentation/display/current/Mule+Object+Stores
Some example configurations here:
https://github.com/mulesoft/mule-module-objectstore/blob/master/src/test/resources/mule-config.xml
Your flow will be something like the following :-
<flow name="test" doc:name="test" >
<http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/services/autocomplete" doc:name="HTTP">
</http:inbound-endpoint>
<set-variable variableName="req" value="#[message.inboundProperties['http.query.string']]" doc:name="Variable"/>
<set-session-variable variableName="message" value="test" doc:name="Set Message ID"/>
<logger message="Done #[sessionVars.message]" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" method="POST" address="http://localhost:8081/services/autocomplete2" doc:name="HTTP"/>
</flow>
<flow name="test2" doc:name="test2" >
<http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/services/autocomplete2" doc:name="HTTP">
</http:inbound-endpoint>
<set-variable variableName="req" value="#[message.inboundProperties['http.query.string']]" doc:name="Variable"/>
<logger message="#[sessionVars.message] #[sessionVars['message']] " level="INFO" doc:name="Logger"/>
</flow>

Magento Connector in Mule 3.5

I have tried creating Megento connector example program as given in the Megento connector vedio link.http://www.youtube.com/watch?v=GCbuqHLCiOg
My flow is:
<magento:config name="MagentoConnector" username="${magento.username}" password="${magento.password}" address="${magento.address}" doc:name="Magento">
<magento:connection-pooling-profile initialisationPolicy="INITIALISE_ONE" exhaustedAction="WHEN_EXHAUSTED_GROW"/>
</magento:config>
<flow name="ShoppingCartOPerations" doc:name="ShoppingCartOPerations">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="shoppingCartOperation" doc:name="HTTP"/>
<flow-ref name="CreateProduct" doc:name="Flow Reference"/>
<set-payload value="Product Id is #[groovy:message.getProperty('productId')]" doc:name="Set Payload"/>
</flow>
<sub-flow name="CreateProduct" doc:name="CreateProduct">
<magento:create-product config-ref="MagentoConnector" type="simple" set="1" sku="simple_sku" storeViewIdOrCode="4" doc:name="Create Product" address="https://sashistore.gostorego.com/api/v2_soap" password="gdskey" username="gdssrao">
<magento:attributes name="SampleProduct" description="TestProduct" short_description="creating sample product" weight="100" status="1" visibility="4" price="100" tax_class_id="1"/>
</magento:create-product>
<set-property propertyName="productId" value="#[payload]" doc:name="Store Product id"/>
<magento:update-inventory-stock-item config-ref="MagentoConnector" productId="#[groovy:message.getProperty('productId')]" doc:name="Update Stock">
<magento:catalog-inventory-stock-item qty="33" is_in_stock="100" min_qty="10"/>
</magento:update-inventory-stock-item>
</sub-flow>
ERROR 2014-01-29 23:48:48,521 [[magentotest].connector.http.mule.default.receiver.02] org.mule.retry.notifiers.ConnectNotifier: Failed to connect/reconnect: Work Descriptor. Root Exception was: null. Type: class org.mule.api.ConnectionException
ERROR 2014-01-29 23:48:48,524 [[magentotest].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy:
<magento:config name="MagentoConnector" username="gdssrao" password="gdskey" address="https://sashistore.gostorego.com/api/v2_soap" doc:name="Magento">
<magento:connection-pooling-profile initialisationPolicy="INITIALISE_ONE" exhaustedAction="WHEN_EXHAUSTED_GROW"/>
</magento:config>
<flow name="ShoppingCartOPerationsFlow" doc:name="ShoppingCartOPerationsFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="shoppingCartOperation" doc:name="HTTP"/>
<logger level="INFO" doc:name="Logger"/>
<flow-ref name="CreateProductFlow" doc:name="Flow Reference"/>
<logger level="INFO" doc:name="Logger"/>
<set-payload value="Product Id is #[groovy:message.getProperty('productId')]" doc:name="Set Payload"/>
</flow>
<sub-flow name="CreateProductFlow" doc:name="CreateProductFlow">
<magento:create-product config-ref="MagentoConnector" type="simple" set="1" sku="simple_sku" storeViewIdOrCode="4" doc:name="Create Product">
<magento:attributes name="SampleProduct" description="TestProduct" short_description="creating sample product" weight="100" visibility="4" />
</magento:create-product>
<logger level="INFO" doc:name="Logger"/>
<set-property propertyName="productId" value="#[payload]" doc:name="Store Product id"/>
<logger level="INFO" doc:name="Logger"/>
<magento:update-inventory-stock-item config-ref="MagentoConnector" productId="#[groovy:message.getProperty('productId')]" doc:name="Update Stock">
<magento:catalog-inventory-stock-item />
</magento:update-inventory-stock-item>
</sub-flow>
You have defined your plaintext connection attributes (username, password, address) in magento:create-product and then you have them as application properties in magento:config. That does not really make sense, as you only need to define the attributes once (in the config element) when you use config-ref in the other elements. Since you are having a connection failure, I would guess that you have incorrect properties in the config element. Try using the attributes from magento:create-product, instead.
EDIT: I checked the WSDL for your Magento API, and it seems that you have incorrect address
Try using https://sashistore.gostorego.com/index.php/api/v2_soap/index/ instead.
EDIT2: I got the WSDL URL for Magento API v2 from the Magento documentation. See this page for explanation on how to get the address for Web services from WSDL.

Resources