I need to create a route (or not only one) that will do the following:
- Read some ids from a .txt file (tokenized by
/n
) - For each id I will make a GET request to an url (
http://myexample.com/something/**id**
) - Every request will bring me a JSON
- JSON will be unmarshaled to XML
So, I need a JSON file for every id in my file.txt. If I have 10 ids, I will get 10 JSON files from that url. I made the component that take me JSONs from a folder and unmarshal them to XML. Also, I tokenized my file.txt
.
The problem is I don't know how to get a JSON file per each id, more exactly, how can I dynamically transform my url?
My code is:
<camel:route id="getRequestForEachId">
<camel:from uri="file:src/main/resources/idList?noop=true" />
<camel:split>
<camel:tokenize token="\n" />
<camel:to uri="stream:out" />
<camel:recipientList>
<camel:simple>
http://myexample.com/something/${body}
</camel:simple>
</camel:recipientList>
<camel:to uri="file:src/main/resources/jsonMandatFromReq" />
<!--from this will take my json->xml component-->
</camel:split>
</camel:route>
And with this code I get a 405 error:
HTTP operation failed invoking http://google.com/something/3 with statusCode: 405
That 3
is from file.txt
with ids. So the url is built somehow, but I end with exceptions.
I would love concrete help, not a url to dynamic url on the camel site. Thank you very much!
LE:
The below answer solved my main problem, but I'm having another one now. The GET method won't stop from making requests.
I want to have just one request for each id, and for this I'll get a JSON file per each request or id. But my route is making requests continuously. After the list with ids is ending, it begins again. So I end with many JSON files for one id, when I need just one JSON file per id.
I don't want to override the existing JSON file. I want to have just one GET request per each id. How can I solve this?