3. Configuration for EJB 3
Configuration for EJB 3
In order to initialize GDS/Tide for EJB 3 and Hibernate, you must add granite.jar and granite-hibernate.jar to your WEB-INF/lib or in the lib directory of an ear. For other JPA providers, just use the corresponding GDS jar plugin from the distribution.
In the case of ear packaging, it is important to put all libs in ear/lib and to make sure that no jar concerning JPA persistence is left in WEB-INF/lib.
Then you have to add the following configuration to your web.xml:
<web-app version="2.4" ...> ... <!-- Granite config context listener --> <listener> <listener-class>org.granite.config.GraniteConfigListener</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> ... </web-app>
Then you have to configure the specific Tide/EJB 3 destination and service factory in service-config.xml:
<services-config> <services> <service id="granite-service" class="flex.messaging.services.RemotingService" messageTypes="flex.messaging.messages.RemotingMessage"> <!-- ! Use "tideEjbFactory" and "my-graniteamf" for "ejb" destination (see below). ! The destination must be "ejb" when using Tide with default configuration. !--> <destination id="ejb"> <channels> <channel ref="my-graniteamf"/> </channels> <properties> <factory>tideEjbFactory</factory> <entity-manager-factory-jndi-name>java:/DefaultEMF</entity-manager-factory-jndi-name> </properties> </destination> </service> </services> <!-- ! Declare tideEjbFactory service factory. !--> <factories> <factory id="tideEjbFactory" class="org.granite.tide.ejb.EjbServiceFactory"> <properties> <lookup>myApp.ear/{capitalized.component.name}ServiceBean/local</lookup> </properties> </factory> </factories> <!-- ! Declare my-graniteamf channel. !--> <channels> <channel-definition id="my-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 the destination named "ejb" will be the one and only configuration needed here for all remote EJB calls.
The lookup property of the factory is used by Tide to lookup the EJBs from the global JNDI. The example here is suitable for JBoss, however other servers may have different naming schemes.
The entity-manager-factory-jndi-name must be the global JNDI name of the EntityManagerFactory that will be used by Tide to enable transparent lazy loading.
In many JEE servers (GlassFish for example, but not JBoss), EJB local interfaces are not published in the global JNDI. To be able to call them through Tide, you will have to add additional ejb-local-ref definitions for each EJB in web.xml.
Finally, there is a little more configuration in granite-config.xml for Tide and container security integration:
<granite-config scan="true"> <security type="org.granite.messaging.service.security.TomcatSecurityService"/> <tide-components> <!-- List of component matchers, see 'Enabling components' section --> </tide-components> </granite-config>
Note that you must use automatic scanning in granite-config.xml. This is necessary because Tide needs to have access to the real EJB implementation classes and not only the proxies that are retrieved from JNDI. Additionally, the Tide-enabled EJBs have to be annotated with @RemoteDestination so the GDS scanner knows that it should scan their classes. In most cases, the following granite-config.xml will be appropriate for use with EJB services :
<granite-config scan="true"> <security type="org.granite.messaging.service.security.TomcatSecurityService"/> <tide-components> <tide-component annotated-with="org.granite.messaging.service.annotations.RemoteDestination"/> </tide-components> </granite-config>
The security service defined here is for the Tomcat servlet container. If you use another container, just use the specific security service (GDS comes with out-of-the-box security services for Tomcat, Jetty, GlassFish V2/V3 and WebLogic), and it is very easy to write your own for other servers.
