BIRT Scripted Data Source - Dataset with REST Call Fails using XMLHttpRequest
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">I'm trying to use a REST call instead of XML files. I get an error using XMLHttpRequest to retrieve my REST API call to my database server; here is my code which gets data back in responseText as two elements .count and .result[].<br>
If I try this same code in an HTML page it correctly returns my results. I've adapted the 'fetch()' to BIRT syntax to transfer my data to local Data Set values for display in my BIRT Report. I am using a Scripted Data Source, with a Data Set. The only defined Script functions are in the Data Set for open() and fetch() as seen below. I found another thread that suggested using the importPackage( ) seen in my code. Same error with or without it.<br>
The error generated when I try to run it is:<br><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
org.eclipse.birt.report.engine.api.EngineException: There are errors evaluating script</span></p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">"importPackage(javax.xml.parsers);</span><br><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">var xhr = new XMLHttpRequest();</span><br><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">var xhrtoken="concealedtoprotecttheinnocent";</span><br><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">var xhrurl = "http://</span><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">****.****.****.****:YYYY</span><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">/irm/REST/v1.14/pathway-types";</span><br><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">var countIterator = 0;<br>
.<br>
.<br>
.<br>
"</span><br><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">Fail to execute script in function __bm_OPEN(). Source:</span><br><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">
</span><br><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">" + importPackage(javax.xml.parsers);<br>
.<br>
.<br>
.<br>
"</span></p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"><span style="font-size:10px;"><span style="font-size:18px;"><strong><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);">A BIRT exception occurred. See next exception for more information.</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);">ReferenceError: "XMLHttpRequest" is not defined. (/report/data-sets/script-data-set[@id="6"]/method[@name="open"]#3).</span></strong></span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.report.engine.script.internal.DtEScriptExecutor.handleJS(DtEScriptExecutor.java:99)</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.report.engine.script.internal.DataSetScriptExecutor.handleJS(DataSetScriptExecutor.java:256)</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.report.engine.script.internal.ScriptDataSetScriptExecutor.handleOpen(ScriptDataSetScriptExecutor.java:98)</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.data.engine.impl.ScriptDataSetRuntime.open(ScriptDataSetRuntime.java:80)</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.data.engine.impl.PreparedScriptDSQuery$ScriptDSQueryExecutor$CustomDataSet.open(PreparedScriptDSQuery.java:247)</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.data.engine.impl.PreparedScriptDSQuery$ScriptDSQueryExecutor.executeOdiQuery(PreparedScriptDSQuery.java:223)</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.data.engine.impl.QueryExecutor.execute(QueryExecutor.java:1251)</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.data.engine.impl.ServiceForQueryResults.executeQuery(ServiceForQueryResults.java:233)</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.data.engine.impl.QueryResults.getResultIterator(QueryResults.java:178)</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.report.engine.data.dte.QueryResultSet.</span>(QueryResultSet.java:98)<br>
at org.eclipse.birt.report.engine.data.dte.DteDataEngine.doExecuteQuery(DteDataEngine.java:168)<br>
at org.eclipse.birt.report.engine.data.dte.DataGenerationEngine.doExecuteQuery(DataGenerationEngine.java:83)<br>
at org.eclipse.birt.report.engine.data.dte.AbstractDataEngine.execute(AbstractDataEngine.java:286)<br>
at org.eclipse.birt.report.engine.executor.ExecutionContext.executeQuery(ExecutionContext.java:1947)<br>
at org.eclipse.birt.report.engine.executor.QueryItemExecutor.executeQuery(QueryItemExecutor.java:80)<br>
at org.eclipse.birt.report.engine.executor.ListItemExecutor.execute(ListItemExecutor.java:66)<br>
at org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportItemExecutor.execute(WrappedReportItemExecutor.java:46)<br>
at org.eclipse.birt.report.engine.internal.executor.emitter.ReportItemEmitterExecutor.execute(ReportItemEmitterExecutor.java:46)<br>
at org.eclipse.birt.report.engine.internal.executor.dup.SuppressDuplicateItemExecutor.execute(SuppressDuplicateItemExecutor.java:43)<br>
at org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportItemExecutor.execute(WrappedReportItemExecutor.java:46)<br>
at org.eclipse.birt.report.engine.internal.executor.l18n.LocalizedReportItemExecutor.execute(LocalizedReportItemExecutor.java:34)<br>
at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:65)<br>
at org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layout(HTMLPageLM.java:92)<br>
at org.eclipse.birt.report.engine.layout.html.HTMLReportLayoutEngine.layout(HTMLReportLayoutEngine.java:100)<br>
at org.eclipse.birt.report.engine.presentation.ReportDocumentBuilder.build(ReportDocumentBuilder.java:249)<br>
at org.eclipse.birt.report.engine.api.impl.RunTask.doRun(RunTask.java:273)<br>
at org.eclipse.birt.report.engine.api.impl.RunTask.run(RunTask.java:89)<br>
at org.eclipse.birt.report.service.ReportEngineService.runReport(ReportEngineService.java:1325)<br>
at org.eclipse.birt.report.service.BirtViewerReportService.runReport(BirtViewerReportService.java:159)<br>
at org.eclipse.birt.report.service.actionhandler.BirtRunReportActionHandler.__execute(BirtRunReportActionHandler.java:81)<br>
at org.eclipse.birt.report.service.actionhandler.BirtGetPageActionHandler.__checkDocumentExists(BirtGetPageActionHandler.java:58)<br>
at org.eclipse.birt.report.service.actionhandler.AbstractGetPageActionHandler.prepareParameters(AbstractGetPageActionHandler.java:118)<br>
at org.eclipse.birt.report.service.actionhandler.AbstractGetPageActionHandler.__execute(AbstractGetPageActionHandler.java:103)<br>
at org.eclipse.birt.report.service.actionhandler.AbstractBaseActionHandler.execute(AbstractBaseActionHandler.java:90)<br>
at org.eclipse.birt.report.soapengine.processor.AbstractBaseDocumentProcessor.__executeAction(AbstractBaseDocumentProcessor.java:47)<br>
at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.executeAction(AbstractBaseComponentProcessor.java:143)<br>
at org.eclipse.birt.report.soapengine.processor.BirtDocumentProcessor.handleGetPage(BirtDocumentProcessor.java:87)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)<br>
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)<br>
at java.lang.reflect.Method.invoke(Unknown Source)<br>
at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.process(AbstractBaseComponentProcessor.java:112)<br>
at org.eclipse.birt.report.soapengine.endpoint.BirtSoapBindingImpl.getUpdatedObjects(BirtSoapBindingImpl.java:66)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)<br>
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)<br>
at java.lang.reflect.Method.invoke(Unknown Source)<br>
at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)<br>
at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)<br>
at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)<br>
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)<br>
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)<br>
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)<br>
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)<br>
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)<br>
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)<br>
at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.doPost(BirtSoapMessageDispatcherServlet.java:265)<br>
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)<br>
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)<br>
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)<br>
at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.service(BirtSoapMessageDispatcherServlet.java:122)<br>
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:845)<br>
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1689)<br>
at org.eclipse.birt.report.filter.ViewerFilter.doFilter(ViewerFilter.java:68)<br>
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1668)<br>
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:581)<br>
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)<br>
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)<br>
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)<br>
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1174)<br>
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)<br>
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)<br>
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1106)<br>
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)<br>
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)<br>
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:119)<br>
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)<br>
at org.eclipse.jetty.server.Server.handle(Server.java:524)<br>
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:319)<br>
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:253)<br>
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)<br>
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)<br>
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)<br>
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303)<br>
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148)<br>
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136)<br>
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)<br>
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589)<br>
at java.lang.Thread.run(Unknown Source)</span></p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"><br><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);"><span style="font-size:14px;">Here is my code, do you have any suggestions?</span><br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span></p>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">Dataset - open()</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">importPackage(javax.xml.parsers);</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">var xhr = new XMLHttpRequest();</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">var xhrtoken="specialstringtoauthenticatemyconnection";</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">var xhrurl = "<a class="bbc_url" href="http://****.****.****.****/irm/REST/v1.14/pathway-types" title="External link">http://****.****.****.X...pathway-types";</a></div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">var countIterator = 0;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">var countMax = 0;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">function myFunction(respFromReq) {</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">respText = JSON.parse(this.responseText); // assign to global the data returned.</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">countMax = respText.count; // respText has two elements; .count and .result[]</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">}</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">xhr.onreadystatechange = function() {// function to call when the XHR request completes</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> if (this.readyState == 4 && this.status == 200) </div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> {</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">myFunction(xhr); // call MyFunction if we have data.</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> }</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> else if (this.readyState == 4)</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> respText = "FAILED status = " + this.status;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">};</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">xhr.open("GET", xhrurl, true);</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">xhr.setRequestHeader("Irm-AccessKey", xhrtoken);</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">xhr.setRequestHeader("Accept", "application/json");</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">xhr.setRequestHeader("Content-Type", "application/json");</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">xhr.send();</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">Dataset - fetch()</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">~~~~~~~~~~~~~~~~~~~~~~~~~~~~</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">if (countIterator < respText.count)</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">{</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">// My understanding is 'fetch()' is called each time a record is requested.</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">// In 'open()' we defined a variable countIterator which holds the current index into</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">// the result[] array containing the data. if the count isn't exhausted</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">// we transfer the data to local BIRT variables and increment the counter.</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">row["__type"] = respText.result[countIterator].__type;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">row["_12884901926_description"] = respText.result[countIterator]._12884901926_description;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">row["_12884901926_endAOpeningSize"] = respText.result[countIterator]._12884901926_endAOpeningSize;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">row["_12884901926_endBOpeningSize"] = respText.result[countIterator]._12884901926_endBOpeningSize;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">row["_12884901926_endOpeningType"] = respText.result[countIterator]._12884901926_endOpeningType;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">row["_12884901926_material"] = respText.result[countIterator]._12884901926_material;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">countIterator++;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">return true;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">}</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">else return false; </div>
If I try this same code in an HTML page it correctly returns my results. I've adapted the 'fetch()' to BIRT syntax to transfer my data to local Data Set values for display in my BIRT Report. I am using a Scripted Data Source, with a Data Set. The only defined Script functions are in the Data Set for open() and fetch() as seen below. I found another thread that suggested using the importPackage( ) seen in my code. Same error with or without it.<br>
The error generated when I try to run it is:<br><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
org.eclipse.birt.report.engine.api.EngineException: There are errors evaluating script</span></p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">"importPackage(javax.xml.parsers);</span><br><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">var xhr = new XMLHttpRequest();</span><br><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">var xhrtoken="concealedtoprotecttheinnocent";</span><br><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">var xhrurl = "http://</span><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">****.****.****.****:YYYY</span><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">/irm/REST/v1.14/pathway-types";</span><br><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">var countIterator = 0;<br>
.<br>
.<br>
.<br>
"</span><br><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">Fail to execute script in function __bm_OPEN(). Source:</span><br><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">
</span><br><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);">" + importPackage(javax.xml.parsers);<br>
.<br>
.<br>
.<br>
"</span></p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"><span style="font-size:10px;"><span style="font-size:18px;"><strong><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);">A BIRT exception occurred. See next exception for more information.</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);">ReferenceError: "XMLHttpRequest" is not defined. (/report/data-sets/script-data-set[@id="6"]/method[@name="open"]#3).</span></strong></span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.report.engine.script.internal.DtEScriptExecutor.handleJS(DtEScriptExecutor.java:99)</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.report.engine.script.internal.DataSetScriptExecutor.handleJS(DataSetScriptExecutor.java:256)</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.report.engine.script.internal.ScriptDataSetScriptExecutor.handleOpen(ScriptDataSetScriptExecutor.java:98)</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.data.engine.impl.ScriptDataSetRuntime.open(ScriptDataSetRuntime.java:80)</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.data.engine.impl.PreparedScriptDSQuery$ScriptDSQueryExecutor$CustomDataSet.open(PreparedScriptDSQuery.java:247)</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.data.engine.impl.PreparedScriptDSQuery$ScriptDSQueryExecutor.executeOdiQuery(PreparedScriptDSQuery.java:223)</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.data.engine.impl.QueryExecutor.execute(QueryExecutor.java:1251)</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.data.engine.impl.ServiceForQueryResults.executeQuery(ServiceForQueryResults.java:233)</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.data.engine.impl.QueryResults.getResultIterator(QueryResults.java:178)</span><br><span style="color:rgb(0,0,0);font-family:monospace;background-color:rgb(255,255,239);"> at org.eclipse.birt.report.engine.data.dte.QueryResultSet.</span>(QueryResultSet.java:98)<br>
at org.eclipse.birt.report.engine.data.dte.DteDataEngine.doExecuteQuery(DteDataEngine.java:168)<br>
at org.eclipse.birt.report.engine.data.dte.DataGenerationEngine.doExecuteQuery(DataGenerationEngine.java:83)<br>
at org.eclipse.birt.report.engine.data.dte.AbstractDataEngine.execute(AbstractDataEngine.java:286)<br>
at org.eclipse.birt.report.engine.executor.ExecutionContext.executeQuery(ExecutionContext.java:1947)<br>
at org.eclipse.birt.report.engine.executor.QueryItemExecutor.executeQuery(QueryItemExecutor.java:80)<br>
at org.eclipse.birt.report.engine.executor.ListItemExecutor.execute(ListItemExecutor.java:66)<br>
at org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportItemExecutor.execute(WrappedReportItemExecutor.java:46)<br>
at org.eclipse.birt.report.engine.internal.executor.emitter.ReportItemEmitterExecutor.execute(ReportItemEmitterExecutor.java:46)<br>
at org.eclipse.birt.report.engine.internal.executor.dup.SuppressDuplicateItemExecutor.execute(SuppressDuplicateItemExecutor.java:43)<br>
at org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportItemExecutor.execute(WrappedReportItemExecutor.java:46)<br>
at org.eclipse.birt.report.engine.internal.executor.l18n.LocalizedReportItemExecutor.execute(LocalizedReportItemExecutor.java:34)<br>
at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:65)<br>
at org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layout(HTMLPageLM.java:92)<br>
at org.eclipse.birt.report.engine.layout.html.HTMLReportLayoutEngine.layout(HTMLReportLayoutEngine.java:100)<br>
at org.eclipse.birt.report.engine.presentation.ReportDocumentBuilder.build(ReportDocumentBuilder.java:249)<br>
at org.eclipse.birt.report.engine.api.impl.RunTask.doRun(RunTask.java:273)<br>
at org.eclipse.birt.report.engine.api.impl.RunTask.run(RunTask.java:89)<br>
at org.eclipse.birt.report.service.ReportEngineService.runReport(ReportEngineService.java:1325)<br>
at org.eclipse.birt.report.service.BirtViewerReportService.runReport(BirtViewerReportService.java:159)<br>
at org.eclipse.birt.report.service.actionhandler.BirtRunReportActionHandler.__execute(BirtRunReportActionHandler.java:81)<br>
at org.eclipse.birt.report.service.actionhandler.BirtGetPageActionHandler.__checkDocumentExists(BirtGetPageActionHandler.java:58)<br>
at org.eclipse.birt.report.service.actionhandler.AbstractGetPageActionHandler.prepareParameters(AbstractGetPageActionHandler.java:118)<br>
at org.eclipse.birt.report.service.actionhandler.AbstractGetPageActionHandler.__execute(AbstractGetPageActionHandler.java:103)<br>
at org.eclipse.birt.report.service.actionhandler.AbstractBaseActionHandler.execute(AbstractBaseActionHandler.java:90)<br>
at org.eclipse.birt.report.soapengine.processor.AbstractBaseDocumentProcessor.__executeAction(AbstractBaseDocumentProcessor.java:47)<br>
at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.executeAction(AbstractBaseComponentProcessor.java:143)<br>
at org.eclipse.birt.report.soapengine.processor.BirtDocumentProcessor.handleGetPage(BirtDocumentProcessor.java:87)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)<br>
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)<br>
at java.lang.reflect.Method.invoke(Unknown Source)<br>
at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.process(AbstractBaseComponentProcessor.java:112)<br>
at org.eclipse.birt.report.soapengine.endpoint.BirtSoapBindingImpl.getUpdatedObjects(BirtSoapBindingImpl.java:66)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)<br>
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)<br>
at java.lang.reflect.Method.invoke(Unknown Source)<br>
at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)<br>
at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)<br>
at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)<br>
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)<br>
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)<br>
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)<br>
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)<br>
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)<br>
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)<br>
at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.doPost(BirtSoapMessageDispatcherServlet.java:265)<br>
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)<br>
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)<br>
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)<br>
at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.service(BirtSoapMessageDispatcherServlet.java:122)<br>
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:845)<br>
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1689)<br>
at org.eclipse.birt.report.filter.ViewerFilter.doFilter(ViewerFilter.java:68)<br>
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1668)<br>
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:581)<br>
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)<br>
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)<br>
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)<br>
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1174)<br>
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)<br>
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)<br>
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1106)<br>
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)<br>
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)<br>
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:119)<br>
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)<br>
at org.eclipse.jetty.server.Server.handle(Server.java:524)<br>
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:319)<br>
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:253)<br>
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)<br>
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)<br>
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)<br>
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303)<br>
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148)<br>
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136)<br>
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)<br>
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589)<br>
at java.lang.Thread.run(Unknown Source)</span></p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"><br><span style="color:rgb(0,0,0);font-family:monospace;font-size:10.6667px;background-color:rgb(255,255,239);"><span style="font-size:14px;">Here is my code, do you have any suggestions?</span><br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span></p>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">Dataset - open()</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">importPackage(javax.xml.parsers);</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">var xhr = new XMLHttpRequest();</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">var xhrtoken="specialstringtoauthenticatemyconnection";</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">var xhrurl = "<a class="bbc_url" href="http://****.****.****.****/irm/REST/v1.14/pathway-types" title="External link">http://****.****.****.X...pathway-types";</a></div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">var countIterator = 0;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">var countMax = 0;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">function myFunction(respFromReq) {</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">respText = JSON.parse(this.responseText); // assign to global the data returned.</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">countMax = respText.count; // respText has two elements; .count and .result[]</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">}</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">xhr.onreadystatechange = function() {// function to call when the XHR request completes</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> if (this.readyState == 4 && this.status == 200) </div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> {</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">myFunction(xhr); // call MyFunction if we have data.</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> }</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> else if (this.readyState == 4)</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> respText = "FAILED status = " + this.status;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">};</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">xhr.open("GET", xhrurl, true);</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">xhr.setRequestHeader("Irm-AccessKey", xhrtoken);</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">xhr.setRequestHeader("Accept", "application/json");</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">xhr.setRequestHeader("Content-Type", "application/json");</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">xhr.send();</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">Dataset - fetch()</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">~~~~~~~~~~~~~~~~~~~~~~~~~~~~</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">if (countIterator < respText.count)</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">{</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">// My understanding is 'fetch()' is called each time a record is requested.</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">// In 'open()' we defined a variable countIterator which holds the current index into</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">// the result[] array containing the data. if the count isn't exhausted</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">// we transfer the data to local BIRT variables and increment the counter.</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">row["__type"] = respText.result[countIterator].__type;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">row["_12884901926_description"] = respText.result[countIterator]._12884901926_description;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">row["_12884901926_endAOpeningSize"] = respText.result[countIterator]._12884901926_endAOpeningSize;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">row["_12884901926_endBOpeningSize"] = respText.result[countIterator]._12884901926_endBOpeningSize;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">row["_12884901926_endOpeningType"] = respText.result[countIterator]._12884901926_endOpeningType;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">row["_12884901926_material"] = respText.result[countIterator]._12884901926_material;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">countIterator++;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">return true;</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">}</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">else return false; </div>
0
Comments
-
<p>XMLHttpRequest is not in a Java package, it part of JavaScript. You don't need a AJAX client in this case.</p>
<p> </p>
<p>If you can use commercial BIRT, iHub 16, then we've included a new feature, a REST API data connector.</p>
<p> </p>
<p>If not, you can check out this DevShare that uses a scripted data set against a REST API in JSON format @ <a data-ipb='nomediaparse' href='http://developer.actuate.com/community/forum/index.php?/files/file/1128-querying-elasticsearch-with-birt-using-a-scripted-data-set/'>http://developer.actuate.com/community/forum/index.php?/files/file/1128-querying-elasticsearch-with-birt-using-a-scripted-data-set/</a></p>
<p> </p>
<p>Also, for reference, here is another example but with XML @ <a data-ipb='nomediaparse' href='http://developer.actuate.com/community/forum/index.php?/files/file/1122-parsing-xml-in-birt-with-e4x/'>http://developer.actuate.com/community/forum/index.php?/files/file/1122-parsing-xml-in-birt-with-e4x/</a></p>
Warning No formatter is installed for the format ipb0 -
@Clement Wong can't get the links above, could you please share the examples here? thanks!
0 -
@birtCubes The ElasticSearch DevShare is now @ https://communities.opentext.com/forums/discussion/61521/example-of-connecting-to-elasticsearch-using-birt-with-a-scripted-data-set
The XML parsing using E4X is here @ https://communities.opentext.com/forums/discussion/61515/parse-xml-using-rhino-included-e4x-much-easier-than-using-sax-or-dom
The attachments need to be renamed to .ZIP for the first, and .RPTDESIGN for the second. I've put a request to get that fixed. Also, I'll work on editing the second article since the formatting wasn't ported over properly.
Warning No formatter is installed for the format ipb0
Categories
- All Categories
- 108 Developer Announcements
- 53 Articles
- 106 General Questions
- 145 IM Services
- 43 OpenText Hackathon
- 32 Developer Tools
- 20.6K Analytics
- 4.1K AppWorks
- 8.9K Extended ECM
- 899 Cloud Fax and Notifications
- 77 Digital Asset Management
- 9.3K Documentum
- 29 eDOCS
- 120 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management