Creating Flex "remoting proxies" in Groovy
When you're developing a RIA based on a set of business services, it's rare that your domain model is simple enough to just expose the raw services to Flex. Often, you'll have spots where you need to work in thinner DTOs or do a little extra work specific to Flex.
While you can do a fair amount of this with AOP, that's often like hunting flies with an elephantswatter. Instead, I've been creating remoting services that defer any method not explicitly defined to the business service they wrap. If I need to add a smattering of "advice" before or after a method call, I then just define the method and add my bits.
Here's an example, using a fictitious "LoginService" being proxied by "FlexLoginService."
class FlexLoginService
{
// Injected by Spring
LoginService loginService
/**
* By default, defer invocations to wrapped LoginService
*/
def methodMissing(String name, args)
{
return loginService.invokeMethod(name, args)
}
/**
* Wrap the "login" method to deal with the UserDTO sent from Flex
* - the business service expects a full-size User object
*/
login (UserDTO userDTO)
{
def user = new User(username: userDTO.username, password: userDTO.password)
loginService.login(user)
}
}

There are no comments for this entry.
[Add Comment]