How to set parameters on Groovy / Grails InvokeHelper.invokeMethod ()

I have a Grails web application running with a Spring Integration inbound adapter that is configured to accept emails and a service activator that processes the message. This service activator pulls email parts and parts based on business rules and then has to update the Grails domain objects and save those changes to the database.

Spring Integration Service Activator Code Snippet:

HashMap<String, Serializable> params = new HashMap<String, Serializable>();
params.put("notification", notification );
params.put("notificationType", notificationType );
params.put("sender", notificationSender );
InvokerHelper.invokeMethod(NotificationCreationService.class, "createNotification", params);

      

Fragment of the NotificationCreationSilice snippet:

def static createNotification() {
    if (params.notification != null && params.notificationType != null && params.sender != null) {
        String notification = params.get("notification") as String
        NotificationType notificationType = params.get("notificationType") as NotificationType
        String sender = params.get("sender") as String

        def NotificationMessage notificationMessage = null
        notificationMessage = new NotificationMessage()
        notificationMessage.notification = notification
        notificationMessage.save(flush: true)
        ...
    }
}

      

NotificationMessage

is a standard Grails domain class

An error was generated:

org.springframework.integration.MessageHandlingException: 
    groovy.lang.MissingMethodException: No signature of method: mycompany.pyproject.mypackage.NotificationMessage.save() is applicable for argument types: () values: []
    Possible solutions: save(), save(boolean), save(java.util.Map), wait(), any(), wait(long)

      

If I change createNotification()

to not be static

, then I get this:

org.springframework.integration.MessageHandlingException: 
    groovy.lang.MissingMethodException: No signature of method: static mycompany.pyproject.mypackage.NotificationCreationService.createNotification() is applicable for argument types: (java.util.HashMap) values: [...]       
    Possible solutions: createNotification(java.util.HashMap), createNotification(java.lang.String, napa.changedetection.alert.NotificationType, java.lang.String)

      

I've tried other combinations InvokeHelper.invokeMethod()

and definitions of Grails actions with similar results. InvokeHelper

has several other methods for calling methods as well as setting different properties, but I didn't find a magic combination to get the job done, and any search on the internet ended up very little up to the sample code for InvokeHelper.

Ideally, a Grails action will not be static and will use a standard mechanism params

. This would allow me to call the same action directly from Grails code as well as from the Spring Integration service activator through functionality InvokeMethod

.

Anyone thinking about how to tie this together?

0


a source to share


1 answer


Now you shouldn't be using InvokeHelper, Grails 2 injects signature at compile time for java purposes (other than dynamic searchers, but you can guess why).

In your Java bean, I would inject notificationCreationService using:

  • resources.groovy / xml + setter

    OR

  • Constructor + applicationContext (implement ApplicationContextAware)


Using a service link should work if there is no error to parse it.

Where did you declare the service activator?

+2


a source







All Articles