• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Apache HTTP Commons - HttpClient question

 
Jason Bock
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which version of this library are you referring to?
 
Jason Bock
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using HttpClient 4.0-beta2. Is it okay to use DefaultHttpClient for all my requests?
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic