How to use an external JavaScript file in a BIRT report

In a recent assignment I had to write some custom Java Script code to treat some table cells from an Eclipse BIRT report.

This ticket explains the setting of an external Java Script file in a BIRT report.

Define the resources folder for your BIRT project.

First step is to define the resources folder for your BIRT project. Go to the project properties -> Report Design ->Resource (as shown in the following screenshot). In our case the BIRT project is a (Java) Maven project so all the external resources are in the folder src/ressources.

BIRTProjectResourceSetting

Add the external Java Script file(s) to the BIRT report

In the property editor of the BIRT report, define the external resource files (in the following screenshot the “CustomFunctions.js” was added an external JavaScript file).

BIRTReportPropertyEditor

After adding the JS file, the rptdesign file the will look something like :

<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.23" id="1">
 <property name="createdBy">Eclipse BIRT Designer Version 4.3.1.v201309091055 Build <4.3.1.v20130917-1035></property>
    <list-property name="includeScripts">
       <property>CustomFunctions.js</property>
     </list-property>
....

Use the custom JavaScript functions in the report

In the BIRT expression builder, use the custom JavaScript function (as in the following screenshot):

BIRTExpressionBuilder

Update the BIRT web viewer

When the war file will be created, the src/ressources content will be copied under the folder WEB-INF/classes so, the BIRT web viewer servlet should be instructed where to find the resources folder under using a context parameter:

 <!-- Resource location directory. Defaults to ${birt home} -->
 <context-param>
 <param-name>BIRT_RESOURCE_PATH</param-name>
 <param-value>WEB-INF/classes</param-value>
 </context-param>

Generating Excel files with Apache POI – Removed Feature: Format from /xl/styles.xml part (Styles)

The problem

Some (big) Excel files generated using Apache POI cannot be correctly open by Excel (none of the styles applied to the cells are rendered). The error message shown by Excel is the following one :

Removed Feature: Format from /xl/styles.xml part (Styles)
Repaired Records: Cell information from /xl/worksheets/sheet1.xml part
Cell information from /xl/worksheets/sheet2.xml part
Repaired Records: Cell information from /xl/worksheets/sheet3.xml part

The cause

The root cause is that Excel can handle only a limited number of cell styles by workbook; Excel 2010 for example can handle 4000 cell style by workbook (see Excel specifications and limits).

The solution

The solution is quite simple (in theory). You have to limit the number of unique instances of org.apache.poi.ss.usermodel.CellStyle used in your workbook. For this you can use the POI utility class org.apache.poi.ss.util.CellUtil.

GenericSignatureFormatError while deploying SOAP web services

This ticket will present some problem that I encountered using  JAXB.

Environment

  • OS: Windows 7
  • Servlet container : Tomcat 7.X
  • JRE: Sun Java 1.6.0_11
  • JAXB version: 2.2.1

Stack trace

Trying to deploy a web application containing (SOAP) web services  failed with the following stack trace:

WSSERVLET11: failed to parse runtime descriptor: 
java.lang.reflect.GenericSignatureFormatError
at sun.reflect.generics.parser.SignatureParser.error(SignatureParser.java:103)
at sun.reflect.generics.parser.SignatureParser.parseSimpleClassTypeSignature(SignatureParser.java:262)
at sun.reflect.generics.parser.SignatureParser.parseClassTypeSignatureSuffix(SignatureParser.java:270)
at sun.reflect.generics.parser.SignatureParser.parseClassTypeSignature(SignatureParser.java:244)
...
 at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parse(DeploymentDescriptorParser.java:147)
 at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized(WSServletContextListener.java:124)
...

Cause of the exception

One of the web services had as return value a list of enums. The enum was defined something like :

public enum Season { WINTER, SPRING, SUMMER, FALL }

(no default constructor).

In order to fix the problem it must add a no parameter contructor; something like:

public enum Season { 
WINTER, SPRING, SUMMER, FALL 
 Season() {}
}

How to deploy from Ant to Tomcat through SSL

Problem: Deploy a war using the Ant to Tomcat. The Ant task should be something like this (where ${tomcat-manager-url} is something like httpS://targetServer:port/manager/text):

<target name="deploy" description="Deploy application to tomcat">
<echo>deploying from local source</echo>
<deploy url="${tomcat-manager-url}" username="${tomcat-manager-username}" password="${tomcat-manager-password}" path="/${deployed-application-name}" war="file:///${project-workspace}/${war.name}" />
</target>

Solution: The basic idea is to add the server certificate to the keystore from witch the deployment will be done and use this this certificate to talk with the server through SSL.

Step 1: Get and save the server certificate to the disk.

Step 2: Add the server certificate to the keystone truststore of the system from which Ant will deploy the application.
C:\>keytool -importcert -keystore keystoreFile -trustcacerts -alias targetServer
-file full path to the certificate file

Step 3: Execute the ant script script with the following system properties:
-Djavax.net.ssl.keyStoreType=jks
-Djavax.net.ssl.keyStore=Full path to the keystore file
-Djavax.net.ssl.keyStorePassword=keystore password
-Djavax.net.ssl.trustStore=Full path to the keystore file
-Djavax.net.ssl.trustStorePassword=keystore password

Problems: Some errors that can appear and how to solve them.

Problem: PKIX path building failed. The full error message is:

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException:
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target

Solution: The executed Ant script cannot find the keystore passed as parameter in the Step 3

Problem: No name matching “serverName” found. The full error message is:
javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No name matching serverName found

Solution: The server name on which the deployment is made should be the same as the FQDN(Fully Qualified Domain Name) of the certificate. The FQDN of the certificate is something like serverName.foo.org; the server name on which the deployment is made by Ant should be exactly the same.