如何通过Jasper PHP / REST API部署报告(jrxml
文件)
到Jasper Reports Server?
答案 0 :(得分:6)
要使用Rest-API在Jasper Server上部署Jasper报告,您可以使用以下方法:
JRXML_DATA=$(cat $PATHTOJRXMLFILE/$JRXML_FILE)
curl -X POST $JASPER_REST_HOST/jasperserver/rest_v2/resources/reports \
-H "Content-Type:application/jrxml" \
-H "Content-Disposition:attachment; filename=test" \
-H "Content-Description:test file" \
-d "$JRXML_DATA" \
--user $JASPER_USERNAME:$JASPER_USERNAME
RESOURCEDESCRIPTOR_JSON=$(cat $REPORT/deployable/reportunit.json)
curl -X POST $JASPER_REST_HOST/jasperserver/rest_v2/resources/reports \
-H "Content-Type:application/repository.reportUnit+json" \
-d "$RESOURCEDESCRIPTOR_JSON" \
--user $JASPER_USERNAME:$JASPER_PASSWORD
{
"uri": "/reports/test_report",
"label": "test_report",
"description": "description",
"permissionMask": "0",
"version": "0" ,
"alwaysPromptControls": "true",
"controlsLayout": "popupScreen",
"jrxml": {
"jrxmlFileReference": {
"uri": "/reports/test"
}
}
}
答案 1 :(得分:1)
要上传jrxml文件,请使用ResourceDescriptor
= PROP_HAS_DATA
创建true
,然后在多部分PUT
请求中插入jrxml内容。
经过一段时间的研究和调查后,我开始运行并开发了一个易于使用的PHP类。
http://blog.flowl.info/2013/jasper-php-library-on-github/
要上传jrxml文件,此代码可以完成工作:
// 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'));
要创建报告单位,请继续以下行:
// 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);