I created a service where you call the mule service via http:
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8086" path="idnum" doc:name="HTTP"/>
so if you want to call this service you type:
http://localhost:8086/idnum
but what i want is for the http to accept an id number as a parameter and then store the id number into a variable so that i can use the id number. So the http would look like:
http://localhost:8086/idnum/4583948364094 for example.
So my question is how do you get the parameter from the url
From Mule-3.6 on wards, we have HTTP Listener Connector, using which you can pass URI parameters.
You can access the URI parameters using the below MEL
#[message.inboundProperties.'http.uri.params'.id] provided your URI should be like this: http://localhost:8086/idnum/{id}
You need to put the id as a message inbound parameter as following .. In Mule flow you need to do the following :-
<flow name="test">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8086"
path="idnum" doc:name="HTTP"/>
<!-- storing id in variable myId -->
<set-variable variableName="myId"
value="#[message.inboundProperties['id']]"
doc:name="Variable"/>
<!-- Print the variable in console -->
<logger level="INFO" message="My id :- #[flowVars['myId']]"/>
</flow>
Now in browser access
http://localhost:8086/idnum/?id=4583948364094
Now you can store it in a variable in Mule and you can see it in a logger like:
My id :- 4583948364094
Related
I creating Rest Web service for fetching attachment file through http and storing file to local drive so i need filename dynamically as it is come in http request
My flow as follows
<foreach doc:name="For Each">
<set-payload value="#[payload.getInputStream() ]" doc:name="Get Inputstream from Payload"/>
<logger message="}}}#[message.inboundAttachments['payload']]" level="INFO" doc:name="Logger"/>
<file:outbound-endpoint path="F:\mule_data\e_files" responseTimeout="10000" doc:name="File" outputPattern="abcd.jpg"/>
</foreach>
<set-payload value="{"status":"success"}" doc:name="Generate JSON Response" />
</flow>
Here outputPattern="abcd.jpg" is harcoded so i need filename and format which coming through request
Please help
i refer from https://blogs.mulesoft.com/dev/mule-dev/soap-rest-attachments/
Please go through my answer in the question linked below.
How send a file in an HTTP request and upload it to file server via FTP in Mule
Once you are able to read/get the attachment file,you can get all the metadata associated with file.For reading name you can do following-
use #[payload.dataSource.part.fileName] to get name of attachment.
As shown in this question, it is possible to have parts of the url in variables, when requesting an http endpoint with mule.
But I have a full url, returned from an endpoint supporting hateoas. Is it possible to use this full url for requests without splitting it up into several parts (host, port, path)?
With full url I mean sth. like "http://example.com/a/specific/path" instead of host="example.com", port="80", path="/a/specific/path"
One simple way to do is to split the url into multiple parts and set it into a flow variables. Then you can use this flow variables anywhere you want.
An simple example to do it is as follows:-
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="csv-to-smtpFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/aa" doc:name="HTTP"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<set-payload value="http://example.com:80/a/specific/path" doc:name="Set Payload"/>
<set-variable variableName="url" value="#[new URL(payload);]" doc:name="Variable"/>
<set-variable variableName="protocol" value="#[url.getProtocol();]" doc:name="Variable"/>
<set-variable variableName="host" value="#[url.getHost();]" doc:name="Variable"/>
<set-variable variableName="port" value="#[url.getPort();]" doc:name="Variable"/>
<set-variable variableName="path" value="#[url.getPath();]" doc:name="Variable"/>
<logger message="Done" level="INFO"/>
</flow>
Here you can see I am setting the url http://example.com:80/a/specific/path in a payload and then splitting it into host, port, path etc and storing it in variables.
Pls note if your url is in the form http://example.com:80/a/specific/path, you will get the port using expression #[url.getProtocol();]
But if your url is in the form http://example.com/a/specific/path, you will not get the port number.
Ref:- https://docs.oracle.com/javase/tutorial/networking/urls/urlInfo.html
Using the deprecated http implementation it was possible to dynamically set the url on an outbound http endpoint from the payload or properties:
<http:outbound-endpoint address="http://#[payload]" method="GET" />
Is it possible to do this using the new http request connector?
Yes, it is. Here is a simple example:
<http:request-config
name="HTTP_Request_Configuration"
host="#[flowVars.address]"
port="80"
basePath="/"
doc:name="HTTP Request Configuration"/>
<flow name="httpFlow">
...
<set-variable
variableName="address"
value="#[message.inboundProperties.'http.query.params'.site]"
doc:name="Set site address variable"/>
<http:request
config-ref="HTTP_Request_Configuration"
path="/"
method="GET"
doc:name="Get dynamic HTTP"/>
</flow>
Just define the host attribute using the MEL expression you require.
host="#[flowVars.someVariable]"
I have a requirement in which i need to call a servlet from mule flow.I got one answer from the below site
http://mule.1045714.n5.nabble.com/Creating-query-string-for-calling-a-servlet-td2665836.html
But when i copy that code in my flow it is showing some errors in flow. Is there any other method or solution to call servlet from mule. I have servlet URL and username and password. I am using mule 3.5 anypoint studio. Please help me in completing this task
EDIT: (Pasted from a comment from the OP)
<flow name="CallServletServiceFlow1" doc:name="CallServletServiceFlow1">
<http:inbound-endpoint exchange-pattern="request-response" doc:name="HTTP" address="localhost:8080/servlet"/>
<object-to-string-transformer doc:name="Object to String"/>
<http:outbound-endpoint exchange-pattern="request-response" user="javauser" password="javauser1" method="GET" doc:name="HTTP" address="servlet/customTaskServlet?" connector-ref="HTTP_HTTPS"/>
</flow>
You seem to be copying old Mule 2 syntax in Mule 3, so this can not work.
Just use a simple HTTP outbound endpoint in your flow.
Reference: http://www.mulesoft.org/documentation/display/current/HTTP+Transport+Reference
EDIT: If you use the address attribute in HTTP endpoints (instead of the host port and path), you need to specify the scheme. So for example, you should replace address="localhost:8080/servlet" with address="http://localhost:8080/servlet".
I am trying to poll several addresses (URL links) from a list that contains all these addresses using the http polling connector in Mule. Currently, I am only able to poll from one address but I would like to find a way to use this list to iterate the polling for each site. Is there anything built within Mule that provides such function?
Is composite source what you're looking for? It allows you to have more than one endpoint in the inbound.
e.g. from http://www.mulesoft.org/documentation-3.2/display/32X/Bookstore+Example
<flow name="CatalogService">
<composite-source>
<!-- Public interface -->
<inbound-endpoint address="http://0.0.0.0:8777/services/catalog" exchange-pattern="request-response">
<cxf:jaxws-service serviceClass="org.mule.example.bookstore.CatalogService" />
</inbound-endpoint>
<!-- Administration interface -->
<inbound-endpoint address="servlet://catalog" exchange-pattern="request-response">
<!-- Convert request parameters to Book object -->
<custom-transformer class="org.mule.example.bookstore.transformers.HttpRequestToBook" />
<response>
<!-- Format response to be a nice HTML page -->
<custom-transformer class="org.mule.example.bookstore.transformers.AddBookResponse" />
<!-- Force text/html, otherwise it falls back to request
props, which have form-encoded one -->
<transformer ref="setHtmlContentType" />
</response>
</inbound-endpoint>
</composite-source>
....
Edit:
The following is a simple foreach example:
<flow name="foreachFlow1" doc:name="foreachFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<foreach collection="#[groovy:['localhost:8082', 'localhost:8083']]" doc:name="For Each">
<http:outbound-endpoint exchange-pattern="request-response" address="http://#[payload]" method="GET" doc:name="HTTP"/>
</foreach>
</flow>
<flow name="foreachFlow2" doc:name="foreachFlow2">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP"/>
<logger message="in flow2" level="INFO"/>
</flow>
<flow name="foreachFlow3" doc:name="foreachFlow3">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" doc:name="HTTP"/>
<logger message="in flow3" level="INFO"/>
</flow>
Basically, the 'tricky' part is to figure out that the payload becomes the current item in the collection you're iterating over (the docs do a wonderful job at pointing that out... well at least if you're into fishing :P).