Patrick Hütter

How to get grails rendering and grails-melody (java melody) working together

I’m using grails rendering 0.4.4 plugin to render some HTML(GSP) to PDF wich uses the underlying iText library in version 2.1.0.

I also wanted to monitor my webapplication with java melody, so i decided to install grails-melody. This plugin comes with pdf-export for the java melody reports and uses also the iText library, but in the newer version 2.1.7.

Normally this shouldn’t be a problem, because you can exclude the older or newer library in the dependencies of your grails application, but in this case there is a binary incompatibility between the different Flying Saucer binaries. So you get the following exception:

java.lang.NoSuchMethodError – com.lowagie.text.pdf.BaseFont.getCharBBox(C)….

Line | Method
->> 195 | doFilter in PageFragmentCachingFilter.java
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    63 | doFilter in AbstractFilter.java
|   151 | invoke . in net.bull.javamelody.JspWrapper
|   271 | invoke   in net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler
|   206 | doFilter in net.bull.javamelody.MonitoringFilter
|   179 | doFilter in     ''
|   895 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run      in     ''
^   680 | run . .  in java.lang.Thread

Caused by ControllerExecutionException: Runtime error executing action
->> 195 | doFilter in PageFragmentCachingFilter.java
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    63 | doFilter in AbstractFilter.java
|   151 | invoke . in net.bull.javamelody.JspWrapper
|   271 | invoke   in net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler
|   206 | doFilter in net.bull.javamelody.MonitoringFilter
|   179 | doFilter in     ''
|   895 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run      in     ''
^   680 | run . .  in java.lang.Thread

Caused by InvocationTargetException: null
->> 195 | doFilter in PageFragmentCachingFilter.java
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    63 | doFilter in AbstractFilter.java
|   151 | invoke . in net.bull.javamelody.JspWrapper
|   271 | invoke   in net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler
|   206 | doFilter in net.bull.javamelody.MonitoringFilter
|   179 | doFilter in     ''
|   895 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run      in     ''
^   680 | run . .  in java.lang.Thread

Caused by NoSuchMethodError: com.lowagie.text.pdf.BaseFont.getCharBBox(C)[I
->> 679 | setMetricDefaults in org.xhtmlrenderer.pdf.ITextFontResolver$FontDescription
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|   610 |    in     ''
|   410 | addCourier in org.xhtmlrenderer.pdf.ITextFontResolver
|   390 | createInitialFontMap in     ''
|    52 |  . in     ''
|   115 |    in org.xhtmlrenderer.pdf.ITextRenderer
|   102 |  . in     ''
|    34 | doRender in PdfRenderingService.groovy
|    43 | render . in RenderingService.groovy
|    37 | render   in     ''
|    35 | render . in     ''
|    65 | render   in     ''
|   165 | doCall . in GrailsMelodyGrailsPlugin$_closure4_closure15_closure16
|    59 | doCall   in RenderingGrailsPlugin$_closure3
|   366 | getTickets in ShopController.groovy
|   195 | doFilter in PageFragmentCachingFilter.java
|    63 | doFilter in AbstractFilter.java
|   151 | invoke   in net.bull.javamelody.JspWrapper
|   271 | invoke . in net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler
|   206 | doFilter in net.bull.javamelody.MonitoringFilter
|   179 | doFilter in     ''
|   895 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . .  in     ''
^   680 | run      in java.lang.Thread

To fix this you have to recompile Flying Saucer R8 against iText 2.1.x and it will work fine. But you don’t have to do it yet, because you can use the library from here. Just place it in your „lib“ folder as „core-renderer-R8.jar“ in your grails project and edit your dependencies.

BuildConfig.groovy:

dependencies {
 // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
 runtime ( 'org.xhtmlrenderer:core-renderer:R8', 'com.lowagie:itext:2.1.7')
 }

plugins {
runtime(':rendering:0.4.4') { exclude 'itext' }
compile ":grails-melody:1.45"
}

Now everything works as expected with the newest iText version (old license tree). I’m able to use the rendering plugin to generate pdf exports and java melody to get application reports.

Die mobile Version verlassen