<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ColdFused? &#187; cffeed</title>
	<atom:link href="http://www.rupeshk.org/blog/index.php/tag/cffeed/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rupeshk.org/blog</link>
	<description>My Views on ColdFusion, Java and related technologies</description>
	<lastBuildDate>Mon, 21 Jun 2010 12:40:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using CFFeed with URL sending compressed content</title>
		<link>http://www.rupeshk.org/blog/index.php/2007/08/using-cffeed-with-url-sending-compressed-content/</link>
		<comments>http://www.rupeshk.org/blog/index.php/2007/08/using-cffeed-with-url-sending-compressed-content/#comments</comments>
		<pubDate>Fri, 03 Aug 2007 21:49:00 +0000</pubDate>
		<dc:creator>Rupesh Kumar</dc:creator>
				<category><![CDATA[coldfusion]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[cffeed]]></category>

		<guid isPermaLink="false">http://rupesh106.wordpress.com/2007/08/03/using-cffeed-with-url-sending-compressed-content/</guid>
		<description><![CDATA[Today someone posted on ColdFusion forum regarding this problem where cffeed was not able to handle a particular URL and it was throwing an error. The URL which he tried was http://movies.msn.com/rss/topcelebs and it failed with an error 
&#8220;Unable to read the source URL.unknown compression method&#8221;  
The reason it happens is &#8211; The URL [...]]]></description>
			<content:encoded><![CDATA[<p>Today someone posted on ColdFusion forum regarding this problem where cffeed was not able to handle a particular URL and it was throwing an error. The URL which he tried was <a href="http://movies.msn.com/rss/topcelebs">http://movies.msn.com/rss/topcelebs</a> and it failed with an error </p>
<p>&#8220;<em>Unable to read the source URL.<br />unknown compression method</em>&#8221;  </p>
<p>The reason it happens is &#8211; The URL returns the response in gzip compressed format only. So when ColdFusion sent a request to this URL and asked for uncompressed data, it could not get anything and hence it was unable to read it. A simpe workaround for this is to use cfhttp to fetch the content, write to a temporary file and then use the cffeed tag to read this file. Important thing to keep in mind here is to set an additional header in the cfhttp tag using cfhttpparam to indicate that it can accept compressed data as well.</p>
<p>Here is the modified code where it first tries cffeed with the URL. If that fails, then it tries to use cfhttp to fetch the content and writes to a temporary file and then uses it in cffeed.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> tempDir<span style="color: #0000FF;">=</span><span style="color: #800080; font-weight: bold;">GetTempDirectory</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> tempFile <span style="color: #0000FF;">=</span> <span style="color: #800080; font-weight: bold;">GetTempFile</span><span style="color: #0000FF;">&#40;</span>tempDir, <span style="color: #009900;">&quot;myfeed&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> tempFileName <span style="color: #0000FF;">=</span> <span style="color: #800080; font-weight: bold;">GetFileInfo</span><span style="color: #0000FF;">&#40;</span>tempFile<span style="color: #0000FF;">&#41;</span>.<span style="color: #0000FF;">name</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cftry</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffeed</span> <span style="color: #0000FF;">action</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;read&quot;</span> <span style="color: #0000FF;">source</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;http://movies.msn.com/rss/topcelebs&quot;</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;feedInStruct&quot;</span> <span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfcatch</span> any<span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfhttp</span> <span style="color: #0000FF;">url</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;http://movies.msn.com/rss/topcelebs&quot;</span> <span style="color: #0000FF;">path</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#tempDir#&quot;</span> <span style="color: #0000FF;">file</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#tempFileName#&quot;</span><span style="color: #0000FF;">&gt;</span></span>
        <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfhttpparam</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;header&quot;</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Accept-Encoding&quot;</span> <span style="color: #0000FF;">value</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;compress,gzip,deflate&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfhttp</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffeed</span> <span style="color: #0000FF;">action</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;read&quot;</span> <span style="color: #0000FF;">source</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#tempFile#&quot;</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;feedInStruct&quot;</span> <span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfcatch</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cftry</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> <span style="color: #800080; font-weight: bold;">FileExists</span><span style="color: #0000FF;">&#40;</span>tempFile<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #800080; font-weight: bold;">FileDelete</span><span style="color: #0000FF;">&#40;</span>tempFile<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfdump</span> <span style="color: #0000ff;">var</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#feedInStruct#&quot;</span><span style="color: #0000FF;">&gt;</span></span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.rupeshk.org/blog/index.php/2007/08/using-cffeed-with-url-sending-compressed-content/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
