I struggle to display a notification from middleware service to client tier.
I made a new Exception class that actually is triggered in Catalina.out and I made a ControlledExceptionHandler too.
I put the ControlledExceptionHandler under Screens package (I’m not sure that is correct, I tried to put in Core level but I don’t have access to AbstractUiExceptionHandler base class).
Unfortunatelly I don’t know how to trigger (access) this handler in Middlleware service.
(I can only injected in client tier level).
Middleware Service
try{
}catch(Exception e){
throw new ControlledException("text"); //it works
//handler call??
}
ControlledExceptionHandler
@Component("myapp_ControlledExceptionHandler")
public class ControlledExceptionHandler extends AbstractUiExceptionHandler {
public ControlledExceptionHandler() {
super(ControlledException.class.getName());
}
@Override
protected void doHandle(String className, String message, @Nullable Throwable throwable, UiContext context) {
// windowManager.showNotification("Title", message, Frame.NotificationType.ERROR);
context.getNotifications().create(Notifications.NotificationType.ERROR)
.withCaption("`My message which has to be displayed in client tier` ")
.withDescription(message)
.show();
}
@Override
public boolean handle(Throwable exception, UiContext context) {
return super.handle(exception, context);
}
@Override
protected boolean canHandle(String className, String message, @Nullable Throwable throwable) {
return StringUtils.containsIgnoreCase(message, " ");
}
In Middleware Service you are throwing a ControlledException with the “text” message.
In ControlledExceptionHandler you are trying to handle an exception with a message that contains a space. But there is no space in the error message (“text”).
The canHandle(String className, String message, @Nullable Throwable throwable) method is used if the name of the exception class is insufficient to make a decision whether this handler can be applied to the exception.
Now it works but doesn’t help me too much.
It worksonly if in the client method I don’t cath the ControlledException. When the ControlledException arrise the handler do its job.
But I can throws Exception at the method signature level and cath the ControlledException below (without use any handler).
catch (ControlledException d){
notifications.create()
.withCaption("My message which has to be displayed in client tier" )
.show();
}
If I use general Exception the handler doesn’t work.
I need to catch all exceptions without Controlled exception(with a notification) and Controlled exception(with another/different notification). Of course I can do treating all exceptions but I thouhgt the handler can help me.
Unhandled exceptions thrown on the client tier or passed from Middleware, are passed to the special handlers mechanism of the Web Client block.
Client-level exception handlers handle only unhandled exceptions thrown on the client tier or passed from Middleware. Therefore, you cannot handle exceptions with client-level exception handlers that you already handle in Middleware service.