How to get the ReportDesign class of some subrepor

2019-06-05 21:26发布

问题:

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.