Solved

Coldfusion Error: The toString method was not found

Posted on 2016-08-06
5
79 Views
Last Modified: 2016-08-06
Hello experts
I recently intalled Coldfusion 2016 Developer edition and while i was  trying to use the toString function as i was doing until now with CF9 i got the error: The toString method was not found
Any help?
error line:
 <cfset utf8Response = response.fileContent.toString("UTF8")>
0
Comment
Question by:Panos
  • 3
  • 2
5 Comments
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 500 total points
ID: 41745598
Edit - Added code

Sounds like response.fileContent contains a different type of object than the code was expecting? If you dump it, what does it actually contain - string, binary, null ...?

Type: <cfdump var="#response.fileContent.getClass().getName()#">
Value: <cfdump var="#response.fileContent#">

Side note, why was the CF9 code using the java method toString("UTF8")? Normally the fileContent already is a string (or sometimes binary)?
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 41745609
I'd guess it's returning a byte array. That type of object doesn't have a ToString() method, hence the error.  Test whether the result IsBinary(). If yes, use charsetEncode() to convert it to a string:

<!--- deliberately force response to be binary --->
 <cfhttp url="http://api.openweathermap.org/data/2.5/find?=San+Fransico&mode=json"
          method="GET"
          getAsBinary="yes"
          result="response" / >
 
 <cfif isBinary(response.filecontent)>
        <cfset responseString = charsetEncode(response.filecontent, "utf-8")>
 <cfelse>
        <cfset responseString = response.filecontent>
 </cfif>

  DEBUG
 <cfoutput>
     <br>class = #response.filecontent.getClass().name#
     <br>value = #responseString#
 </cfoutput>

Open in new window

0
 
LVL 2

Author Comment

by:Panos
ID: 41745620
Hi agx.
Thank you very much for your help.
It is really a binary response.
I don't know how i was confused with CF9.
The problem is fixed.
0
 
LVL 2

Author Closing Comment

by:Panos
ID: 41745623
Thank you again
regards Panos
0
 
LVL 52

Expert Comment

by:_agx_
ID: 41745634
>> don't know how i was confused with CF9

Well if the exact same code and url work w/CF9, but not CF2016, it's entirely possible Adobe changed something.  Wouldn't be the first time.  Anyway, glad it helped.
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question