« Flash Remoting Mystery Time | Main | Designing Remote Service APIs »
July 5, 2005
SpringBeanAdapter for Flex Flash Remoting
The Spring Framework is a popular open source framework for managing enterprise Java application components. SpringBeanAdapter provides the ability to locate Flash Remoting services in a Spring application context. Additionally, it provides the ability for server-side developers to exercise custom control over the handling of server-side errors. We have documented and released this implementation on our Sourceforge Open Source site.SpringBeanAdapter is supported by Carbon Five.
Overview
Flash Remoting comes with a number of adapters for locating remote services implemented as Java classes, EJBs, servlets, and JMX Beans. The Spring Framework is a popular open source framework for managing enterprise Java application components. SpringBeanAdapter provides the ability to locate Flash Remoting services in a Spring application context.Features
- Locate Remoting services by bean name in Spring application context
- Customizable error handling of server-side exceptions
Download
The latest release of SpringBeanAdapter is available for download from SourceForge.net. For the adventurous, you can check out the latest changes from CVS.Prerequisites
SpringBeanAdapter depends on:- The Spring Framework - home page
- Macromedia Flash Remoting (Flex version) - Flex home page
Install
To install SpringBeanAdapter you must unzip springadapter-x.x.zip and copy the following jars to your web application's WEB-INF/lib/ directory:- lib/springadapter-x.x.jar
Configure Flash Remoting to use SpringBeanAdapter by editing your Flex Flash Remoting configuration file located in WEB-INF/flex/gateway-config.xml.
<service-adapters>
<adapter type="stateless-class">com.carbonfive.flash.spring.SpringBeanAdapter</adapter>
</service-adapters>
Usage
SpringBeanAdapter handles services named with a 'spring://' prefix. We recommend using named remote services in Flex by adding services to your Flex configuration in WEB-INF/flex/flex-config.xml: The following is just a sample from a flex-config.xml file: <remote-objects>
<named>
<object name="LocalServiceName">
<source>spring://RemoteServiceName</source>
<type>stateless-class</type>
<allow-unnamed-access>false</allow-unnamed-access>
</object>
</named>
</remote-objects>
With this configuration, you can then use remote object services from your Flex application with:
<mx:RemoteObject id="serviceName" named="LocalServiceName"/>
Error Handling
SpreadBeanAdapter provides a nice feature for developers who want control over how errors that happen on the server are sent to the Flash client. In the standard adapters provided by Macromedia, server errors are converted to a class, flashgateway.GatewayException, that contains the same properties as the fault object received by the Flash client:- type
- code
- message
- details
public class ExampleExceptionFactory implements java.io.Serializable, RemotingExceptionFactory { public static String CUSTOM_CODE = "Server.Custom"; public void throwException(Throwable t) throws Exception { if (t instanceof SecurityException) { GatewayException e = new GatewayException(t.getMessage()); e.setRootCause(t); e.setCode(GatewayException.SERVER_AUTHORIZATION); throw e; } else if (t instanceof IndexOutOfBoundsException) { GatewayException e = new GatewayException(t.getMessage()); e.setRootCause(t); e.setCode(CUSTOM_CODE); throw e; } if (t instanceof Exception) throw (Exception) t; else if (t instanceof Error) throw (Error) t; } }If you do not convert the exception to a GatewayException in your implementation of RemotingExceptionFactory, it will be handled by the standard Flash Remoting exception handling process.
Posted by Alon Salant at July 5, 2005 12:02 PM
Comments
Congrats to everyone in Carbon Five for this proyect. I'll try it and i'll give you a proper feedback. Thanks for sharing this!.
Posted by: German at July 11, 2005 7:50 AM
Has anyone gotten this to work with a remote service? Where exactly do I put the gateway address(ive tried the <amf-gateway> tag) and the service name? I dont even see any errors coming up in flex or on the remote server. This would be rad if it worked!
Posted by: bwise at October 6, 2005 12:30 AM
Your gateway configuration should be exactly the same as for any other RemoteObject service. I have mine configured in <amf-gateway>.
I assume you've confirmed that you can access a regular Java service with RemoteObject.
Do you have other service adapters enabled? I have SpringBeanAdapter configured as my first service adapter in gateway-config.xml.
-alon
Posted by: Alon Salant at October 6, 2005 9:49 AM
Do you know if SpringBeanAdapter will work with OpenAMF?
Posted by: Cliff Meyers at August 17, 2006 11:10 AM
OpenAMF has its own implementation of SpringBeanAdapter that accomplishes the same thing. They call it SpringBeanInvoker in that project.
Posted by: Alon Salant at August 24, 2006 12:09 PM
