HttpClient with Feed Protocol

Took me a while to figure this out. If you’re using Apache’s HttpClient and need to change its default protocol from “http” to “feed”, this is how you do it in the code snippet below.

HttpClient client = new HttpClient();
URI uri = 
    new URI("feed://images.apple.com/main/rss/hotnews/hotnews.rss");
		
Protocol feedProtocol =
    new Protocol("feed", new DefaultProtocolSocketFactory(), 80); 
Protocol.registerProtocol("feed", feedProtocol);
client.getHostConfiguration()
    .setHost(uri.getHost(), 80, feedProtocol);

You can find Apache’s documentation and examples on this can be found here.

Advertisements
This entry was posted in code example, general, java. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s