title: How to fix attribute validation errors in Coldfusion cfcontent (java.string.lang not supported variable type)?
body: <p>I have a Coldfusion application in which I'm generating HTML server side, compress, manually gzip and send back as a cfcontent. </p>
  
  <p>Looks like this:</p>
  
  <pre><code>&lt;cfsavecontent variable="renderedResults"&gt;
      &lt;cfoutput&gt;&lt;p&gt;Hello World&lt;/p&gt;&lt;/cfoutput&gt;
  &lt;/cfsavecontent&gt;
  
  &lt;cfscript&gt;
      compressedHTML = reReplace(renderedResults, "\&gt;\s+\&lt;", "&gt; &lt;", "ALL");
      compressedHTML = reReplace(compressedHTML, "\s{2,}", chr(13), "ALL");
      compressedHTML = reReplace(compressedHTML, "\s{2,}", chr(09), "ALL");
  &lt;/cfscript&gt;
  
  &lt;cfif cgi.HTTP_ACCEPT_ENCODING contains "gzip"&gt;
      &lt;cfinvoke component="services.utils" method="gzip" stringToZip="#compressedHTML#" returnvariable="compressedHTML"&gt;&lt;/cfinvoke&gt;   
      &lt;cfheader name="Content-Encoding" value="gzip"&gt;
  &lt;/cfif&gt;
  
  &lt;cfheader name="Content-Type" value="text/html; charset=ISO-8859-1"&gt;
  &lt;cfheader name="Content-Length" value="#len(compressedHTML)#" &gt;
  &lt;cfcontent reset="no" variable="#compressedHTML#" /&gt;
  &lt;cfreturn  /&gt;
  </code></pre>
  
  <p>My GZIP utility function:</p>
  
  <pre><code>&lt;cfscript&gt;
      var result="";
      var text=createObject("java","java.lang.String").init(arguments[1]);
      var dataStream=createObject("java","java.io.ByteArrayOutputStream").init();
      var compressDataStream=createObject("java","java.util.zip.GZIPOutputStream").init(dataStream);
      compressDataStream.write(text.getBytes());
      compressDataStream.finish();
      compressDataStream.close();
  
      if(arrayLen(arguments) gt 1){
          result=binaryEncode(dataStream.toByteArray(),arguments[2]);
      }else{
          result=dataStream.toByteArray();
      }
      return result;
  &lt;/cfscript&gt;
  </code></pre>
  
  <p>I'm running this on all pages and it works well most of the time, no matter if the page is requested straight or via AJAX.</p>
  
  <p><strong>However sometimes I get the following error</strong>:</p>
  
  <p><code>Diagnose: Attribute validation error for tag cfcontent. java.lang.String is not a supported variable type. The variable is expected to contain binary data. &lt;br&gt;The error occurred on line 338.</code>
  <code>Browser: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)</code> </p>
  
  <p>which is the <code>cfcontent</code> line. </p>
  
  <p><strong>Question</strong>:<br>
  Could this be that a page was requested by browser not supporting GZIP or with GZIP disabled? Because then the HTML would only be compressed and not binary encoded?</p>
  
  <p>If so, would a fix be that I would have to binary encode the compressed HTML?</p>
  
  <p>If both are wrong, please shed some light if you can?</p>