I'm starting using Mule and have some trivial questions. Here one of them.
Suppose you store the address of a url to invoke later on a process on a property file.
Then you want to use an http endpoint specifying this url.
It works fine, you simply put in the address: ${URL_ADDRESS} and that's it.
Now if your url is calculated and set on a flowVar, why the following code does not work?
<http:outbound-endpoint exchange-pattern="request-response" method="GET" address="#[flowVars['URL_ADDRESS']]" doc:name="HTTP"/>
It throws this exception:
java.lang.IllegalArgumentException: Address '#[flowVars['URL_ADDRESS']]' for protocol 'http' should start with http://
Why is it checked at compilation time? How can I do to set it at runtime?
The protocol cannot be dynamic. You should change your outbound endpoint to <http:outbound-endpoint exchange-pattern="request-response" method="GET" address="http://#[flowVars['URL_ADDRESS']]" doc:name="HTTP"/>
you should use the flow variables in below format. Either #[FileName] or #[flowVars.FileName]
Related
i need to send json to a web service and getting the response in json format.
so firstly i have a http connecter which receive data and then i need a datamaper to map the json that i get to the web service. in a second flow i put another http connecter which listen to the web service and get the response. actually what i need is an element who can replace the datamaper because i'm working with the community version. so if there is any example of code any tutorial, i would be grateful.
First flow:
<flow name="Flow1">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8082" doc:name="HTTP"
contentType="application/x-www-form-urlencoded" path="getDetails" />
<json:json-to-object-transformer
returnClass="java.lang.Object" doc:name="JSON to Object" />
<set-session-variable variableName="tkn"
value="#[message.payload.token]" doc:name="token" />
<set-session-variable variableName="msg"
value="#[message.payload.msg]" doc:name="message" />
<logger message="#[sessionVars['tkn']]" level="INFO" doc:name="Logger" />
</flow>
You can either do your own mapping in a custom component or use a framework like Smooks to do the transformations. If you choose the latter you can check out this blog post. HTH.
Rajeun,
Refer the below link if that helps.
http://www.mulesoft.org/documentation/display/current/JSON+Module+Reference
You need to follow following steps :-
1. Extract the data from your input Json request and store in variables.
2. Now, if your external service is a SOAP, then you can create a SOAP request using XSLT example :- http://bushorn.com/xml-to-xml-transformation-in-mule/
3. If your external web service is a REST, you can create the JSON request for that service using Mule Expression transformer example :- http://bushorn.com/json-to-json-transformation-in-mule/
I have a requirement to pass an object to an HTTP connector (Not sure if I can use any other connector). The next step is convert an object to a CXML and make an outbound end point call to another API, get the response and convert it another java object. I am very new to Mule and need some inputs on this. Any pointers would be very helpful.
Can someone give me some good points where we have good links for mule implementation examples (apart from Mule in Action)
EDIT: code from OP's comment below
<flow name="object_serialization.mflowFlow1" doc:name="object_serialization.mflowFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<component class="SerializeObject" doc:name="Java"/>
<serializable-to-byte-array-transformer doc:name="Serializable to Byte Array"/>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" method="POST" doc:name="HTTP"/>
</flow>
You can achieve your goal with Mule:
On the client side:
Serialize the Java object with serializable-to-byte-array-transformer
HTTP POST it with an http:outbound-endpoint
On the server side:
Receive the HTTP POST with an http:inbound-endpoint
Deserialize the Java object with byte-array-to-serializable-transformer
This assumes the Java object implements java.io.Serializable, which should be the case since you stated you want to use Java serialization. This also assumes that the necessary Java classes are available on the classpath of both client and server Mules.
I currently have a flow that is triggered using a specific HTTP request path, which should then make a request to a RabbitMQ server hosted locally. However, I cannot seem to see the output of the Mule Requester module; I see the HTTP request instead. Here is the gist of my current flow:
<flow name="get-queue-messages-manually" doc:name="get-queue-messages-manually" initialState="started">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="getqueue" contentType="text/plain" doc:name="HTTP"/>
<mulerequester:request returnClass="java.io.String" config-ref="Mule_Requester" resource="amqp://myexchange" doc:name="Mule Requester"/>
<logger level="INFO" doc:name="Logger"/>
<echo-component doc:name="Echo"/>
</flow>
I am able to send messages to the exchange and have them be enqueued without a problem, but I cannot seem to extract any. As I understand it, the Mule Requester module allows one to make a request for resources at any point in a flow; I believe I also read that it causes an asynchronous operation, which may be the problem here. In that case, how would I be able to retrieve the queued message, and not the HTTP request?
I have also looked into the Mulesoft AMQP documentation, and though the URI specs mention the format amdq://{exchange}/amqp-queue.{queue}, it doesn't seem that the Mule Requester accepts this, as it only seems to take exchange names only. The console logs do contain a line which states that a private queue has been created, and from a little bit of searching, is an indication that a queue name is not specified? Not quite sure how that can be done in this component, however.
Note that the reason I have the HTTP request element first is that I do not want the flow firing off the moment a message is received, and therefore the HTTP component is used to ensure that the messages are read only when requested. Without the HTTP component, everything is swell.
Thanks in advance for any pointers on this issue - been struggling with this for some time now.
Well, now I feel silly. This can indeed be done using the Mule Requester. The format for the resource field should be: amqp://amqp-queue.{queueName}. Once I used the queue name instead of the exchange, I finally see the message in the payload. Hope this helps others! (There seems to be a restriction with accepting own answers; I'll accept this answer once that is lifted)
I am very new to mule. I am trying to read a http link, which outputs txt file.
I want to call this link in mule, read text and insert data in to database.
Can any one suggest me how to read txt file in mule when file is coming from http.
Thanks in advance.
Let us consider there is a HTTP url localhost:8081/service which will provide a text output while calling it.
So, to call it from Mule flow, you need to configure HTTP outbound or HTTP request component which is used to call external url.
So, you need to configure it in following way :-
If you are using Mule 3.5 or earlier, you need outbound endpoint :-
<http:outbound-endpoint exchange-pattern="request-response" address="localhost:8081/service" method="GET" doc:name="HTTP"/>
If you are using Mule 3.6 or later version, you need Http request component :-
<http:request-config name="HTTP_Request_Configuration" host="localhost" port="8081" doc:name="HTTP Request Configuration"/>
And in Mule flow :-
<http:request config-ref="HTTP_Request_Configuration" path="/service" method="GET" doc:name="Call external service" />
Reference :- https://developer.mulesoft.com/docs/display/current/HTTP+Request+Connector
After calling the external url from Mule flow, you will be getting the text as payload, which you can insert into database using your SQL query
Take a look at the Mule HTTP Endpoint.
I have tested Twitter and LinkedIn and I seem to be able to get these working eventually, but I just cannot find enough material to get the Google connectors to work. When using the Google Calendar connector I am trying to collect the token with - #[flowVars['tokenId']] but the value always comes out as null. Am I doing something wrong? Can someone please help?
Thanks,
Ash.
Answered my own question for anyone else struggling with the same issue -
Managing OAuth Tokens (optional)
Configure ObjectStore
To keep data persistent you need to store it somewhere, it is recommended you use ObjectStore for this. Install an ObjectStore connector. Configure it like this in your application:
<objectstore:config name="ObjectStore" doc:name="ObjectStore" />
Storing Tokens After Authorization
After the authorization dance is done, the accessTokenId for the service you are invoking is available as a flow variable called OAuthAccessTokenId. You must persist this ID so you can use it in future invocations of your connector. This example shows how to store this variable into ObjectStore under the key accessTokenId.
<flow name="authorize-google" doc:name="authorize-google">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="authorize" doc:name="HTTP"/>
<google-contacts:authorize config-ref="Google_Contacts" doc:name="Authorize GContacts"/>
<objectstore:store config-ref="ObjectStore" key="accessTokenId" value-ref="#[flowVars['OAuthAccessTokenId']]" overwrite="true" doc:name="ObjectStore"/>
</flow>
Using Your Access Token
Any invocation of your connector must load the access token from ObjectStore and reference it. This example shows loading it from ObjectStore and checking if it was set, before proceeding.
<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"/>
Once accessTokenId is available as a flow variable, you can reference it in your connector operations:
<google-contacts:get-contacts config-ref="Google_Contacts" accessTokenId="#[flowVars['accessTokenId']]" />
More details here - http://www.mulesoft.org/documentation/display/34X/Using+a+Connector+to+Access+an+OAuth+API
Heres how it look in the studio - http://imgur.com/DtLodel
Thanks,
Ash.