embed JasperServer WS in Coldfusion

0
Hi to all,
in the last few days, I tried to embed JasperServer into my web application written in Coldfusion.
I create the jasperserver webservice from within the coldfusion administrator in this way : "http://jasperadmin:jasperadmin@localhost:9090/jasperserver/services/repo..."
Searching into the web I found this code but it seems not working...
The messagge error is: "variables.webservice.runReport(reportXML) doesn't exist." 
and the code is:"
<cfcomponent displayname="JasperServerService" hint="Jasper Server Service" output="false">
<!--- Constructor --->
<cffunction name="init" access="public" returntype="void" hint="Constructor.">
<cftry>
<cfset doh = refreshWebservice()>
<cfobject type="JAVA" action="Create" name="factory" class="coldfusion.server.ServiceFactory">
<cfset RpcService = factory.XmlRpcService>
<cfset RpcService.refreshWebService("jasper")>
<cfset variables.webservice = CreateObject("webservice", "jasper")>
<cfcatch>
</cfcatch>
</cftry>
</cffunction>
<!--- Private Functions --->
<cffunction name="dumpvar" access="private">
<cfargument name="daVar">
<cfargument name="abort" default="true">
<cfdump var="#daVar#">
<cfif arguments.abort>
<cfabort>
</cfif>
</cffunction>
<cffunction name="refreshWebservice" access="private" returntype="any" output="false" hint="refresh webservice">
<cfargument name="uriString" default="/">
<cfset var listXML = "">
<cfsavecontent variable="listXML">
<request operationName="list" locale="en">
<resourceDescriptor name="" wsType="folder" uriString="<cfoutput>#arguments.uriString#</cfoutput>" isNew="false">
<label>null</label>
</resourceDescriptor>
</request>
</cfsavecontent>
<!--- <cfinvoke webservice="http://localhost:9090/jasperserver/services/repository?wsdl" username="jasperadmin" password="jasperadmin" method="list" returnVariable = "foo">
<cfinvokeargument name="requestXmlString" value="#listXML#">
</cfinvoke> --->
<cfinvoke webservice="jasper" username="jasperadmin" password="jasperadmin" method="list" returnVariable = "foo">
<cfinvokeargument name="requestXmlString" value="#listXML#">
</cfinvoke>
</cffunction>
<cffunction name="getMimeTypes" access="private" returntype="any" output="false" hint="list mime types.">
<cfargument name="listIterator" required="true">
<cfscript>
var iterator = arguments.listIterator;
var mimeTypes = structNew();
var header = "";
while (iterator.hasNext()) {
header = iterator.next();
//dumpvar(iterator.next());
mimeTypes[header.getName()] = header.getValue();
}
return mimeTypes;
</cfscript>
</cffunction>
 
<cffunction name="outputContent" access="private" returntype="any" output="false" hint="output content.">
<cfargument name="mimetype" required="true">
<cfargument name="content" required="true">
<cfargument name="filename" default="report">
<cfif mimetype eq "application/pdf">
<cfheader name="Content-Disposition" value="attachment;filename=#arguments.filename#.pdf">
<cfelseif mimetype eq "application/rtf">
<cfheader name="Content-Disposition" value="attachment;filename=#arguments.filename#.rtf">
</cfif>
<cfcontent type="#arguments.mimetype#" variable="#arguments.content#" reset="true">
</cffunction>
 
<cffunction name="outputAttachments" access="private" returntype="any" output="false" hint="output Attachments.">
<cfargument name="attachments" required="true">
<cfargument name="reportfilename" default="">
<cfscript>
var allAttachments = arguments.attachments;
var attachment = "";
var i = 0;
var byteClass = createObject("java", "java.lang.Byte");
var byteArrayObj = createObject("java","java.lang.reflect.Array");
var byteArray = "";
//dumpvar(allAttachments);
for (i = 1; i lte arrayLen(allAttachments); i = i+1) {
attachment = allAttachments;
filSize = attachment.getSize();
byteArray = byteArrayObj.newInstance(byteClass.TYPE, filSize);
ins = attachment.getActivationDataHandler().getInputStream();
arr = ins.read(byteArray,0,filSize);
mimeTypes = getMimeTypes(attachment.getAllMimeHeaders());
outputContent(mimeTypes["Content-Type"],byteArray,reportfilename);
flvoutstream.write(byteArray);
flvoutstream.flush();
response.reset();
// reset the feed to the browser flvoutstream.close();
// close the stream to flash dumpvar(byteArray);
mimeTypes = getMimeTypes(attachment.getAllMimeHeaders());
dumpvar(attachment.getContent());
wee = attachment.getActivationDataHandler().getTransferDataFlavors();
ins = attachment.getActivationDataHandler().getInputStream();
xmlDataBuffer = CreateObject("java","java.lang.String").init(ins);
dumpvar(xmlDataBuffer);
// dumpvar(mimeTypes);
if (mimeTypes["Content-Type"] eq "application/pdf"){
outputContent(mimeTypes["Content-Type"],attachment.getContent());
} else {
outputContent(mimeTypes["Content-Type"],attachment.getAttachmentFile());
}
}
return attachment;
</cfscript>
<cfabort>
</cffunction>
 
Public Functions --->
<cffunction name="list" access="public" returntype="any" output="false" hint="list jasper server resources.">
<cfargument name="uriString" default="/">
<cfargument name="wsType" default="folder">
<cfset var listXML = "">
<cfset var list = "listXML">
<cfsavecontent variable="listXML">
<request operationName="list" locale="en">
<resourceDescriptor name="" wsType="<cfoutput>#arguments.wsType#</cfoutput>" uriString="<cfoutput>#arguments.uriString#</cfoutput>" isNew="false">
<label>null</label>
</resourceDescriptor>
</request>
</cfsavecontent>
<cfscript>
list = variables.webservice.List(listXML);
</cfscript>
<cfreturn list>
</cffunction>
 
<cffunction name="runReport" access="public" returntype="any" output="false" hint="runs a jasper report.">
<cfargument name="uriString" default="/">
<cfargument name="reportParams" default="structNew()">
<cfset var outputFormat = arguments.reportParams["outputFormat"]>
<cfset var imagesUri = "/path/to/images">
<cfset var reportXML = "">
<cfset var report = "reportXML">
<cfset var reportFileName = listlast(uriString,"/")>
<cfif structKeyExists(arguments.reportParams,"reportFileName")>
<cfset reportFileName = arguments.reportParams.reportFileName>
</cfif>
<cfset doh = refreshWebservice()>
<cfsavecontent variable="reportXML">
<request operationName="runReport" locale="en">
<argument name="IMAGES_URI"><cfoutput>#imagesUri#</cfoutput></argument>
<argument name="RUN_OUTPUT_FORMAT"><cfoutput>#outputFormat#</cfoutput></argument>
<resourceDescriptor name="" wsType="" uriString="<cfoutput>#arguments.uriString#</cfoutput>" isNew="false">
<label>null</label>
<cfloop list="#structKeyList(arguments.reportParams)#" index="pp">
<parameter name="<cfoutput>#pp#</cfoutput>"><cfoutput>#arguments.reportParams[pp]#</cfoutput></parameter>
</cfloop>
<!--- <parameter name="EmployeeID">emil_id</parameter>
<parameter name="TEST_LIST" isListItem="true">A &amp; L Powers Engineering, Inc</parameter>
<parameter name="TEST_LIST" isListItem="true">A &amp; U Jaramillo Telecom, Inc</parameter>
<parameter name="TEST_LIST" isListItem="true">A &amp; U Stalker Telecom, Inc</parameter> --->
</resourceDescriptor>
</request>
</cfsavecontent>
<!--- <cfdump var="#reportXML#"><cfabort> --->
<cfscript>
report = variables.webservice.runReport(reportXML);
if(NOT find("<returnCode><![CDATA[0]]></returnCode>",report)) {
dumpvar(xmlParse(report));
} else {
outputAttachments(variables.webservice.getAttachments(),reportFileName);
}
// dumpvar(attach);
</cfscript>
<cfabort>
</cffunction>
</cfcomponent>
 
Could anyone help me?
 
thanks in advance
marco.toninato's picture
Joined: Feb 2 2015 - 1:30am
Last seen: 4 years 5 months ago

0 Answers:

No answers yet
Feedback
randomness