using apache HttpClinet i have to connect to two different URLs based on conditions.
we have given two urls URL1 and URl2.
initially i have to connect to URL1 .if it fails due to communication errors retry for 3 times,then also it failed Now connect to URL2 and repeat the same process.finally if URL2 also fails. read from database.
here is my code.
how can i achieve my above scenario. am i doing the correct way or there is some other means of achieving it.please help me.
No, I'd say the code is pretty broken. It looks like it connects twice, no matter what.
The methods that make the connection and do the processing should be refactored, since they're exactly the same, except for the URL.
You also check the statusCode for a specific value (using a constant, which is good), but then try to use it in a switch statement that has values other than that which you just compared it to (using non-constants, which is bad), which makes no sense.
That's what sticks out at me the most.
subject: apache HttpClient make connection for url1 ,if url1 failed connect url2