0

I need to create a route (or not only one) that will do the following:

  1. Read some ids from a .txt file (tokenized by /n)
  2. For each id I will make a GET request to an url (http://myexample.com/something/**id**)
  3. Every request will bring me a JSON
  4. 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?

Dan Novac
  • 31
  • 7
  • Error code 405 means "Method not allowed" so maybe the request method is not being set to GET? Try adding ` – mdnghtblue Dec 03 '14 at 18:13
  • Thank you very much. Now I'm ending with a 500 error, but it's ok. I can receive the only available JSON for one id, so I think this works. Thank you so much! – Dan Novac Dec 04 '14 at 08:09
  • Still having a problem. I can't make the GET stop from making requests. I mean, after the request is made for all the ids, the GET is starting again and make me another jsons, so I end with more than 1 JSON file per id. I end with a lot of JSONs for a single id. Any idea on how can I solve this? – Dan Novac Dec 04 '14 at 09:18

0 Answers0