Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to create a Web Service that returns a PDF file with Jasper Report

Habib EslamiFeb 18 2014 — edited Feb 18 2014

Hi

I use jdeveloper 11.1.1.3.0

My requirement is to create a Web Service that returns a PDF file or a image.

I first created a report in Jasper Report and then I call this report as a PDF file through a method in a bean and the PDF file display successfully in ADF application

    public void runReport(String repPath, java.util.Map param) throws Exception {

        Connection conn = null;

        try {

            HttpServletResponse response = getResponse();

            ServletOutputStream out = response.getOutputStream();

            response.setHeader("Cache-Control", "max-age=0");

            response.setContentType("application/pdf");

            ServletContext context = getContext();

            InputStream fs = context.getResourceAsStream("/reports/" + repPath);

            JasperReport template = (JasperReport)JRLoader.loadObject(fs);

            template.setWhenNoDataType(WhenNoDataTypeEnum.NO_DATA_SECTION);

            conn = getConnection();

            JasperPrint print = JasperFillManager.fillReport(template, param, conn);

            ByteArrayOutputStream baos = new ByteArrayOutputStream();

            JasperExportManager.exportReportToPdfStream(print, baos);

            out.write(baos.toByteArray());

            out.flush();

            out.close();

            FacesContext.getCurrentInstance().responseComplete();

        } catch (Exception jex) {          

            jex.printStackTrace();

        }

    }

but I can't create a web service from this method

what is the solution for this problem?

Habib

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 18 2014
Added on Feb 18 2014
1 comment
567 views