• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I wasn't selected to go to mars. This tiny ad got in ahead of me:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic