DekGenius.com
[ Team LiB ] Previous Section Next Section

Recipe 20.4 Configuring Flash Remoting for J2EE

20.4.1 Problem

You want to configure Flash Remoting for J2EE.

20.4.2 Solution

Copy the flashgateway.jar file into the web application's WEB-INF/lib directory and configure a servlet and servlet-mapping in the web.xml file. If you use JRun 4 as your J2EE server, Flash Remoting comes preinstalled.

20.4.3 Discussion

If you are using JRun 4 as your J2EE server, Flash Remoting comes preinstalled and you do not need to purchase or configure any additional software. If you use a third-party J2EE server, such as IBM WebSphere or BEA Weblogic, the Flash Remoting for J2EE gateway, sold separately by Macromedia, allows Flash clients to communicate with Enterprise Java applications (see http://www.macromedia.com/software/flashremoting/productinfo/versions_pricing). If you are not using JRun 4, you must download and install either the trial version or full version before proceeding. (As an open source alternative, see the OpenAMF project at http://www.openamf.org.)

All the necessary code for Flash Remoting for J2EE is contained within the flashgateway.jar file. You can find this file in the Flash Remoting installation (on Windows machines this is typically under C:\Program Files\Macromedia\Flash Remoting MX). You can either extract the .jar file from the .war file (flashgateway-samples.war) or copy it from the sample application (within the sample\WEB-INF\lib subdirectory). You should copy this .jar file to the WEB-INF/lib directory of your own J2EE web application.

Once you have copied the .jar file into your web application, you only need to configure a servlet and servlet-mapping for the J2EE Flash Remoting gateway servlet that is contained within the .jar file. You should map the servlet to the URL pattern /gateway (the name /gateway is not required, but it is a logical choice). The following shows an example web.xml file with the necessary <servlet> and <servlet-mapping> tags:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
 "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
  <display-name>My Application</display-name>
  <servlet>
    <servlet-name>FlashGatewayServlet</servlet-name>
    <servlet-class>
      flashgateway.controller.GatewayServlet
    </servlet-class>
    <init-param>
      <param-name>LOG_LEVEL</param-name>
      <param-value>Error</param-value>
    </init-param>
    <init-param>
      <param-name>DISABLE_JAVA_ADAPTERS</param-name>
      <param-value>false</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>FlashGatewayServlet</servlet-name>
    <url-pattern>/gateway</url-pattern>
  </servlet-mapping>
</web-app>

The correct gateway URL to use within your Flash movies to connect to Flash Remoting for J2EE (as discussed in Recipe 20.1) should be of the form:

http://j2eeServerNameOrIP[:port]/applicationContext/gateway

in which j2eeServerNameOrIP is the domain name or IP address of the J2EE application server, and applicationContext is the context for the web application as it is configured by the application server. For example, the correct gateway URL for web application on localhost (port 80) with a context of /myApplication is:

http://localhost/myApplication/gateway

20.4.4 See Also

Recipe 20.1, Recipe 20.13, Recipe 20.17, and Recipe 20.20. "Flash Remoting for J2EE Developers" at http://www.onjava.com/pub/a/onjava/2003/02/26/flash_remoting.html and The OpenAMF Java Flash Remoting project (http://www.openamf.org), a free, open source alternative to Macromedia's Flash Remoting for J2EE. Information on JRun can be found at http://www.macromedia.com/software/jrun.

    [ Team LiB ] Previous Section Next Section