Hi all,
When using GatewayProxyFactoryBean, I noticed that it's behaviour when proxying a method with no arguments is to wait for an incoming message via receive(...), without actually sending a message.
I wanted different behaviour in this case; specifically, I wanted the proxy to send a message anyway for a method with no args, via sendAndReceive(...). After examining the code, I came up with the following quick workaround which is currently meeting my requirements:
Step 1 - annotate the desired gateway interface method with a payload annotation, that uses a SpEL expression to create a payload instance:
Step 2 - annotate a corresponding service implementation method with a service activator annotation:Code:@Payload("new Item()") List<Item> findAllItems();
Step 3 - Copy the source of GatewayProxyFactoryBean (v2.0.4) into a new class, e.g. NoArgMethodCapableGatewayProxyFactoryBean (in the same package) and comment out lines 264-270. This ensures that sendAndReceive(...) is called instead of receive(...) with an empty args Object array, in the case where the method has no arguments.Code:@ServiceActivator public List<Item> findAllItems() { ... }
Step 4 - Define a spring application context to wire up a gateway proxy using the above implementation to a service bean, via a channel and service activator as usual.
The above is currently working for me, personally I think it would be great if the GatewayProxyFactoryBean behaviour for a no-arg method could be configurable, either use the current receive(...) behaviour, or use sendAndReceive(...) if a payload is configured either by a method annotation as above, or by xml configuration.
Any feedback would be appreciated.
Thanks
Alex.


Reply With Quote