Skip to content

Instantly share code, notes, and snippets.

Created September 8, 2015 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7cbacb9856e9de8a2b1a to your computer and use it in GitHub Desktop.
Save anonymous/7cbacb9856e9de8a2b1a to your computer and use it in GitHub Desktop.
<!--- test function --->
<CFFUNCTION name="getJSON" returntype="Struct" returnformat="JSON" output="no" access="remote">
<!--- apache derby test table --->
<cfquery name="Local.qData" datasource="someDatasource">
SELECT LastName, FirstName FROM TestUTF8
</cfquery>
<cfset Local.result = { lastName=qData.LastName, firstName=qData.FirstName}>
<cfreturn Local.result>
</cffunction>
<!--- simple jasper datasource test --->
<cfscript>
urlObj = CreateObject("java", "java.net.URL").init("http://127.0.0.1:8500/SomeComponent.cfc?method=getJSON");
conn = urlObj.openConnection();
input = conn.getInputStream();
// Test #1: simple datasource test
ds = createObject("java", "net.sf.jasperreports.engine.data.JsonDataSource").init(input);
writeDump("Done");
</cfscript>
<!--- display utf8 response as string --->
<cfscript>
urlObj = CreateObject("java", "java.net.URL").init("http://127.0.0.1:8500/SomeComponent.cfc?method=getJSON");
conn = urlObj.openConnection();
input = conn.getInputStream();
reader = CreateObject("java", "java.io.InputStreamReader").init(input, "UTF-8");
buffered = CreateObject("java", "java.io.BufferedReader").init(reader);
inputLine = buffered.readLine();
while (!isNull(inputLine)) {
writedump(inputLine);
inputLine = buffered.readLine();
}
buffered.close();
reader.close();
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment