12 Replies Latest reply on Nov 14, 2011 12:45 PM by Jason Porter

    Seam Reports Jasper and Jboss-javaee6

    Christophe Boudjennah Newbie

      Hello everybody.
      I have a big problem trying ti use seam report.
      Basically, we made a JEE application using Seam 3 and Wicket and I have to create a feature allowing to use jasper reports  to create reports.
      We use jboss-javaee-6.0 for injection mechanism.
      The module which should contain this feature depends on jboss-javaee-6.0.
      When I add the seam-reports-api dependancy I have no problem deploying my application on JBoss.
      But I want to use Jasper reports. So I want to depends on seam-reports-jasper too.
      And when I do so, the deployment in Jboss cannot be done.
      I have indeed this error:




      17:06:55,876 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/ucmt2]] Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.jboss.weld.integration.webtier.jsp.JspInitializationListener: java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.enterprise.inject.spi.BeanManager.getELResolver()Ljavax/el/ELResolver;" the class loader (instance of org/jboss/classloader/spi/base/BaseClassLoader) of the current class, org/jboss/weld/integration/webtier/jsp/JspInitializationListener, and the class loader (instance of org/jboss/classloader/spi/base/BaseClassLoader) for resolved class, javax/enterprise/inject/spi/BeanManager, have different Class objects for the type javax/el/ELResolver used in the signature



      So what I understood is that there some trouble regarding some EL component.
      If I look more closely on the dependancies hierarchy, I can see that:
      .jboss-javaee-6.0 1.0.0.Beta7 depends on jboss-el-api2.2spec 1.0.0.Beta1
      .seam-reports-jasper depends on el-api 2.2


      Does anybody ever have a clue about what I should do to make it work???
      Thanks veeeeery much in advance!!!
      Maybe a problem with version numbers?
      I set in my pom version 3.1.0.Beta1 for seam report components and no specific version for jboss-javaee-6.0.


      Regards,


      Chris


        • 1. Re: Seam Reports Jasper and Jboss-javaee6
          Jason Porter Master

          Try excluding one of the EL libraries, or make the jboss-javaee-6.0 provided scope.

          • 2. Re: Seam Reports Jasper and Jboss-javaee6
            Christophe Boudjennah Newbie

            Jason Porter wrote on Nov 07, 2011 13:10:


            Try excluding one of the EL libraries, or make the jboss-javaee-6.0 provided scope.


            Thanks a lot!!!
            I excluded el-api from the seam-report-jasper dependancy and now I can deploy it :D!!!!!

            • 3. Re: Seam Reports Jasper and Jboss-javaee6
              Christophe Boudjennah Newbie

              OK.
              Now I have another problem. I try to build a report programaticcaly and I have a



              org.jboss.seam.reports.exceptions.IllegalReportDataSourceException




              when I call



              |ReportDefinition::fill(...)|



              Here is the class where I try to do that:




              "@Inject
                   @Resource("WEB-INF/jasperreports/project.jasper")
                   private InputStream reportJasper;
              
                   @Inject
                   @Jasper
                   private ReportCompiler reportCompiler;
              
                   @Inject
                   @Jasper
                   @PDF
                   private ReportRenderer pdfRenderer;
              
                   //
                    @Inject
                    @Jasper
                    ReportLoader reportLoader;
              
              public OutputStream render() {
                        final Report filledReport = this.fillReport();
                        final OutputStream os = new ByteArrayOutputStream();
              
                        try {
                             this.pdfRenderer.render(filledReport, os);
                        } catch (IOException e) {
                             // TODO Auto-generated catch block
                             e.printStackTrace();
                        }
                        return os;
                   }
              
                   private Report fillReport() {
                        final ReportDefinition rd = reportLoader.loadReportDefinition(reportJasper);
              
                        Map parameters = new HashMap();
                        EntityManager entityManager = dbUtil.getEntityManager();
                        parameters.put(JRJpaQueryExecuterFactory.PARAMETER_JPA_ENTITY_MANAGER,
                                  entityManager);
                        parameters.put("PROJECT_ID", "1");
              
                        return rd.fill(entityManager, parameters);
                   }"



              Do you have an idea of what I did wrong???


              • 4. Re: Seam Reports Jasper and Jboss-javaee6
                Christophe Boudjennah Newbie

                For info I called the report via a small java program with the same parameters and it worked...

                • 5. Re: Seam Reports Jasper and Jboss-javaee6
                  Christophe Boudjennah Newbie

                  I debugged a little further and I saw that at some point the framework tried to cast my datasource to a JRDataSource.
                  And it cannot work because I pass it my application EntityManager and, thus, the datasource is a TransactionScopedEntityManager.
                  How can I manage to give it a suitable datasource?


                  Thanks in advance :)!!!

                  • 6. Re: Seam Reports Jasper and Jboss-javaee6
                    Jason Porter Master

                    You'll have to look at the JasperReports classes and find an instance of JRDataSource which will work for you, create that and pass that in.

                    • 7. Re: Seam Reports Jasper and Jboss-javaee6
                      Christophe Boudjennah Newbie

                      I understood that :) But I really don't see how to build an appropriate JRDatasource which would encapsulate my EntityManager (since I don't want to pass any query via java, all queries are included in the reports and subreports. I only give the entry point report a paramater which is an id).

                      • 8. Re: Seam Reports Jasper and Jboss-javaee6
                        Christophe Boudjennah Newbie
                        OK I tried another way. I made something like this:



                        `Map parameters = new HashMap();
                                        EntityManager entityManager = dbUtil.getEntityManager();
                                        parameters.put(JRJpaQueryExecuterFactory.PARAMETER_JPA_ENTITY_MANAGER, entityManager);
                                        parameters.put("USECASE_ID", "6");

                                        try {
                                               

                                        JasperExportManager.exportReportToPdf(fillReport);
                                               
                                                byte[] runReportToPdf = JasperRunManager.runReportToPdf(
                                                                reportJasper, parameters);

                                                reportJasper.close();

                                                final ByteArrayOutputStream os = new ByteArrayOutputStream();

                                                os.write(runReportToPdf);

                                                return os;
                                        } catch (JRException e) {
                                                // TODO Auto-generated catch block
                                                e.printStackTrace();
                                        } catch (IOException e) {
                                                // TODO Auto-generated catch block
                                                e.printStackTrace();
                                        }`

                        But it seems that the report is not filled. I mean I have several logs like:



                        `18:07:18,903 INFO  [STDOUT] DEBUG 09-11 18:07:18,902 (JRBaseFiller.java:fill:883)  -Fill 386453935: filling report

                        18:07:18,906 INFO  [STDOUT] DEBUG 09-11 18:07:18,905 (JRFillDataset.java:createQueryDatasource:677)  -Fill 386453935: Creating sql query executer

                        18:07:18,909 INFO  [STDOUT] WARN  09-11 18:07:18,908 (JRJdbcQueryExecuter.java:<init>:109)  -The supplied java.sql.Connection object is null.

                        18:07:18,912 INFO  [STDOUT] DEBUG 09-11 18:07:18,910 (JRJdbcQueryExecuter.java:createStatement:183)  -SQL query string: SELECT * FROM usecase_description where usecase_ID = ?

                        18:07:18,920 INFO  [STDOUT] DEBUG 09-11 18:07:18,913 (JRVerticalFiller.java:fillReport:141)  -Fill 386453935: no data

                        18:07:18,922 INFO  [STDOUT] DEBUG 09-11 18:07:18,921 (JRVerticalFiller.java:fillReport:217)  -Fill 386453935: no pages

                        18:07:18,924 INFO  [STDOUT] DEBUG 09-11 18:07:18,923 (JRBaseFiller.java:fill:956)   - Fill 386453935: ended `

                        It's like the paramater called USECASE_ID is not passed to the report . And i'm sure of the paramater name and the data with its value set to 6 (running the report with iReport and this parameter leads to a correct result). And the EntityManager I use must be correct because it is used in the whole application

                        Any idea??


                        • 9. Re: Seam Reports Jasper and Jboss-javaee6
                          George Gastaldi Master

                          You must use net.sf.jasperreports.engine.data.JRJpaDataSource as the JRDataSource parameter in ReportDefinition.fill() method. The rest of the code looks ok.

                          • 10. Re: Seam Reports Jasper and Jboss-javaee6
                            Christophe Boudjennah Newbie

                            George Gastaldi wrote on Nov 11, 2011 08:08:


                            You must use net.sf.jasperreports.engine.data.JRJpaDataSource as the JRDataSource parameter in ReportDefinition.fill() method. The rest of the code looks ok.


                            OK, I see :)
                            But how do I instantiate a correct JRDataSource starting from an EntityManager, or a standart datasource which I also have? Cause I tried something like this:


                                 


                            Report filled = loadReportDefinition.fill(dbUtil.getDataSource(),
                                                     parameters);



                            And I have an InvalidDataSourceException. So i'm pretty sure I should have a SeamJasper specific encapsulation of my datasource here but I don't know how to build it :-(


                            I tried to inject a JRDataSource but it seams the framework cannot inject (I have a missing dependancy exception at deployment).
                            Searching on the web, I found this:
                            https://gist.github.com/969969
                            They use a SeamReportDataSource which seems to fit the need, but I cannot find it in seam-reports-api neither in seam-reports-jasper :-(...

                            • 11. Re: Seam Reports Jasper and Jboss-javaee6
                              Christophe Boudjennah Newbie

                              OK. I succeeded into making it work. I mean at least being able to generate locally a pdf for tests.
                              I made it like this:




                                 Map parameters = new HashMap();
                                               EntityManager entityManager = dbUtil.getEntityManager();
                                              
                                               parameters.put(JRJpaQueryExecuterFactory.PARAMETER_JPA_ENTITY_MANAGER,
                                               entityManager);
                                              
                                               parameters.put(JRParameter.REPORT_CONNECTION,
                                               dbUtil.getConnection());
                              
                                      parameters.put("USECASE_ID", "6");
                                                      parameters.put("TITLE_LEVEL", 0);
                              
                                      JasperReport compiledReport = JasperCompileManager
                                                                      .compileReport(reportTemplate);
                              
                                                      
                                                      JasperPrint fillReport = JasperFillManager.fillReport(
                                                                      compiledReport, parameters, dbUtil.getConnection());
                              
                              //For test
                               JasperExportManager.exportReportToPdfFile(fillReport,
                                                       "C:\\Users\\test\\report.pdf");






                              :)

                              • 12. Re: Seam Reports Jasper and Jboss-javaee6
                                Jason Porter Master

                                Glad you found something that worked. As far as injection, no, you won't be able to inject them because the Jasper jar isn't a Bean Archive as it doesn't have a beans.xml. You'd need to create a producer for it. I wonder if there's value in adding a wrapper in Seam Reports.