1

如何jrxml通过 Jasper PHP/REST API 将报告(文件)部署到 Jasper Reports Server?

4

2 回答 2

6

要使用 Rest-API 在 Jasper 服务器上部署 Jasper 报告,您可以使用以下方法:

上传 JRXML 文件

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

reportUnit 示例的 ResourceDescriptor

{
    "uri": "/reports/test_report", 
    "label": "test_report", 
    "description": "description", 
    "permissionMask": "0",
    "version": "0" ,
    "alwaysPromptControls": "true",
    "controlsLayout": "popupScreen",
    "jrxml": {
        "jrxmlFileReference": {
            "uri": "/reports/test"
        }
    }
}

资源描述符引用

http://community.jaspersoft.com/documentation/jasperreports-server-web-services-guide/v56/v2-resource-descriptor-types

于 2015-08-27T12:16:42.623 回答
1

要上传 jrxml 文件,请创建一个ResourceDescriptorwith PROP_HAS_DATA=true并将 jrxml 内容插入到多部分PUT请求中。

经过一段时间的研究和调查,我让它运行起来并开发了一个易于使用的 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);
于 2013-07-19T09:07:02.137 回答