使用jrs-rest-java-client将数据源注入到报表中 [英] Inject a datasource using jrs-rest-java-client to a report
本文介绍了使用jrs-rest-java-client将数据源注入到报表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用JasperReports Server及其 jrs-rest-java-client API 。当我访问远程服务器时,我想要注入报告应该使用的数据源(在我的情况下,它是一个数据库)。我不知道是否可以使用此API执行此操作。
I am using JasperReports Server with its jrs-rest-java-client API. When I access the remote server I want to inject the datasource (in my case it is a database) that the report should use. I do not know if it is possible to do it using this API.
推荐答案
是的,有可能。这是我在JasperReports Server v6.2.1中使用jrs-rest-java-client v6.2.3的方式:
Yes, it is possible. This is how I do it in JasperReports Server v6.2.1 with the jrs-rest-java-client v6.2.3:
// build configuration object
RestClientConfiguration configuration = new RestClientConfiguration("http://localhost:8080/jasperserver");
configuration.setContentMimeType(MimeType.JSON);
configuration.setAcceptMimeType(MimeType.JSON);
configuration.setAuthenticationType(AuthenticationType.SPRING);
configuration.setLogHttp(true);
configuration.setLogHttpEntity(true);
// build client and authenticate
JasperserverRestClient client = new JasperserverRestClient(configuration);
Session session = client.authenticate("jasperadmin", "jasperadmin");
String reportUnitUri = "/path/to/reportUnit";
// first get the version of the reportUnit to prevent update conflicts from optimistic locking
OperationResult<ClientReportUnit> reportUnitOperationResult = session.resourcesService().resource(reportUnitUri).get(ClientReportUnit.class);
Integer reportUnitVersion = reportUnitOperationResult.getEntity().getVersion();
// build patchDescriptor with the dataSource field
PatchDescriptor patchDescriptor = new PatchDescriptor();
patchDescriptor.setVersion(reportUnitVersion);
patchDescriptor.field("dataSource", "/path/to/repository/dataSource");
// apply the patchDescriptor
session.resourcesService().resource(reportUnitUri).patchResource(ClientReportUnit.class, patchDescriptor);
这篇关于使用jrs-rest-java-client将数据源注入到报表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文