Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

apache HttpClient make connection for url1 ,if url1 failed connect url2

 
sreenivas jeenor
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

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.






Thanks
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please edit your post to UseCodeTags. It's unnecessarily hard to read the code as it is, making it less likely that people will bother to do so.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic