Command Handling Return values

Hi,
I am working in a flex application using spring,hibernate and axon. In
the logon process I want to return some data: the aggregate id, a
authenticate string code and some other data like user state, passwrod
expiring days, etc.

I've decide to use a command handler cause this process changes the
state of the server, but i have problems receiving the response in
flex. I'm receiving a void ProxyObject.

Where am i wrong? Anyone can help me? Can i found any example
returning data to flex client?

Thanks!!

Code:

public class UsuariCommandHandler {
  private Repository<Usuari> repository;
  private UsuariRepository usuariRepository;

  @CommandHandler
  public UsuariAuthenticatedResult
handleAuthenticateUser(UsuariAuthenticateCommand command) throws
DeskException {
        Assert.notNull(command.getIdent(),
"usuari.authenticate.ident.null");
        Assert.notNull(command.getPassword(),
"usuari.authenticate.password.null");

        try {
          Usuari usuari;

            String usuariId = command.getUsuariId();
            if (usuariId == null) {
              usuariId = UUID.randomUUID().toString();

              UsuariEntry account =
usuariRepository.getByIdent(command.getIdent());
              usuari = new Usuari(new
StringAggregateIdentifier(usuariId),account);
        usuari.authenticate(command.getPassword());
        repository.add(usuari);
            } else {
              usuari = repository.load(new
StringAggregateIdentifier(usuariId));
            }

             String code = usuari.authorize(command.getToken());

             UsuariAuthenticatedResult result = new
UsuariAuthenticatedResult(usuariId,code,usuari.getUsuariState(),usuari.daysToExpirePassword());
      return result;
    } catch (NoResultException e) {
      throw new UsuariException(e);
    }
  }

  @Autowired
  public void setRepository(Repository<Usuari> repository) {
    this.repository = repository;
  }

  @Autowired
  public void setUsuariRepository(UsuariRepository userRepository) {
    this.usuariRepository = userRepository;
  }
}

Flex:
package commands.system
{
  import commands.BaseController;

  import model.system.UserAuthenticateEvent;

  import mx.messaging.messages.AcknowledgeMessage;
  import mx.rpc.AsyncToken;
  import mx.rpc.events.FaultEvent;

  public class LoginUserController extends BaseController {

    public function LoginUserController() {
      super();
    }

    public function execute(event:UserAuthenticateEvent):AsyncToken {
      var command:UsuariAuthenticateCommand = new
UsuariAuthenticateCommand();
      command.ident = event.user.ident;
      command.password = event.user.password;

      return commandReceiver.sendCommand(command);
    }

    public function result(result:*):void {
      return;
    }
  }
}

The address book sample application contains a complete Flex sample. It might be a bit dated, since I did not upgrade any of the flex code for at least e year. But it did work.

https://github.com/AxonFramework/Addressbook-Sample

regards Jettro

Thanks Jettro,
I'm learning with your Addredbook app, but i've haven't found any case
that can help me.

May be i have to use entityManager like you use in
JpaContactNameRepository.claimContactName.

My apologies. I'm training to undesrtand how work all togheter.

Thanks a lot.
Regards,
Manel

You can check the CommandReceiverImpl class, the method

FutureCallback callback = new FutureCallback();
commandBus.dispatch(new GenericCommandMessage(command), callback);
try {
return callback.get();
} catch (Exception e) {
throw new RuntimeException(e);
}

Shows the mechanism to use a Future. The most important class here is the FutureCallback.

Hope that helps,

regards Jettro