Hi,

 

I'd like to integrate jasper reports. All going well, except for how
Jasper locates images in a web environment, using an ImageServlet. The
demo app from jasper requires that I set a map into the http session
which contains a cache of the images as they are called. 

 

Here is a snippet of my code:

 

@Resource

    private HttpServletRequest httpRequest; 

                

                public Response getCustomerList(ReportQuery reportQuery)
{

                                

                                log.debug("Start - getCustomerList");

                                log.debug("Customer Id:
"+reportQuery.getCustomerId());

                                log.debug("Start from controller id:
"+reportQuery.getStartFromControllerId());

                                

                                // TODO: this is an example report only
used to test the framework.

                                ByteArrayOutputStream baos = new
ByteArrayOutputStream();

                                

                                try {

                                                InputStream is =
ResourceUtils.getClasspathResourceStream("/WEB-INF/jasperreports/WebappR
eport.jasper", this.getClass(), BusFactory.getDefaultBus());

                                                JasperReport
jasperReport = (JasperReport)JRLoader.loadObject(is);

                                                

                                                Map parameters = new
HashMap();

 
parameters.put("ReportTitle", "Address Report");

 


                                                JasperPrint jasperPrint
= 

 
JasperFillManager.fillReport(

 
jasperReport, 

 
parameters, 

 
new DataSourceStub()

 
);

                                                

                                                JRHtmlExporter exporter
= new JRHtmlExporter();

 
httpRequest.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_
SESSION_ATTRIBUTE, jasperPrint);

 
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

 
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);

 
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,
"image?image=");

                                                exporter.exportReport();

                                                

                                } catch (JRException e) {

                                                e.printStackTrace();

                                }

                                

                                

                                return Response.ok(baos.toString(),
"text/html").build();

                }

 

Note the @Resource  private HttpServletRequest httpRequest field. Is
this the best way to do this? Is the field thread safe? As I potentially
have a lot of users requesting this service... 

 

Cheers,

Matt.

Reply via email to