Is it possible to retrieve a connector's exception message and stack trace with a CONNECTOR_INSTANCE_STATE_UPDATED Event Handler?

1
0
-1

Hi,

Consider a task or activity with:

  • a connector that throws an error event when it fails
  • a boundary catch error event that catches the error thrown by the connector

Now, when the connector fails, the boundary event will catch the error, and the task/activity will be archived, as a result of which the failed connector's exception message and stack trace will be lost from the portal (sure enough, they will have been logged in the server log file, but that is only accessible to the system administrator).

So,

  • Would it be somehow possible to use an Event Handler triggered by the CONNECTOR_INSTANCE_STATE_UPDATED event (or even the more general CONNECTOR_INSTANCE_UPDATED one) to catch the exception message and stack trace from the newly failed connector (before the connector is archived alongside the task/activity by the boundary event) and make it available to the portal user or administrator?
  • How could the ConnectorInstanceWithFailureInfoImpl class be used, to benefit from the getExceptionMessage() and getStackTrace() methods?

Thanks in advance for your help,

Unai

1 answer

1
+2
-1
This one is the BEST answer!

Hello,

This method is called when setting the connector as failed:

https://github.com/bonitasoft/bonita-engine/blob/master/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/connector/impl/ConnectorInstanceServiceImpl.java#L106

This produces an update event of type CONNECTOR_INSTANCE_UPDATED with fields updated: exceptionMessage and stackTrace

The handle should be registered on the CONNECTOR_INSTANCE_UPDATED event type.

The is isInterested method should check the type of the and fields of the event like that:

 @Override  
    public boolean isInterested(SEvent event) {  
        return event instanceof SUpdateEvent  
                && event.getObject() instanceof SConnectorInstanceWithFailureInfo  
                && Optional.ofNullable(((SUpdateEvent) event).getUpdatedFields())  
                        .filter(map -> map.containsKey("exceptionMessage"))  
                        .filter(map -> map.containsKey("stackTrace"))  
                        .isPresent();  
    }

and then you can safely cast the event or the object in the execute method

    @Override  
    public void execute(SEvent event) throws SHandlerExecutionException {  
        SConnectorInstanceWithFailureInfo connector = (SConnectorInstanceWithFailureInfo) event.getObject();  
        //or  
        String exceptionMessage = ((SUpdateEvent) event).getUpdatedFields().get("exceptionMessage");  
        String stackTrace = ((SUpdateEvent) event).getUpdatedFields().get("stackTrace");  
    }

HTH,

Baptiste.

Comments

Submitted by unai.gaston.caminos on Thu, 11/19/2020 - 13:01

Thanks a lot, Baptiste, much appreciated!

Notifications