问题描述
如何通过Jasper PHP / REST API
将报告( jrxml
文件)部署到Jasper Reports Server?
How to deploy a report (jrxml
file) through the Jasper PHP/REST APIto the Jasper Reports Server?
推荐答案
要上传jrxml文件,请使用 PROP_HAS_DATA $创建
ResourceDescriptor
c $ c> = true
并在多部分 PUT
请求中插入jrxml内容。
To upload a jrxml file, create a ResourceDescriptor
with PROP_HAS_DATA
= true
and insert the jrxml content in a multipart PUT
request.
经过一段时间的研究和调查后,我开始运行并开发了一个易于使用的PHP类。
After a while of researching and investigating I got it running and developed a PHP class that's easy to use.
要上传jrxml文件,此代码可以完成工作:
To upload a jrxml file this code does the job:
// Init the Jasper connection
require_once('Jasper/Jasper.php');
$jasper = new \Jasper\Jasper();
$jasper->login('jasperadmin', 'jasperadmin', 'jasper.host.com:8080');
// Create a Resource Descriptor object for the jrxml file
$jrxml = new \Jasper\JasperJrxml('/reports/test.jrxml');
// Upload the Resource Descriptor object with content
$jasper->createContent($jrxml, file_get_contents('templates/test.jrxml'));
要创建报告单位,请继续以下行:
To create a report unit, go on with the following lines:
// Datasource Resource Descriptor
$mongo = new \Jasper\JasperDatasource();
$mongo->setPropIsReference('true');
$mongo->setPropReferenceUri('/datasources/mongo_local_test');
// Put everything together and deploy the report
$report->addChildResource($mongo);
$report->addChildResource($jrxml);
// Want to see the Resource Descriptor of the Report Unit?
// true = pretty print
print_r($report->getXml(true));
// Create a the Report Unit
$jasper->createResource($report);
这篇关于如何通过Jasper PHP / REST API部署报告(jrxml文件)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!