report generation issue

0

Hi Team ,

 

I Have created an application for generating Jasper Report .In that application , I have created a servlet  that is calling jrxml report and exporting it to PDF formet .That application i have deployed as a EAR on weblogic server . 

In my local server it is running fine while executing servlet through URL .But on server it is giving me error while exporting report to PDF file  . Below is code , dev server exception log and URL to access servel .

APP URL : 

http://localhost:7101/RestApiJasperCallApi/reportServlet?BOOKING_ID="123123123"

Server log:

####<Apr 15, 2019, 9:07:18,306 AM UTC> <Error> <HTTP> <twjcs-wls-1.compute-603777986.oraclecloud.internal> <TWJCS_do_server_1> <[ACTIVE] ExecuteThread: '25' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <8c851a43-c92e-40df-8c85-94090c59ed45-0001fea8> <1555319238306> <[severity-value: 8] [rid: 0] [partition-id: 0] [partition-name: DOMAIN] > <BEA-101017> <[ServletContext@512052688[app:RestApiJasperCallApi module:RestApiJasperCallApi path:null spec-version:3.1]] Root cause of ServletException.
java.lang.NullPointerException
    at net.sf.jasperreports.engine.JRAbstractExporter.ensureInput(JRAbstractExporter.java:692)
    at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:503)
    at net.sf.jasperreports.engine.JasperExportManager.exportToPdfStream(JasperExportManager.java:198)
    at net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfStream(JasperExportManager.java:535)
    at view.servlets.ReportServlet.doGet(ReportServlet.java:68)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

I am using Jasper soft 6.5.1 final version for creating jasper report . and below jars in my application :

1:jasperreport 5.6.0 , jasperreport-font-5.6.0, IText -2.1.7.js2 , Common-Digester-2.1 , Jdt-compiler-3.1.1 , Xml-api-ext,  Xml-apis.

CODE :: 

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String parameter = request.getParameter("BOOKING_ID");
              JasperPrint jasPrint = null;
        try {
            jasPrint = generateJasperReprotPrint();
        } catch (JRException | SQLException e) {
        }
        System.out.println("jasPrint  +jasPrint" + jasPrint);
        String file = "TEST.pdf";
        ServletOutputStream sos = response.getOutputStream();
        response.setContentType("application/pdf");
        try {
            JasperExportManager.exportReportToPdfStream(jasPrint, sos);  -- I am getting exception here in dev server but in local server it is working fine .
        } catch (JRException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
            
        }

}
      

    public JasperPrint generateJasperReprotPrint() throws SQLException, JRException, FileNotFoundException,
                                                          MalformedURLException {
       
        System.out.println(" getServletContext() " + getServletContext());
        InputStream is = getServletContext().getResourceAsStream("/jasperreports/zzzzz.jrxml");
        InputStream is1 = getServletContext().getResourceAsStream("/jasperreports/yyyy.jrxml");
        JasperDesign jasperDesign1 = JRXmlLoader.load(is); 
        JasperDesign jasperDesign2 = JRXmlLoader.load(is1); 
        Connection con =
            DriverManager.getConnection("jdbc:oracle:thin:@xxxxxxxxx/xxxxxxxxxxx",
                                        "xxxx", "xxx");

        JasperReport report = JasperCompileManager.compileReport(jasperDesign1);
        JasperReport report2 = JasperCompileManager.compileReport(jasperDesign2);
        Map parameters = new HashMap();
        parameters.put("blNumberParam", "111");
        parameters.put("bookingIdParam", "2222-0009");
        parameters.put("BlHeaderTitleParam", "abc");
        parameters.put("subreportparamtest", report2);
        System.out.println("--+" + parameters + "---" + con);
        JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, con);
     

        return jasperPrint;
    }

Please help .

 

Thanks

Rohit 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

rohitit3031's picture
Joined: Oct 7 2018 - 11:22pm
Last seen: 3 weeks 1 day ago

1 Answer:

0

Try

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String parameter = request.getParameter("BOOKING_ID");
              JasperPrint jasPrint = null;
        try {
            jasPrint = generateJasperReprotPrint();
            System.out.println("jasPrint  +jasPrint" + jasPrint);
            String file = "TEST.pdf";
            ServletOutputStream sos = response.getOutputStream();
            response.setContentType("application/pdf");
            JasperExportManager.exportReportToPdfStream(jasPrint, sos);  -- I am getting exception here in dev server but in local server it is working fine .
        } catch (JRException e | SQLException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }

hozawa's picture
42118
Joined: Apr 24 2010 - 4:31pm
Last seen: 5 hours 47 min ago
Feedback
randomness