How to get the ReportDesign class of some subreport on the server for scriptlet-based modifications?

给你一囗甜甜゛ 提交于 2019-12-23 00:30:14

问题


Locally I have a master.jrxml report and some subreport.jrxml and can load and manipulate the subreport via ReportDesign design = JRXmlLoader.load( "/local-file-dir/path/to/subreport.jrxml" ) in the Scriptlet code.

On the server, the above load method (trigged by my master.jrxml) obviously cannot deal with repo paths, no matter what I tried (basically net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: ...)

(subreport.jrxml uploaded as a JRXML File Resource - not as Report with invisibly created folder structures ; subreport-attached.jrxml uploaded as a file resource of my master.jrxml Report )

  • apwop) absolute repo path without protocol prefix, e.g. /repo/path/subreport.jrxml
  • apwp) absolute repo path with protocol prefix, e.g. repo:/repo/path/subreport.jrxml
  • rpwop) relative repo path without protocol prefix, e.g. subreport-attached.jrxml
  • rpwp) relative repo path with protocol prefix, e.g. repo:subreport-attached.jrxml

I also tried the following with the above uri variants as found elsewhere in the web without success:

  • JRXmlLoader:

    JRXmlLoader.load(
      new DefaultRepositoryService( 
        DefaultJasperReportsContext.getInstance() 
      ).getInputStream( subrepPath )
    
  • RepositoryUtil:

    RepositoryUtil.getInstance( 
      DefaultJasperReportsContext.getInstance() 
    ).getInputStreamFromLocation( subrepPath )
    
  • JasperServerUtil: similar to this I am still trying out and will report back (had problems with proper Maven jasperserver libraries support till now - other problem I may address in another question)
    • update: it worked: see my answer below

回答1:


Woohoo! :) The last approach with the com.jaspersoft.jasperserver.api.metadata.common.service.RepositoryService worked like this:

JasperDesign design = JRXmlLoader.load(
   ( (RepositoryService) StaticApplicationContext.getApplicationContext()
     .getBean( "repositoryService" ) 
   )
   .getResourceData( JasperServerUtil.getExecutionContext() , 
     "repo:/some/where/subreport.jrxml" )
   .getDataStream()

Puh! hard birth.



来源:https://stackoverflow.com/questions/37960315/how-to-get-the-reportdesign-class-of-some-subreport-on-the-server-for-scriptlet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!