This article covers a Bloomreach Experience Manager version 13. There's an updated version available that covers our most recent release.

Abort a Channel Manager Action

Introduction

Goal

Abort a channel manager action using a channel event listener.

Summary

Channel manager event listeners that use the HST internal event bus mechanism can abort channel manager actions by setting an exception on the event object. This can be useful in case some requirement is not met or the post-processing fails. Two different exceptions - RuntimeException and ClientException - can be used, each with a different effect:

  1. A RuntimeException's message will be logged in the server log and the Channel Manager UI will render a generic, localized message informing the user that the action failed.
  2. A ClientException has the option to add a custom message to be rendered in the Channel Manager UI.

This page explains how to achieve the intended behavior using each exception type.

Abort with a Generic Error Message Using a RuntimeException

The most straightforward way to abort a channel manager action in an event listener is by setting a RuntimException on the event object as in the following example:

    @Subscribe
    public void onEvent(ChannelEvent event) {
        if (event.getException() != null) {
            return;
        }
 
        event.setException(new RuntimeException("This will abort the action"));        
    }

This will render a generic error message in the Channel Manager UI, informing the user that the action failed. For example, Failed to publish changes.

It will also cause a message to be logged similar to the the one below, followed by a stacktrace of the exception.

08.04.2019 11:09:26 WARN  http-nio-8080-exec-3 [AbstractConfigResource.logAndReturnServerError:184] java.lang.RuntimeException: This will abort the action

Abort and Provide a Custom Feedback Message Using a ClientException

A more user-friendly way to abort a channel manager action is by providing a custom feedback message using a ClientException as in the following example:

    @Subscribe
    public void onEvent(ChannelEvent event) {
        if (event.getException() != null) {
            return;
        }
 
        final Map<String, String> parameterMap = new HashMap<>();
        parameterMap.put("userMessage", "Channel {{channel}} can't be published after 9 PM");
        parameterMap.put("channel", event.getEditingPreviewSite().getName());
        final String techDetails = "add technical details here"; 
        event.setException(new ClientException(techDetails, ClientError.UNKNOWN, parameterMap));        
    }

This will render the userMessage in the Channel Manager UI.

At the moment, the custom message cannot be easily localized because the locale of the authenticated user is not available to the event listener. This may be improved in a future Bloomreach Experience Manager release (see the relevant JIRA ticket).
Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?