File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes apache HttpClient make connection for url1 ,if url1 failed connect url2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "apache HttpClient make connection for url1 ,if url1 failed connect url2" Watch "apache HttpClient make connection for url1 ,if url1 failed connect url2" New topic
Author

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

sreenivas jeenor
Ranch Hand

Joined: Jan 09, 2005
Posts: 125
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
Marshal

Joined: Mar 22, 2005
Posts: 39551
    
  27
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.


Ping & DNS - updated with new look and Ping home screen widget
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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 agree. Here's the link: http://aspose.com/file-tools
 
subject: apache HttpClient make connection for url1 ,if url1 failed connect url2
 
Similar Threads
[Apache Httpclient] Connection refused
HttpURLConnection and Redirects
Use of HttpClient in Applet
how to execute commands on router using java code
httpclient athentification issue