users@jersey.java.net

Re: [Jersey] Jaser Reports / PDF

From: aloleary <alanoleary_at_gmail.com>
Date: Tue, 15 Sep 2009 07:11:12 -0500 (CDT)

Hello,
   Just getting back into this again and I am going to write my own Provider
for JasperReports...

JasperReports is basically a reporting 'template' engine which takes report
templates, injects the params and then can produce reports. The key point is
that these reports can be multiple formats : pdf, csv, xml, xls etc..

All this makes Jasper a good candidate for a Jersey Provider and MVCJ

I would like to use com.sun.jersey.spi.template.TemplateProcessor as its
idea of templates matches Jaspers report templates but this hides the
content type from me whereas using MessageBodyWriter<MyModel> directly
allows me to get the MediaType.

However I am not sure if its possible to say 'switch' on the request content
type and produce the correct report at the provider level... application/pdf
causes jasper/provider to generate PDF etc..

For anyone else searching the forum the two approaches I'm looking at for
ideas are FreeMarker providers:

one using TemplateProcessor
(http://www.cwinters.com/blog/2009/04/03/jersey_freemarker_provider.html)

one using MessageBodyWriter (http://blogs.citytechinc.com/sjohnson/?p=32)

you can see the signature of writeTo in MessageBodyWriter has 'MediaType
mediaType'




Paul Sandoz wrote:
>
>
> On Jul 15, 2009, at 1:31 PM, António Mota wrote:
>
>> I don't think there is a best practice for that,
>
> I tried to allude to what such a best practice might be by utilizing a
> TemplateProcessor, but without understanding a little more about how
> Jasper Reports works i cannot really say if this fits well.
>
> Paul.
>
>
>> you have to write the code to produce the report as usual using the
>> ouptut format you want, and wrap that in a Jersey annotated method.
>> At least that how we did it, but please note that we aren't using
>> the full Jersey stack, so maybe there are cleaner ways?
>>
>> @GET
>> @Path("/reports/{name}")
>> @Produces("application/pdf")
>> byte[] executePdf(@PathParam("name")String name,
>> @MatrixParam("queryparams")Map<String, String> params,
>> @QueryParam("locale")Locale locale);
>>
>>
>>
>>
>> Paul Sandoz wrote:
>>> Hi,
>>>
>>> I am not familiar with the Jasper Report...
>>>
>>> Is there an API to generate reports ? If so you might be able to
>>> use that directly in a resource method.
>>>
>>> If you can do that what you might find is that you start
>>> reproducing code in the resource method that might be more
>>> appropriate else where, hence the separation of model and view.
>>>
>>> You might be able to easily integrate such functionality as a
>>> TemplateProcessor e.g. See Bill's integration of StringTemplate
>>>
>>> http://github.com/dehora/jersey-stringtemplate
>>> <http://github.com/dehora/jersey-stringtemplate/
>>> >
>>>
>>>
>>> Thus you could potentially do:
>>>
>>> @Produces("application/pdf")
>>> public Viewable getReport() {
>>> Model model = ...
>>> return new Viewable(
>>> "myreport.jr", // reference to a Jasper Report template
>>> model);
>>> }
>>>
>>> Paul.
>>>
>>> On Jul 14, 2009, at 10:05 AM, aloleary wrote:
>>>
>>>>
>>>> Hello,
>>>> Has/Is anyone @Produce-ing JasperReports from Jersey/JAX-RS ?
>>>> What is
>>>> the best practice or suggested approach. All the Jasper examples I
>>>> see
>>>> typically involve a web view layer - something I'm trying to avoid
>>>>
>>>> Any pointers appreciated
>>>>
>>>> -A-
>>>> --
>>>> View this message in context:
>>>> http://n2.nabble.com/Jaser-Reports---PDF-tp3254543p3254543.html
>>>> Sent from the Jersey mailing list archive at Nabble.com.
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>> <mailto:users-unsubscribe_at_jersey.dev.java.net
>>>> >
>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>> <mailto:users-help_at_jersey.dev.java.net
>>>> >
>>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
>

-- 
View this message in context: http://n2.nabble.com/Jaser-Reports-PDF-tp3254543p3648606.html
Sent from the Jersey mailing list archive at Nabble.com.