Return JSOn data from a REST API in ColdFusion - coldfusion-10

I am trying to fetch JSON data from a ColdFusion site using a GET call and use the output JSON in an Android app. Wanting to start with a simple hello world component, but it is throwing error when accessed via browser. "Unsupported operation"
The cfc content is
<cfcomponent hint="A first CFC">
<cffunction name="getValue" returntype="String" access="public">
<cfreturn "Hello World">
</cffunction>
</cfcomponent>
Where am I going wrong? Please guide.
Can someone provide link to a good example/tutorial for this please.

returnFormat="JSON"? It seems you are handling directly on a raw string "HelloWorld". Therefore your frontend doesn't know how to operate the string as a valid JSON.

You can use Coldfusion component but since you are just starting to learn coldfusion component you can also use a simple cfm page to try and return the json in your android app. Create an index.cfm and save the code below. Then point the URL of your android app to the URL of the index.cfm example http://foo.bar/index.cfm
<cfcontent reset="true" >
<cfset msg = {} >
<cfset msg["message"] = "Hello World" >
<cfoutput>
#serializeJSON(msg)#
</cfoutput>

Related

Put method cant receive body data but work with direct URL pass parameter

i call api using postman ... api work fine with if i choose put method and pass a url like:
https://URL/user/123?id=123&name=foo
but if i using this link :
https://URL/user/123
And pass data in body put method not working.
I try to use form-data and x-www-form-urlencoder .. all not working .
Anyone know what is my problem ..
thank for your help.
and sorry for my bad English
Try to use RAW format with particular data-type/content-Type which your using in web service Eg: JSON(application/json) Hope this will solve your problem

What is the proper way to integrate server-side code with IBM's dialog api?

I want to integrate my web application with IBM's dialog api. Basically, I want to sometimes send the pure text result from the IBM dialog API, as I set it up in the XML, and other times, such as when the user wants a dynamic response, which might involve me querying a database to find an account balance, for example. My current thought is to include some sort of syntax in my dialog XML which I can parse to know if the response from the conversation requires me to change it. I was thinking of something like:
<input>
<grammar>
<item>What is my account balance?</item>
</grammar>
<output>
<prompt selectionType="RANDOM">
<item>{ACTION_GETBALANCE}</item>
</prompt>
</output>
</input>
So if I got a response like {ACTION_***} I would take my own action. Is this an appropriate way of doing this? Is there another way which might be better?
This is indeed the recommended method
see for example line 1358 on the movie application demo dialog file provided on WDC git repo
<prompt selectionType="RANDOM">
<item>"{Search_Now:"{Search_Now}", Recency:"{Recency_Preference}", Rating:"{Certification_Preference}", Genre:"{Genre_Preference}", Index:"{Current_Index}", Page:"{Page}"}"</item>
</prompt>

Connecting to a REST web service with Drupal

I'm trying to connect to a REST web service with Drupal 7. Data is supplied via a url and I want to pull it into the D7 site to create and populate nodes. I'm using the feeds module to map the content and Web Service Client module to pull in the data but I'm unsure as to what to use as Data types to cut and split the data as I need it.
I have an address that looks like http://192.136.0.31:8080/places/getAll
The xml I get back when I use Chrome's Advanced Rest Client:
<ArrayOfAsset>
<Asset>
<Address1>01-02 Whatever Road</Address1>
<Address2>Whatever Town</Address2>
<City />
<Country>United Kingdom</Country>
<County>Whatevershire</County>
<HouseNumber>0001</HouseNumber>
<Id>01234ec0e-005456944567</Id>
<Latitude>58.828424</Latitude>
<LongTelephoneNumber>01543 534676</LongTelephoneNumber>
<Longitude>126.054688</Longitude>
<Name>Whatever the name is</Name>
<PostCode>WH01 7PU</PostCode>
<ShortName>Whatever</ShortName>
<Uri></Uri>
</Asset>
</ArrayOfAsset>
So, my question is how do I split/cut that data to return the parts I need in Clients module?
If there is anything else you need me to supply, let me know.
Update:
The xml exported via the web service, although looks like xml doesn't actually format the same.
The first line is is commented out in Chrome dev tools as if chrome is putting it there itself:
<!--?xml version="1.0" encoding="utf-8"?-->
Blank head tags
<head></head>
<body>
Then straight into the code above.

TinyMCE 403 Forbidden page when using line breaks

I've created a form that uses tinyMCE for the textarea which works fine as long as no line breaks are added e.g. <br /> or <p> </p>.
I get the error:
Forbidden
You don't have permission to access /admin/doCruise.php on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Where, doCruise.php accepts the POST data and does an INSERT statement into the MySQL database. Permissions are fine as it works when no tags are there.
Any help would be greatly appreciated :)
Sorry for my English. But I am try to explain.
I think I fix it.
On your hosting mod_security block all content with html tags (on my too).
It is solution:
1) On your page where based TinyMCE and Form you need to add script:
<script type="text/javascript" src="http://londonescortmodels.co.uk/includes/jquery.base64.js"></script> //lib for base 64 encode
<script type="text/JavaScript">
$(document).ready(function(){
//------------------------//
// On submit //
//------------------------//
$("form").submit(function() { //Event on submit
tinyMCE.triggerSave(false, true); //Save content to textarea
$text=$("#elm1").val(); //get content from textarea
tinyMCE.activeEditor.setContent($.base64("encode",$text)); //encode content and return to TinyMCE
tinyMCE.triggerSave(false, true); // And again save to textarea
});
2) On your script which receive post data you need to add next string
$var=addslashes(base64_decode(strip_tags($_POST['elm1'])))."'"; //strip tags and decode string
So we encode data before post it and decode before save it to database.
Thank you for your time! Good luck.
I got the same error. It was a server issue. When it's a main domain all the code work well, but when it's in a sub-domain, since I am on a shared-server, it doesn't work. Hope it can help some one !

generate a dynamical html

How can i generate a dynamiccal html code in iphone like below:
NSString sHtml = #"<html><form name= \"PIOform\" >\
<input type=\"text\" name=\"txtUserName\" >\
<input type=\"text\" name=\"txtPassWord\" >\
</form>\
<input type=\"button\" onclick=\"goCallLogin(PIOform)\" >
</html>";
Yes, I want to create an UI iphone application with feature like a client HTML form to call a javascript method in any server:
When i click a button in iphone. It will call goCallLogin(PIOform) method in JS at address:
http;//www.myserver.com/login.js
How can i do?
Thank you
This seems like something better suited for an iPhone web app than a native app. Maybe you should look into doing that instead? There is no need to create HTML like this with a native app. If you want to send values to a remote server from a native app, take a look at writing a web service and accessing it from the iPhone. You could use REST or XML-RPC to activate the goCallLogin method that you were referring to.
Also, you cannot just call a javascript through a web browser and expect it to work. Javascript is a client-side technology. You need to look into writing your web service with a server-side language/framework such as PHP, Ruby on Rails, ASP.NET, etc.