Class IntegrationApiExceptionTranslationHandler

java.lang.Object
de.hybris.platform.integrationbackoffice.exceptionhandlers.IntegrationApiExceptionTranslationHandler
All Implemented Interfaces:
com.hybris.cockpitng.service.ExceptionTranslationHandler, org.springframework.core.Ordered
Direct Known Subclasses:
IntegrationBackofficeExceptionTranslationHandler, OutboundSyncBackofficeExceptionTranslationHandler, WebhookExceptionTranslationHandler

public abstract class IntegrationApiExceptionTranslationHandler extends Object implements com.hybris.cockpitng.service.ExceptionTranslationHandler, org.springframework.core.Ordered
An abstract class for translating target exceptions to localized error messages. Its subclass needs to overwrite methods in order to specify the target exceptions. Target exceptions are those that can be handled even if they caused some other exception. For example, if targetException is an exception known by the handler and there is another exception, e.g. var ex = new Throwable(targetException), then the root cause(s) of the ex will be analyzed and when targetException is found, the message will be displayed for the targetException instead of the ex.

The message is retrieved from the localization properties of this extension by the resource bundle key that has the following format: <prefix>.exceptionTranslation.msg.<exception_simple_class_name>

, where <prefix> is the resource bundle prefix used by the handler or by the extension in general (for all messagges and not only for exception translation).
  • Constructor Details

    • IntegrationApiExceptionTranslationHandler

      public IntegrationApiExceptionTranslationHandler()
  • Method Details

    • canHandle

      public boolean canHandle(Throwable throwable)
      Specified by:
      canHandle in interface com.hybris.cockpitng.service.ExceptionTranslationHandler
    • toString

      public String toString(Throwable throwable)
      Specified by:
      toString in interface com.hybris.cockpitng.service.ExceptionTranslationHandler
    • getOrder

      public int getOrder()
      Specified by:
      getOrder in interface org.springframework.core.Ordered
    • getTargetedExceptions

      protected abstract Collection<Class<? extends Throwable>> getTargetedExceptions()
    • convertExceptionToResourceMsg

      protected String convertExceptionToResourceMsg(Throwable exception)
      Try to get bundle resource with the information of the exception that is being handled.
      Parameters:
      exception - The exception that is being translated. Use its class name or other information as key to get bundle resource
    • extractParameters

      protected Object[] extractParameters(Throwable exception)
      Extracts parameters from the given exception.
      Parameters:
      exception - an exception to convert to a parameters array.
      Returns:
      the parameters array that will be used to format the localized message or an empty array, if the message for the exception should not have parameters.
    • getKeyPrefix

      protected abstract String getKeyPrefix()
      Retrieves prefix of all property keys in the resource bundle used by this extension/handler. All localization keys should start with this prefix, then followed by "." and further key specification.
      Returns:
      a prefix to be used for localization property keys in the resource bundle.
    • setLocalizationService

      public void setLocalizationService(LocalizationService service)
      Injects localization service implementation to be used for localized message retrieval from the localization resource bundle.
      Parameters:
      service - a localization service implementation. If null, then a default service available in the platform will be used.