Example of Using the MetadataAwareRemoteFactoryBean

ColdSpring has generated a Remote Proxy component for our UserService.
We are about to invoke that Remote Proxy as a web service by using the URL:

http://localhost:8500/beanutils/example/RemoteUserService.cfc?wsdl

and call the getUser() remote method.

Normally, calling getUser() on our RemoteUserService would return a User object, because that is what the underlying UserService returns from its getUser() method. What we have done is apply an AOP advice to the RemoteUserService's getUser() method that will convert the User object into a typed structure that could be used by a Flex application. Flex sees the typed structure as a real User object. Using this workaround, it is possible to send large numbers of objects to Flex (perhaps from a query) without incurring the overhead of creating a large number of CFC instances.

The web service call to RemoteUserService triggered the following sequence of events:

  1. RemoteUserService recieves the method call and hands processing to the first (and only) interceptor VOConverterAdvice
  2. The VOConverterAdvice proceeds with the method call to UserService's getUser()
  3. UserService.getUser() returns a User object to the Advice
  4. Because VOConverterAdvice extends AbstractMetadataAwareAdvice, it locates the metadata
    configuration file named "userservice.xml" at the location specified by the advice's "metadataPath"
    property (see the coldspring.xml)
  5. The advice parses the XML and locates metadata specified for the getUser() method
    (see the userservice.xml)
  6. The metadata specifies that a ColdSpring bean named "UserVOConverter" should be used to
    perform the conversion
  7. The VOConverterAdvice passes the metadata and the user object to the UserVOConverter
  8. UserVOConverter uses the metadata and the object to generate a typed structure containing the User data
  9. The typed structure is returned to the VOConverterAdvice
  10. The typed structure is returned to the RemoteUserService
  11. The RemoteUserService returns the typed structure to the caller (in this case, the web service call)

Normally, it would not be possible to dynamically configure the VOConverterAdvice to use different converter objects for different method calls. An entirely separate Advice would have to be configured in the coldspring.xml. By adding metadata, the Advice becomes far more flexible and is able to use the proper converters that may be required by different method calls. Other possible uses include specifying what variables to log for different method calls in a LoggingAdvice, or specifying security rules for different method calls in a SecurityAdvice.