jersey-mvc-jasper

Jersey Teplate to integrate Jasper in Jersey Template system, generating PDF files

License

License

Categories

Categories

Jersey Program Interface REST Frameworks
GroupId

GroupId

br.uff.sti
ArtifactId

ArtifactId

jersey-mvc-jasper
Last Version

Last Version

0.2
Release Date

Release Date

Type

Type

jar
Description

Description

jersey-mvc-jasper
Jersey Teplate to integrate Jasper in Jersey Template system, generating PDF files
Project URL

Project URL

https://github.com/marcosvpcortes/jersey-mvc-jasper
Source Code Management

Source Code Management

https://github.com/marcosvpcortes/jersey-mvc-jasper

Download jersey-mvc-jasper

How to add to project

<!-- https://jarcasting.com/artifacts/br.uff.sti/jersey-mvc-jasper/ -->
<dependency>
    <groupId>br.uff.sti</groupId>
    <artifactId>jersey-mvc-jasper</artifactId>
    <version>0.2</version>
</dependency>
// https://jarcasting.com/artifacts/br.uff.sti/jersey-mvc-jasper/
implementation 'br.uff.sti:jersey-mvc-jasper:0.2'
// https://jarcasting.com/artifacts/br.uff.sti/jersey-mvc-jasper/
implementation ("br.uff.sti:jersey-mvc-jasper:0.2")
'br.uff.sti:jersey-mvc-jasper:jar:0.2'
<dependency org="br.uff.sti" name="jersey-mvc-jasper" rev="0.2">
  <artifact name="jersey-mvc-jasper" type="jar" />
</dependency>
@Grapes(
@Grab(group='br.uff.sti', module='jersey-mvc-jasper', version='0.2')
)
libraryDependencies += "br.uff.sti" % "jersey-mvc-jasper" % "0.2"
[br.uff.sti/jersey-mvc-jasper "0.2"]

Dependencies

compile (3)

Group / Artifact Type Version
com.google.collections : google-collections jar 1.0
org.glassfish.jersey.ext : jersey-mvc jar 2.13
net.sf.jasperreports : jasperreports jar 5.6.1

test (3)

Group / Artifact Type Version
org.testng : testng jar 6.8.8
br.com.six2six : fixture-factory jar 2.2.0
org.mockito : mockito-core jar 1.10.8

Project Modules

There are no modules declared in this project.

jersey-mvc-jasper

Build Status

Jersey plugin to integrate Jasper Report at Jersey Template system, generating PDF files.

Installing

Install it has two steps:

  • Include the depedency in pom.xml;
  • Register the MvcFeature of the jersey-mvc-jasper;

Include the dependency

    <dependency>
        <groupId>br.uff.sti</groupId>
        <artifactId>jersey-mvc-jasper</artifactId>
        <version>0.1.10</version>
        <exclusions>
            <exclusion>
                <artifactId>jasperreports</artifactId>
                <groupId>net.sf.jasperreports</groupId>
            </exclusion>
        </exclusions>
    </dependency>

Details:

  • You should exclude the Jasper Report dependency od this plugin to avoid conflict with the module insered by yout application or by others dependencies. It is important because Jasper is very sensible to differences between the .jasper compiled version and the jasper module version.

  • Currently, this plugin is not in a maven repository (I am learning do it, sorry...). You should download this plugin and clean/install with maven

    ``mvn clean install``
    

Register the MvcFeature

Register the MvcFeature provide by this module. More details here.

...
register(org.glassfish.jersey.jackson.JacksonFeature.class);
register(MultiPartFeature.class);
register(JasperMvcFeature.class);
...

Usage

Jersey by itself has a lot of ways to define a web-service method (returning a entity, a Response, etc). You using the same syntax to render with jersey-mvc-jasper, but using the annotation @Template with your template name and defining the @Produces type:

@GET
@Path("{id}.pdf")
@Template(name="/jasper/my_template")
@Produces("application/pdf")
public Person getPerson(@PathParam("id") id){
  Person person = this.getPerson(id);//using spring/CDI/etc...
  return person;
}

The jersey-mv-jasper will search in "WEB-INF/jasper/" for a file like my_template.jasper. If it not found, will search by my_template.jrxml" and compile it.

You can return a List to represent multiples entities to be rendered by jasper using $F{...} (field).

@GET
@Path(".pdf")
@Template(name="/jasper/my_template")
@Produces("application/pdf")
public List<Person> getPersons(){
  List<Person> persons = this.getPersons();//using spring/CDI/etc...
  return persons;
}

Return too a instance of JasperModel that can receive the list of entities and a collections of key->value to be used with $P{...} (parameters) in jasper.

@GET
@Path(".pdf")
@Template(name="/jasper/my_template")
@Produces("application/pdf")
public JasperModel getPersons(){
  List<Person> persons = this.getPersons();//using spring/CDI/etc...
  return JasperModel.create(Person.class).putParam("LOGO", "/logo.png").addModels(persons);
}

See more

Versions

Version
0.2