在 Java 类中工作时,使用 JSON 的脚本化数据源无法与 BIRT 一起使用
我将用几句话来谈论抛出代码行,在露天,我需要使用其以 JSON 形式响应的工作流程 API 创建一个报告,我在此链接中找到了使用 JSON 作为数据源的解决方案(这将是完整的参考)了解我的问题):
我下载了源代码,然后我了解它是如何工作的,最后我遇到了一个问题“身份验证问题”并通过编辑源文件“JSONParser.java”解决了它,无论如何我现在还有另一个问题,我在 Java 中有以下代码可以工作:
package com.actuate.json.test;
import java.io.IOException;
import com.actuate.json.JSONParser;
public class TestJSONParse_OutBound {
public static void main(String[] args) {
try{
JSONParser theParser = new JSONParser();
theParser.loadData("http://localhost:8080/alfresco/service/api/workflow-definitions/activiti$CS-Outbound-WFPD:5:403/workflow-instances?state=active&format=json","admin","admin");
System.out.println("Number of jobs found: " + theParser.getChildCount("data") + "\n");
for(int i = 0; i < theParser.getChildCount("data"); i++){
System.out.println(String.valueOf(i + 1) + ") " + theParser.getValue("data", "description", i));
System.out.println("\tID: " + theParser.getValue("data", "id", i));
System.out.println("\tURL: " + theParser.getValue("data", "url", i));
System.out.println("\tUsername: " + theParser.getValue("data", "initiator/firstName", i));
}
}catch (IOException ioe) {
// TODO: handle exception
}catch(Exception ex){
}
}
}
结果:
Number of jobs found: 2
1) CS-Outbound-WFPD
ID: activiti$499
URL: api/workflow-instances/activiti$499
Username: Administrator
2) CS-Outbound-WFPD
ID: activiti$404
URL: api/workflow-instances/activiti$404
Username: Administrator
但在 Eclipse IDE 的 BIRT 报告中,运气不佳 1,在脚本数据源中,我输入:
count = 0;
controller = new Packages.com.actuate.json.JSONParser();
controller.loadData(params["JSONURL"],params["USERNAME"],params["PASSWORD"]);
totalCount = controller.getChildCount("data");
并在数据集表中获取行,例如:
if(count < totalCount){
row["id"] = controller.getValue("data", "id", count);
row["url"] = controller.getValue("data", "url", count);
count++;
return true;
}
return false
但仍然给我只有标题标题的白页,空单元格!!。
为了获得例外,我将其上传到与 BIRT 集成的 Alfresco,然后我得到:
WARNING: Fail to execute script in function __bm_OPEN(). Source:
------
" + count = 0;
controller = new Packages.com.actuate.json.JSONParser();
controller.loadData(params["JSONURL"],params["USERNAME"],params["PASSWORD"]);
totalCount = controller.getChildCount("data"); + "
-----
A BIRT exception occurred. See next exception for more information.
Error evaluating Javascript expression. Script engine error: TypeError: [JavaPackage com.actuate.json.JSONParser] is not a function, it is object. (/report/data-sources/script-data-source[@id="8"]/method[@name="open"]#2)
Script source: /report/data-sources/script-data-source[@id="8"]/method[@name="open"], line: 0, text:
__bm_OPEN()
org.eclipse.birt.data.engine.core.DataException: Fail to execute script in function __bm_OPEN(). Source:
------
" + count = 0;
controller = new Packages.com.actuate.json.JSONParser();
controller.loadData(params["JSONURL"],params["USERNAME"],params["PASSWORD"]);
totalCount = controller.getChildCount("data"); + "
-----
A BIRT exception occurred. See next exception for more information.
Error evaluating Javascript expression. Script engine error: TypeError: [JavaPackage com.actuate.json.JSONParser] is not a function, it is object. (/report/data-sources/script-data-source[@id="8"]/method[@name="open"]#2)
Script source: /report/data-sources/script-data-source[@id="8"]/method[@name="open"], line: 0, text:
__bm_OPEN()
at org.eclipse.birt.data.engine.script.JSMethodRunner.runScript(JSMethodRunner.java:147)
.
.
.
Caused by: org.mozilla.javascript.EcmaError: TypeError: [JavaPackage com.actuate.json.JSONParser] is not a function, it is object. (/report/data-sources/script-data-source[@id="8"]/method[@name="open"]#2)
.
.
.
真的,我不知道问题是什么,也不知道如何解决,如果有人对此有任何想法,我花了大约 1 周的时间,但没有解决方案...
I will talking throw codes line with a few words, In alfresco I need to create a reports using its Workflows APIs that response as JSON, I found the solution for using JSON as a Data Source in this link (this will be good reference to full understand my issue) :
I downloaded the source and I understand how its works, and finally I was having a problem "authentication issue" and solved it by editing source file 'JSONParser.java', anyway I have another problem now, I have the following code in Java thats working:
package com.actuate.json.test;
import java.io.IOException;
import com.actuate.json.JSONParser;
public class TestJSONParse_OutBound {
public static void main(String[] args) {
try{
JSONParser theParser = new JSONParser();
theParser.loadData("http://localhost:8080/alfresco/service/api/workflow-definitions/activiti$CS-Outbound-WFPD:5:403/workflow-instances?state=active&format=json","admin","admin");
System.out.println("Number of jobs found: " + theParser.getChildCount("data") + "\n");
for(int i = 0; i < theParser.getChildCount("data"); i++){
System.out.println(String.valueOf(i + 1) + ") " + theParser.getValue("data", "description", i));
System.out.println("\tID: " + theParser.getValue("data", "id", i));
System.out.println("\tURL: " + theParser.getValue("data", "url", i));
System.out.println("\tUsername: " + theParser.getValue("data", "initiator/firstName", i));
}
}catch (IOException ioe) {
// TODO: handle exception
}catch(Exception ex){
}
}
}
Result :
Number of jobs found: 2
1) CS-Outbound-WFPD
ID: activiti$499
URL: api/workflow-instances/activiti$499
Username: Administrator
2) CS-Outbound-WFPD
ID: activiti$404
URL: api/workflow-instances/activiti$404
Username: Administrator
BUT In BIRT Report in eclipse IDE no luck 1, in Scripted Data Source I put:
count = 0;
controller = new Packages.com.actuate.json.JSONParser();
controller.loadData(params["JSONURL"],params["USERNAME"],params["PASSWORD"]);
totalCount = controller.getChildCount("data");
and fetch rows in data set table like :
if(count < totalCount){
row["id"] = controller.getValue("data", "id", count);
row["url"] = controller.getValue("data", "url", count);
count++;
return true;
}
return false
But still giving me white page with head titles only, empty cells !!.
To get exception I uploaded it to Alfresco integrated with BIRT, and I got :
WARNING: Fail to execute script in function __bm_OPEN(). Source:
------
" + count = 0;
controller = new Packages.com.actuate.json.JSONParser();
controller.loadData(params["JSONURL"],params["USERNAME"],params["PASSWORD"]);
totalCount = controller.getChildCount("data"); + "
-----
A BIRT exception occurred. See next exception for more information.
Error evaluating Javascript expression. Script engine error: TypeError: [JavaPackage com.actuate.json.JSONParser] is not a function, it is object. (/report/data-sources/script-data-source[@id="8"]/method[@name="open"]#2)
Script source: /report/data-sources/script-data-source[@id="8"]/method[@name="open"], line: 0, text:
__bm_OPEN()
org.eclipse.birt.data.engine.core.DataException: Fail to execute script in function __bm_OPEN(). Source:
------
" + count = 0;
controller = new Packages.com.actuate.json.JSONParser();
controller.loadData(params["JSONURL"],params["USERNAME"],params["PASSWORD"]);
totalCount = controller.getChildCount("data"); + "
-----
A BIRT exception occurred. See next exception for more information.
Error evaluating Javascript expression. Script engine error: TypeError: [JavaPackage com.actuate.json.JSONParser] is not a function, it is object. (/report/data-sources/script-data-source[@id="8"]/method[@name="open"]#2)
Script source: /report/data-sources/script-data-source[@id="8"]/method[@name="open"], line: 0, text:
__bm_OPEN()
at org.eclipse.birt.data.engine.script.JSMethodRunner.runScript(JSMethodRunner.java:147)
.
.
.
Caused by: org.mozilla.javascript.EcmaError: TypeError: [JavaPackage com.actuate.json.JSONParser] is not a function, it is object. (/report/data-sources/script-data-source[@id="8"]/method[@name="open"]#2)
.
.
.
Really I don't know what the problem is, and how to solve, if anybody have any idea for It, I spent about 1 week on it with no solution ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论