1. Configuration for Seam

Library dependencies

In order to initialize GDS/Tide for Seam 2.1 and Hibernate, you must add granite.jar, granite-hibernate.jar and granite-seam21.jar to your WEB-INF/lib or in the lib directory of an ear.

In the case of ear packaging, jboss-seam.jar should be added at the root of the ear and referenced in application.xml:

application.xml
<module><ejb>jboss-seam.jar</ejb></module>

With ear again, it is necessary to put all libs in ear/lib and to make sure that no jar concerning JPA persistence is left in WEB-INF/lib.

Simplified configuration (components.xml)

The easiest way to add GraniteDS support to a Seam project is by enabling the Flex filter it in components.xml :

components.xml
<components xmlns="http://jboss.com/products/seam/components"
            xmlns:core="http://jboss.com/products/seam/core"
            xmlns:security="http://jboss.com/products/seam/security"
            xmlns:transaction="http://jboss.com/products/seam/transaction"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:graniteds="http://www.graniteds.org/config"
            xsi:schemaLocation=
                "http://jboss.com/products/seam/core 
                     http://jboss.com/products/seam/core-2.1.xsd
                 http://jboss.com/products/seam/transaction 
                     http://jboss.com/products/seam/transaction-2.1.xsd
                 http://jboss.com/products/seam/security 
                     http://jboss.com/products/seam/security-2.1.xsd
                 http://jboss.com/products/seam/components 
                     http://jboss.com/products/seam/components-2.1.xsd
                 http://www.graniteds.org/config 
                     http://www.graniteds.org/public/dtd/2.1.0/granite-config-2.1.xsd">

    <core:init .../>
    
    ...
    
    <graniteds:flex-filter url-pattern="/graniteamf/*" tide="true">
    	<graniteds:tide-annotations>
    		<value>javax.ejb.Stateless</value>
    		<value>javax.ejb.Stateful</value>
    	</graniteds:tide-annotations>
    </graniteds:flex-filter>

</components>

The flex-filter declaration will setup an AMF processor for the specified url mapping, and the tide attribute indicates that you want to configure a Tide-enabled service factory.

Other configurations can be done though flex-filter :

  • tide-annotations is equivalent to tide-component annotated-with="" in granite-config.xml. It allows to define the list of annotation names that enable remote access to Seam components.
  • tide-roles allows to define a list of security roles that are required to access the Tide remote destination. In general it is not necessary to define this destination-wide security and only rely on Seam security for fine-grained access to individual Seam components.
  • exception-converters allows to define a list of server-side exception converters. It's the equivalent to exception-converters in granite-config.xml.
  • amf3-message-interceptor allows to define a message interceptor. You have to define an EL expression referencing an existing component implementing AMFMessageInterceptor. It's highly recommended to subclass Seam21Interceptor and call super.before and super.after in your implementation.

As there is no services-config.xml in this kind of setup, you will have to define manually the endpoint for remote services. This can be done by defining a service initializer in a static block of the main mxml file :

Seam.getInstance().addComponentWithFactory("serviceInitializer", 
    DefaultServiceInitializer, 
    { contextRoot: "/seam-flexbooking" }
);

Note that if you have choosen this kind of simplified configuration, you generally don't need to read the following sections. However if you have more specific requirements, you can still define granite-config.xml and/or services-config.xml files that will override or complete the configuration.

General Web Configuration (web.xml)

Then you have to add the following configuration to your web.xml:

web.xml
<web-app version="2.4" ...>
    ...
    <!-- Seam -->
    
    <listener>
        <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
    </listener>
    
    <!-- GDS AMF message filter -->
    <filter>
        <filter-name>AMFMessageFilter</filter-name> 
        <filter-class>org.granite.messaging.webapp.AMFMessageFilter</filter-class> 
        
        <!--
        Uncomment (part of) this block if configs are not present at default locations.
        <init-param>
            <param-name>servicesConfigPath</param-name>
            <param-value>/WEB-INF/flex/services-config.xml</param-value>
        </init-param>
        <init-param>
            <param-name>graniteConfigPath</param-name>
            <param-value>/WEB-INF/granite/granite-config.xml</param-value>
        </init-param-->

    </filter>
    
    <filter-mapping>
        <filter-name>AMFMessageFilter</filter-name> 
        <url-pattern>/graniteamf/*</url-pattern> 
    </filter-mapping>
    
    <!-- GDS AMF Servlet -->
    <servlet>
        <servlet-name>AMFMessageServlet</servlet-name>
        <servlet-class>org.granite.messaging.webapp.AMFMessageServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>AMFMessageServlet</servlet-name>
        <url-pattern>/graniteamf/*</url-pattern>
    </servlet-mapping>
    ...
</web-app>
You must not use the standard SeamFilter together with the Tide/Seam interceptor. If you need a dual Flex/HTML front-end, you have to configure the standard SeamFilter only for the HTML URLs.

Flex/GDS Configuration

To use Tide/Seam services in your Flex application, you have to configure a specific destination and service factory in services-config.xml:

services-config.xml
<services-config>

    <services>
        <service id="granite-service"
            class="flex.messaging.services.RemotingService"
            messageTypes="flex.messaging.messages.RemotingMessage">
            <!--
             ! Use "tideSeamFactory" and "graniteamf" for "seam" destination (see below).
             ! The destination must be "seam" when using Tide with default configuration.
             !-->
            <destination id="seam">
                <channels>
                    <channel ref="graniteamf"/>
                </channels>
                <properties>
                    <factory>tideSeamFactory</factory>
                </properties>
            </destination>
        </service>
    </services>

    <!--
     ! Declare tideSeamFactory service factory.
     !-->
    <factories>
        <factory id="tideSeamFactory" class="org.granite.tide.seam.SeamServiceFactory" />
    </factories>

    <!--
     ! Declare graniteamf channel.
     !-->
    <channels>
        <channel-definition id="graniteamf" class="mx.messaging.channels.AMFChannel">
            <endpoint
                uri="http://{server.name}:{server.port}/{context.root}/graniteamf/amf"
                class="flex.messaging.endpoints.AMFEndpoint"/>
        </channel-definition>
    </channels>

</services-config>

Note that this is the one and only destination configuration needed for all remote component calls.

There is then a little more configuration in granite-config.xml for Tide and security integration:

granite-config.xml without automatic scanning
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE granite-config PUBLIC
    "-//Granite Data Services//DTD granite-config internal//EN"
    "http://www.graniteds.org/public/dtd/2.0.0/granite-config.dtd">

<granite-config>

    <amf3-message-interceptor type="org.granite.seam21.Seam21Interceptor"/>

    <converters>
        <converter type="org.granite.seam21.ValueExpressionConverter"/>
        <converter type="org.granite.seam21.ConversationEntryConverter"/>
    </converters>
    
    <externalizers>
        <externalizer type="org.granite.hibernate.HibernateExternalizer">
            <include annotated-with="javax.persistence.Entity"/>
            <include annotated-with="javax.persistence.MappedSuperclass"/>
            <include annotated-with="javax.persistence.Embeddable"/>
        </externalizer>
        ...
    </externalizers>
    
    ...

    <security type="org.granite.seam21.security.Seam21SecurityService"/>

    <tide-components>
        <!-- List of component matchers, see 'Enabling components' section -->
    </tide-components>
    
</granite-config>

Note that this part is much simpler if you use the automatic scanning of GraniteDS 1.1+:

granite-config.xml with automatic scanning
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE granite-config PUBLIC
    "-//Granite Data Services//DTD granite-config internal//EN"
    "http://www.graniteds.org/public/dtd/2.0.0/granite-config.dtd">

<granite-config scan="true">

    <security type="org.granite.seam21.security.Seam21SecurityService"/>

    <tide-components>
        <!-- List of component matchers, see 'Enabling components' section -->
    </tide-components>

</granite-config>

 

Configuration for Seam 2.0

It is highly recommend to use Seam 2.1 with Flex because the removal of the dependency on JSF. If you absolutely need to use Seam 2.0, the configuration of GDS/Tide is a little different.

First, the granite-seam.jar must be used instead of granite-seam21.jar.

Second, the FacesServlet must be added in web.xml. A typical web.xml with Tide/Seam 2.0 will look like:

web.xml
<web-app version="2.4" ...>
    ...
    <!-- Seam -->
    
    <listener>
        <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
    </listener>
    
    <!-- GDS AMF message filter -->
    <filter>
        <filter-name>AMFMessageFilter</filter-name> 
        <filter-class>org.granite.messaging.webapp.AMFMessageFilter</filter-class> 
        
        <!--
        Uncomment (part of) this block if configs are not present at default locations.
        <init-param>
            <param-name>servicesConfigPath</param-name>
            <param-value>/WEB-INF/flex/services-config.xml</param-value>
        </init-param>
        <init-param>
            <param-name>graniteConfigPath</param-name>
            <param-value>/WEB-INF/granite/granite-config.xml</param-value>
        </init-param-->

    </filter>
    
    <filter-mapping>
        <filter-name>AMFMessageFilter</filter-name> 
        <url-pattern>/graniteamf/*</url-pattern> 
    </filter-mapping>

    
    <!-- JSF Servlet -->
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>
    <context-param>
        <param-name>facelets.DEVELOPMENT</param-name>
        <param-value>true</param-value>
    </context-param>
    
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- GDS AMF Servlet -->
    <servlet>
        <servlet-name>AMFMessageServlet</servlet-name>
        <servlet-class>org.granite.messaging.webapp.AMFMessageServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.seam</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>AMFMessageServlet</servlet-name>
        <url-pattern>/graniteamf/*</url-pattern>
    </servlet-mapping>
    ...
</web-app>

The security service is also different, so the granite-config.xml would look like:

granite-config.xml without automatic scanning
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE granite-config PUBLIC
    "-//Granite Data Services//DTD granite-config internal//EN"
    "http://www.graniteds.org/public/dtd/2.0.0/granite-config.dtd">

<granite-config>

    <amf3-message-interceptor type="org.granite.seam.SeamInterceptor"/>
    
    <externalizers>
        <externalizer type="org.granite.hibernate.HibernateExternalizer">
            <include annotated-with="javax.persistence.Entity"/>
            <include annotated-with="javax.persistence.MappedSuperclass"/>
            <include annotated-with="javax.persistence.Embeddable"/>
        </externalizer>
        ...
    </externalizers>
    
    ...

    <security type="org.granite.seam21.security.Seam21SecurityService"/>

    <tide-components>
        <!-- List of component matchers, see 'Enabling components' section -->
    </tide-components>
    
</granite-config>

 

granite-config.xml with automatic scanning
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE granite-config PUBLIC
    "-//Granite Data Services//DTD granite-config internal//EN"
    "http://www.graniteds.org/public/dtd/2.0.0/granite-config.dtd">

<granite-config scan="true">

    <security type="org.granite.seam.security.SeamSecurityService"/>

    <tide-components>
        <!-- List of component matchers, see 'Enabling components' section -->
    </tide-components>

</granite-config>

 


Browse Space

- Pages
- Blog
- Labels
- Attachments
- Bookmarks
- Mail
- Advanced

Explore Confluence

- Popular Labels
- Notation Guide

Your Account

Log In

Other Features

Add Content

- Add Comment


SourceForge.net Logo
Copyright © 2007-2010 Adequate Systems. All Rights Reserved.