【问题标题】:Inject a datasource using jrs-rest-java-client to a report使用 jrs-rest-java-client 将数据源注入到报表中
【发布时间】:2016-07-03 13:11:34
【问题描述】:

我正在使用带有 jrs-rest-java-client API 的 JasperReports 服务器。当我访问远程服务器时,我想注入报告应该使用的数据源(在我的情况下是数据库)。我不知道是否可以使用这个 API 来做到这一点。

【问题讨论】:

    标签: rest jasper-reports jasperserver


    【解决方案1】:

    是的,这是可能的。这就是我在 JasperReports Server v6.2.1 中使用 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-01
      • 1970-01-01
      相关资源
      最近更新 更多