Jump to content

mchisty

Members
  • Posts

    13
  • Joined

  • Last visited

 Content Type 

Forum

Downloads

Featured Visualizations

Knowledge Base

Documentation (PDF Downloads)

Blog

Documentation (Test Area)

Documentation

Dr. Jaspersoft Webinar Series

Security Advisories

Events

Profiles

Posts posted by mchisty

  1. Hi,

    We are using SpringBoot for microservices solution. For reporting solution, we are in the process of migrating to JasperSoft latest version 8.1.x. We have a requirement as follows:

    Step 1: A SpringBoot class/API (@RestController) should invoke a Jasper report API published in JasperServer by passing a list of DTO objects e.g. as a request body. The report URL may look like this http://localhost:8080/jasperserver/rest_v2/reports/LT/stimulus.pdf

    Step 2: The expectation is that the PDF report should be generated based on the json data provided in request body

    Questions:

    Q1. Can you provide any example using which we can achieve the above?

    Please note: Most of the examples online are not very useful; they are very basic and they mostly show about placing the .jrxml or .jasper file within the spring boot application. (screenshot  attached which is a bad example; very old style approach). And this is not what we are looking for. The jrxml/jasper template should only deployed in the jasper server and we want to produce the report by making a REST API call from Java/Spring and passing json data in request body or JRBeanCollection etc.

    Q2. Is there any sample where we can test from Postman API by calling a jasper report by passing json input in request body?

    Your feedback would be appreciable.

    With Thanks.

  2.  Just comment (or remove) those lines in applicationContext-remote-services.xml
    You will find this file under you tomcat directory (e.g. under "..apache-tomcat-9.0.70webappsjasperserverWEB-INFapplicationContext-remote-services.xml" if you have already installed jasper server)


        <util:set id="customDataSourcesToHide">
            <value>remoteXmlDataSource2</value> 
            <value>remoteXmlDataSource</value>  
            <value>mongoDBQueryDataSource2</value> 
            <value>mongoDBQueryDataSource</value>  
            <!-- value>jsonDataSource2</value --> 
            <!-- value>jsonDataSource</value -->  
            <!-- value>jsonQLDataSource</value -->
            <value>jdbcQueryDataSource2</value> 
            <value>jdbcQueryDataSource</value>  
            <!--<value>xlsDataSource</value>   -->
            <!--<value>xlsxDataSource</value> -->
            <value>textDataSource</value> 
            <!-- value>JsonSeriesDataSource</value --> 
            <value>xmlaQueryDataSource</value> 
            <value>cassandraQueryDataSource</value>
            <value>HiveDataSource</value> 
        </util:set>

  3. You should comment those, not uncomment.

    Like this:


        <util:set id="customDataSourcesToHide">
            <value>remoteXmlDataSource2</value> 
            <value>remoteXmlDataSource</value>  
            <value>mongoDBQueryDataSource2</value> 
            <value>mongoDBQueryDataSource</value>  
            <!-- value>jsonDataSource2</value --> 
            <!-- value>jsonDataSource</value -->  
            <!-- value>jsonQLDataSource</value -->
            <value>jdbcQueryDataSource2</value> 
            <value>jdbcQueryDataSource</value>  
            <!--<value>xlsDataSource</value>   -->
            <!--<value>xlsxDataSource</value> -->
            <value>textDataSource</value> 
            <!-- value>JsonSeriesDataSource</value --> 
            <value>xmlaQueryDataSource</value> 
            <value>cassandraQueryDataSource</value>
            <value>HiveDataSource</value> 
        </util:set>

     

     

  4. Hi Mate,

    Thanks for your feedback.

    As you mentioned "You could download the JRXML file via REST and then compile it locally. " ... . That's something I was actually looking for.

    Now to answer your question: "why do you need access to the .jasper file on the server? ", I am providing a piece of code below which is currently working properly in our system. We are using iReport5.5 to design/compile reports. The reports (source/binary) are bundled with our EAR file (e.g. /mars-ejb/resources/META-INF/jasper-reports/reports/espl/esl_ej_final_assessment_notice.jrxml and /mars-ejb/resources/META-INF/jasper-reports/reports/espl/esl_ej_final_assessment_notice.jasper).

    We have two types of reports:

    1. Type (1): SQL query embedded within reports
    2. Type (2): Java ArrayList is populated and filled in report

    We have decided to migrate to TIBCO JasperSoft solutions (with JasperStudio and Jasperreports Server, as because iReport is now deprecated). For this, Type (1) is not a problem. But I do not know how to achieve Type (2) i.e. how do I pass the populated ArrayList objects in .jasper file.

    Our current code is like this:

    public static byte[] generateJasperPdfReport(String path, Map<String, Object> parameters, List<?> objects) throws Exception {    if (StringUtils.isBlank(path)) {        throw new Exception("Report generation path can't be empty");    }    if (null == parameters) {        parameters = new HashMap<>();    }    path = "/META-INF/jasper-reports" + path;    InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);    byte[] bytes = null;    if (null != objects && !objects.isEmpty()) {        bytes = JasperRunManager.runReportToPdf(is, parameters, new JRBeanCollectionDataSource(objects));    } else {        bytes = JasperRunManager.runReportToPdf(is, parameters);    }    return bytes;}[/code]

        
    When we want to generate a report (PDF byestream), we call our util class like this with passing the jasper file location, required parameters and ArrayList:

    E.G.

    List<PslPropertyDetailDTO> properties = ... // Some list of Java DTO objects hereMap<String, Object> parameters = .... // Some parameters provided...// Then invoke the util classbyte fileData[] = ReportUtil.generateJasperPdfReport("/reports/parkingSpaceLevy/psl_modify_property.jasper", parameters, list);[/code]

     

    As you can see, if our report is deployed in the jasper server and our EAR/WAR file is deployed another server (JBoss/Tomcat etc), we cannot locate .jasper file path like this "/reports/parkingSpaceLevy/psl_modify_property.jasper".

    In such a case, your suggestion about "download the JRXML file via REST and then compile it locally" might be one solution.

     

    Question is: how/where can I locate the jrxml file? Is there any example?

    Thanks.

  5. I like to add a bit more:

    The example provided here is applicable only if the report is in the same workstation with java appcation (the jasper report file .jrxml/.jasper is bundled with the web application, deployed in the same web/app server). But what if the report is depoyed in a remote jasper report server and not in the same server with the bundled web app? How do you pass the ArrayList of beans to the jasper file in such a case?

  6. As from the official documentation (JasperReports-Server-REST-API-Reference.pdf), it was found that a sample report (e.g. CutomersReport) published in jasper server can be invoked by the following restful api,

    http://somehost:8080/jasperserver/rest_v2/reports/reports/interactive/CustomersReport.pdf
    or,
    http://somehost:8080/jasperserver/rest_v2/reports/reports/interactive/CustomersReport.csv
    or,
    http://somehost:8080/jasperserver/rest_v2/reports/reports/interactive/CustomersReport.html
    etc

    Question is: is there any way to locate the compiled .jasper file in the report server? (E.G. something like http://somehost:8080/jasperserver/CustomersReport.jasper ???)

    Thanks.

  7. Hi,

    I saw method solutions like this (a sample provided below. Ref URL: https://www.programcreek.com/java-api-examples/index.php?api=net.sf.jasperreports.engine.JasperFillManager):

            try {          Map<String, Object> params = new HashMap<String, Object>(1);          params.put("upit", query);                    JasperPrint jp = JasperFillManager.fillReport(SearchReport.class.getResource(                      "/com/gint/app/bisis4/client/circ/jaspers/searchuser.jasper").openStream(),             params, new JRTableModelDataSource(table));            return jp;        } catch (Exception e) {            log.error(e);            return null;        }[/code]

             

    However, there is not a single solution that says how to fill the report with JavaBean collection/ArrayList if the jasper report file is already deployed on the report server and NOT in the local workstation.

    Just observe the compiled file (searchuser.jasper) location here: "/com/gint/app/bisis4/client/circ/jaspers/searchuser.jasper" which resides in the local host. But a report published in a report server might be somewhere like: http://someJasperHost:8080/XYZ/searchuser.jasper, isn't it?

    Now-a-days, we do not put the .jasper files as bundled with local war/ear file; rather the reports (jrxml and jasper) are meant to be compiled/published on the report server. However, if we have an ArrayList of Java objects (beans/POJOS etc) and we want to fill the .jasper file (which is already published in the report server), how can we acheive that?

    Or, in other words,

    What is the best way to supply the ArrayList of Javabeans to a jasper report located in a jasper server and fill/populate it?


    Is there actually any solution/sample code for this?

    Thanks.

     

×
×
  • Create New...