Instalando el birt viewer en el contexto de Seam

 Este post intenta explicar como hice para acceder al contexto de Seam desde el visor de reportes de BIRT, el servelet de Birt Viewer, ya que si usaba la librería de BIRT para hacer PDFs u otros archivos funcionaba OK, el problema comenzo cuando decidimos utilizar el visor.

Cualquier consulta no dude en comentar.
Espero que sea de ayuda.

1.    Añadir las siguientes dependencias al pom.xml


<!--        BEGIN BIRT -->
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>axis-ant</artifactId>
                  <version>2.5.0</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>axis</artifactId>
                  <version>2.5.0</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>chartengineapi</artifactId>
                  <version>2.5.1</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>com.ibm.icu_4.0.1.v20090822</artifactId>
                  <version>2.5.1</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>commons-cli-1.0</artifactId>
                  <version>2.5.1</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>commons-discovery-0.2</artifactId>
                  <version>2.5.0</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>coreapi</artifactId>
                  <version>2.5.1</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>crosstabcoreapi</artifactId>
                  <version>2.5.1</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>dataadapterapi</artifactId>
                  <version>2.5.1</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>dataaggregationapi</artifactId>
                  <version>2.5.1</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>dataextraction</artifactId>
                  <version>2.5.1</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>dteapi</artifactId>
                  <version>2.5.1</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>engineapi</artifactId>
                  <version>2.5.1</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>flute</artifactId>
                  <version>2.5.1</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>javax.wsdl_1.5.1.v200806030408</artifactId>
                  <version>2.5.0</version>
            </dependency>
<!--        <dependency>-->
<!--              <groupId>org.eclipse.birt</groupId>-->
<!--              <artifactId>jaxrpc</artifactId>-->
<!--              <version>2.5.0</version>-->
<!--        </dependency>-->
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>js</artifactId>
                  <version>2.5.1</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>modelapi</artifactId>
                  <version>2.5.1</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>modelodaapi</artifactId>
                  <version>2.5.1</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>odadesignapi</artifactId>
                  <version>2.5.1</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>org.apache.commons.codec_1.3.0.v20080530-1600</artifactId>
                  <version>2.5.1</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>org.eclipse.emf.common_2.5.0.v200906151043</artifactId>
                  <version>2.5.1</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>org.eclipse.emf.ecore_2.5.0.v200906151043</artifactId>
                  <version>2.5.1</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>org.eclipse.emf.ecore.xmi_2.4.1.v200902171115</artifactId>
                  <version>2.5.0</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>org.w3c.css.sac_1.3.0.v200805290154</artifactId>
                  <version>2.5.1</version>
            </dependency>
<!--        <dependency>-->
<!--              <groupId>org.eclipse.birt</groupId>-->
<!--              <artifactId>saaj</artifactId>-->
<!--              <version>2.5.0</version>-->
<!--        </dependency>-->
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>scriptapi</artifactId>
                  <version>2.5.1</version>
            </dependency>
            <dependency>
                  <groupId>org.eclipse.birt</groupId>
                  <artifactId>viewservlets</artifactId>
                  <version>2.5.0</version>
            </dependency>
<!--        END BIRT -->


El servlet del viewer se encuentra en viewerservlets.jar pero se necesitan el resto de las dependencias para el motor de ejecución de reportes.

2.    Agregar las siguientes entradas al web.xml (Configuración del birt viewer)


<description>Deployment Descriptor for BIRT Viewer. Please check and specify the following settings.</description>

      <context-param>
            <description>Report resources(design files or document files) directory for preview. Defaults to ${Context Root}</description>
            <param-name>BIRT_VIEWER_WORKING_FOLDER</param-name>
            <param-value></param-value>
      </context-param>

      <context-param>
            <param-name>BIRT_VIEWER_LOCALE</param-name>
            <param-value>es-UY</param-value>
      </context-param>

      <context-param>
            <param-name>BIRT_VIEWER_TIMEZONE</param-name>
            <param-value>"GMT-3"</param-value>
      </context-param>

      <context-param>
            <description>Memory size in MB for creating a cube.</description>
            <param-name>BIRT_VIEWER_CUBE_MEMORY_SIZE</param-name>
            <param-value></param-value>
      </context-param>
      <context-param>
            <description>Report engine log level. (ALL|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST|OFF)</description>
            <param-name>BIRT_VIEWER_LOG_LEVEL</param-name>
            <param-value>FINEST</param-value>
      </context-param>
      <context-param>
            <description>Directory where to store all the birt report script libraries (JARs).. Defaults to ${Context Root}/scriptlib</description>
            <param-name>BIRT_VIEWER_SCRIPTLIB_DIR</param-name>
            <param-value>scriptlib</param-value>
      </context-param>
      <context-param>
            <description>Flag whether to force browser-optimized HTML output. Defaults to true</description>
            <param-name>HTML_ENABLE_AGENTSTYLE_ENGINE</param-name>
            <param-value>true</param-value>
      </context-param>
      <context-param>
            <description>Report Engine logs directory. Default to ${Context Root}/logs</description>
            <param-name>BIRT_VIEWER_LOG_DIR</param-name>
            <param-value>logs</param-value>
      </context-param>
      <context-param>
            <description>Max cube fetch columns levels limit for report preview (Only used when previewing a report design file using the preview pattern). Defaults to return all levels</description>
            <param-name>BIRT_VIEWER_MAX_CUBE_COLUMNLEVELS</param-name>
            <param-value></param-value>
      </context-param>
      <context-param>
            <description>Resource location directory (library files, images files or others). Defaults to ${Context Root}</description>
            <param-name>BIRT_RESOURCE_PATH</param-name>
            <param-value></param-value>
      </context-param>
      <context-param>
            <description>Temporary images/charts directory. Defaults to ${Context Root}/report/images</description>
            <param-name>BIRT_VIEWER_IMAGE_DIR</param-name>
            <param-value>report/images</param-value>
      </context-param>
      <context-param>
            <description>BIRT viewer extended configuration file</description>
            <param-name>BIRT_VIEWER_CONFIG_FILE</param-name>
            <param-value>WEB-INF/viewer.properties</param-value>
      </context-param>
      <context-param>
            <description>Preview report rows limit. An empty value means no limit.</description>
            <param-name>BIRT_VIEWER_MAX_ROWS</param-name>
            <param-value></param-value>
      </context-param>
      <context-param>
            <description>Temporary document files directory. Defaults to ${Context Root}/documents</description>
            <param-name>BIRT_VIEWER_DOCUMENT_FOLDER</param-name>
            <param-value>documents</param-value>
      </context-param>
      <context-param>
            <description>Flag whether to allow server-side printing. Possible values are ON and OFF. Defaults to ON</description>
            <param-name>BIRT_VIEWER_PRINT_SERVERSIDE</param-name>
            <param-value>ON</param-value>
      </context-param>

      <context-param>
            <description>Flag whether the report resources can only be accessed under the working folder. Defaults to false</description>
            <param-name>WORKING_FOLDER_ACCESS_ONLY</param-name>
            <param-value>false</param-value>
      </context-param>
      <context-param>
            <description>Max cube fetch rows levels limit for report preview (Only used when previewing a report design file using the preview pattern). Defaults to return all levels</description>
            <param-name>BIRT_VIEWER_MAX_CUBE_ROWLEVELS</param-name>
            <param-value></param-value>
      </context-param>

3.    Agregar las siguientes entradas al web.xml (Mapeos a servlets)


<servlet>
            <servlet-name>ViewerServlet</servlet-name>
            <servlet-class>org.eclipse.birt.report.servlet.ViewerServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
            <servlet-name>EngineServlet</servlet-name>
            <url-pattern>/output</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
            <servlet-name>EngineServlet</servlet-name>
            <url-pattern>/download</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
            <servlet-name>EngineServlet</servlet-name>
            <url-pattern>/preview</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
            <servlet-name>EngineServlet</servlet-name>
            <url-pattern>/document</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
            <servlet-name>ViewerServlet</servlet-name>
            <url-pattern>/frameset</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
            <servlet-name>EngineServlet</servlet-name>
            <url-pattern>/parameter</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
            <servlet-name>EngineServlet</servlet-name>
            <url-pattern>/extract</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
            <servlet-name>ViewerServlet</servlet-name>
            <url-pattern>/run</url-pattern>
      </servlet-mapping>
      <filter>
            <filter-name>ViewerFilter</filter-name>
            <filter-class>org.eclipse.birt.report.filter.ViewerFilter</filter-class>
      </filter>
      <filter-mapping>
            <filter-name>ViewerFilter</filter-name>
            <servlet-name>EngineServlet</servlet-name>
      </filter-mapping>
      <filter-mapping>
            <filter-name>ViewerFilter</filter-name>
            <servlet-name>ViewerServlet</servlet-name>
      </filter-mapping>


4.    Verificar que los filtros de seam estén al final del archivo web.xml



<filter>
            <filter-name>Seam Filter</filter-name>
            <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
      </filter>
      <filter-mapping>
            <filter-name>Seam Filter</filter-name>
            <url-pattern>*.seam</url-pattern>
      </filter-mapping>

Fin de web.xml

5.    Crear el archivo viewer.properties, el cual contiene configuraciones avanzadas. La ruta de este archivo se setea en el web.xml, bajo el parametro :

<param-name>BIRT_VIEWER_CONFIG_FILE</param-name>


###############################################################################
# Copyright (c) 2004 Actuate Corporation.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
#  Actuate Corporation  - initial API and implementation
###############################################################################

# configurable variable for JSP base href. Please uncomment the below line.
#base_url=http://127.0.0.1:8080

# [EXTENSION SETTING]
viewer.extension.html=html
viewer.extension.pdf=pdf
viewer.extension.postscript=ps
viewer.extension.doc=doc
viewer.extension.xls=xls
viewer.extension.ppt=ppt

# [OUTPUT FORMAT LABEL NAME]
viewer.label.html=HTML
viewer.label.pdf=PDF
viewer.label.postscript=PostScript
viewer.label.doc=Word
viewer.label.xls=Excel
viewer.label.ppt=PowerPoint

# [CSV SEPARATOR]
viewer.sep.0=,
viewer.sep.1=;
viewer.sep.2=:
viewer.sep.3=|
viewer.sep.4=\t

# [VIEWING SESSION CONFIGURATION]
# The BIRT viewing session is a sub-session of the HTTP session.
# An HTTP session can have multiple BIRT viewing sessions.
# Each time a new viewer is opened, a new viewing session is created.
# The following parameters are used to configure the viewing session
# management.
# If the matching HTTP session expires, all the viewing sessions
# attached to it will expire as well.

# Timeout value in seconds after which a viewing session will expire.
# The value 0 means that a session will never expire, and the cached files
# will never be cleant unless the belonging HTTP session expires.
viewer.session.timeout=0

# Defines a session count threshold after which the cleanup process
# will try to clean up expired sessions.
viewer.session.minimumThreshold=20

# Load factor to recalculate the minimum threshold value based on the remaining
# session count after cleanup.
viewer.session.loadFactor=0.75

# Maximum number of simultaneous viewing sessions that can be open at the
# same time, to prevent cache overflowing through multiple requests.
# A value of 0 means no limit.
viewer.session.maximumSessionCount=0

# Behavior that must be used once the maximum session count is reached
# (if different than 0):
# - A value of 0 will use the "Discard new session" policy that will show
# an error message for all the newer sessions.
# - A value of 1 will use the "Discard the oldest session" policy that will
# try to discard the oldest session, even if it has not expired yet.
# Note that "busy" sessions (for example downloading results) won't be
# cleant by this mechanism.
viewer.session.maximumSessionCountPolicy=1

# [LOGGERS]
# "logger."+class=level
# if no level is specified or the text "DEFAULT",
# then the default level from the web.xml will be used
logger.org.eclipse.datatools.connectivity.oda=DEFAULT
logger.org.eclipse.datatools.enablement.oda=DEFAULT



6.    Estructura de directorios dentro del proyecto


clip_image002


Dentro del proyecto web, se deben copiar las carpetas del Birt Viewer. Estas se pueden conseguir del Birt WebViewerExample, que viene con el runtime de birt.
Todos los archivos que se encuentren en WEB-INF, deben copiarse al WEB-INF de la app que contendrá al birt viewer, estas se consiguen del runtime.
clip_image004

Copiar todo menos el web.xml, las entradas del web.xml de nuestra aplicación las editamos según indique este manual.
Directorios en proyecto actual:

clip_image006


7.    Utilización de tags jsf de birt


Para poder hacer uso de los tags de birt, es necesario agregar seam-birt.taglib.xml a META-INF

<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC
   "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
   "facelet-taglib_1_0.dtd">
  
<facelet-taglib>
    <namespace>http://jboss.com/products/seam/birt</namespace>

    <tag>
        <tag-name>birt</tag-name>
        <component>
            <component-type>org.jboss.seam.birt.ui.UIDocument</component-type>
        </component>
    </tag>
   
    <tag>
        <tag-name>param</tag-name>
        <component>
            <component-type>org.jboss.seam.birt.ui.UIParameter</component-type>
        </component>
    </tag>

</facelet-taglib>

Se agrega en faces-config:


<component>
        <component-type>org.jboss.seam.birt.ui.UIDocument</component-type>
        <component-class>org.jboss.seam.birt.ui.UIDocument</component-class>
    </component>
    <component>
        <component-type>org.jboss.seam.birt.ui.UIParameter</component-type>
        <component-class>org.jboss.seam.birt.ui.UIParameter</component-class>
    </component>

Se agregan a la carpeta WEB-INF/lib:

jboss-seam-birt.jar

Para acceder al contexto:


En components.xml

<web:context-filter url-pattern="/frameset"/>

En web.xml

    <filter-mapping>
        <filter-name>Seam Filter</filter-name>
        <url-pattern>/frameset</url-pattern>
    </filter-mapping>

--


Packages.org.jboss.seam.Component.getInstance("_user",false);

Comments

Popular Posts