wood burning stoves*
The moose likes Other Open Source Projects and the fly likes Apache HTTP Commons - HttpClient question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Apache HTTP Commons - HttpClient question" Watch "Apache HTTP Commons - HttpClient question" New topic
Author

Apache HTTP Commons - HttpClient question

Jason Bock
Greenhorn

Joined: Dec 27, 2008
Posts: 19
What is the difference between AbstractHttpClient, HttpClient, and DefaultHttpClient?

I noticed some have functions that others don't, but I couldn't find any additional documentation.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Which version of this library are you referring to?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Jason Bock
Greenhorn

Joined: Dec 27, 2008
Posts: 19
I'm using HttpClient 4.0-beta2. Is it okay to use DefaultHttpClient for all my requests?
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi Jason,

This is quite a common 'structure' you'll see in public APIs (so is something useful to recognize for future)!

HttpClient is the Interface - So you would not use this directly, but you would use an implementation of that interface (or build your own implementation)

AbstractHttpClient is an implementation of HttpClient - It contains some default functionality and extension points that Apache thinks almost all implementers of HttpClient would use - So you would probably not use this directly, you'd want to use a class that extends from this one (someone else's or your own).

DefaultHttpClient is a 'default' implementation - It extends from the basic functionality and extension points that AbstractHttpClient provides and is meant to be used by people who just want an 'out of the box' solution, which a high percentage of people do. This is almost certainly the class you want to use, unless you have some unusual requirements it'll almost certainly do the trick.

Remember to 'code to the interface' though!

So

HttpClient httpClient = new DefaultHttpClient(...);

as opposed to:

DefaultHttpClient httpClient = new DefaultHttpClient(...);

Hope that helps!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Apache HTTP Commons - HttpClient question
 
Similar Threads
Post data and receive response
How do I respond to a webpage that contains a javascript?
Requesting for web page through java program
Using JSP to post data to external url without losing control focus
Calling a URL via HttpClient