diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/WebServerMessage.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/WebServerMessage.java index 6dc4bfa762..74c8b52def 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/WebServerMessage.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/WebServerMessage.java @@ -17,26 +17,17 @@ package io.cloudbeaver.model; import io.cloudbeaver.utils.CBModelConstants; +import org.jkiss.dbeaver.model.websocket.event.MessageType; import java.io.PrintWriter; import java.io.StringWriter; import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneId; /** * Web server message */ public class WebServerMessage { - - public enum MessageType { - DEBUG, - INFO, - WARNING, - ERROR - } - private final MessageType type; private final Instant time; private final String message; diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/rm/local/LocalResourceController.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/rm/local/LocalResourceController.java index 34d11920e8..a12d43a2bc 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/rm/local/LocalResourceController.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/rm/local/LocalResourceController.java @@ -43,6 +43,9 @@ import org.jkiss.dbeaver.model.security.SMController; import org.jkiss.dbeaver.model.security.SMObjectType; import org.jkiss.dbeaver.model.sql.DBQuotaException; +import org.jkiss.dbeaver.model.websocket.event.MessageType; +import org.jkiss.dbeaver.model.websocket.event.WSEventType; +import org.jkiss.dbeaver.model.websocket.event.WSSessionLogUpdatedEvent; import org.jkiss.dbeaver.registry.*; import org.jkiss.dbeaver.runtime.DBWorkbench; import org.jkiss.utils.ArrayUtils; @@ -958,7 +961,19 @@ private void createResourceTypeFolders(Path path) { protected T doProjectOperation(String projectId, RMFileOperation operation) throws DBException { for (RMFileOperationHandler fileHandler : fileHandlers) { - fileHandler.projectOpened(projectId); + try { + fileHandler.projectOpened(projectId); + } catch (Exception e) { + if (credentialsProvider.getActiveUserCredentials() != null) { + WebAppUtils.getWebApplication().getEventController().addEvent( + new WSSessionLogUpdatedEvent( + WSEventType.SESSION_LOG_UPDATED, + credentialsProvider.getActiveUserCredentials().getSmSessionId(), + credentialsProvider.getActiveUserCredentials().getUserId(), + MessageType.ERROR, + e.getMessage())); + } + } } return operation.doOperation(); } @@ -968,6 +983,15 @@ protected T doFileReadOperation(String projectId, Path file, RMFileOperation try { fileHandler.beforeFileRead(projectId, file); } catch (Exception e) { + if (credentialsProvider.getActiveUserCredentials() != null) { + WebAppUtils.getWebApplication().getEventController().addEvent( + new WSSessionLogUpdatedEvent( + WSEventType.SESSION_LOG_UPDATED, + credentialsProvider.getActiveUserCredentials().getSmSessionId(), + credentialsProvider.getActiveUserCredentials().getUserId(), + MessageType.ERROR, + e.getMessage())); + } log.error("Error before file reading", e); } } diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/BaseWebSession.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/BaseWebSession.java index caf0f59f85..d96429c4e6 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/BaseWebSession.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/BaseWebSession.java @@ -16,6 +16,7 @@ */ package io.cloudbeaver.model.session; +import io.cloudbeaver.model.WebServerMessage; import io.cloudbeaver.model.app.WebApplication; import io.cloudbeaver.model.app.WebAuthApplication; import io.cloudbeaver.websocket.CBWebSessionEventHandler; @@ -201,6 +202,8 @@ public void removeSessionProject(@Nullable String projectId) throws DBException userContext.getAccessibleProjectIds().remove(projectId); } + public abstract void addSessionMessage(WebServerMessage message); + @Property public boolean isValid() { return getRemainingTime() > 0; diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebHeadlessSession.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebHeadlessSession.java index 9f8856507b..c71e55aa19 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebHeadlessSession.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebHeadlessSession.java @@ -16,6 +16,7 @@ */ package io.cloudbeaver.model.session; +import io.cloudbeaver.model.WebServerMessage; import io.cloudbeaver.model.app.WebAuthApplication; import org.jkiss.code.NotNull; import org.jkiss.dbeaver.DBException; @@ -37,6 +38,11 @@ public void addSessionError(Throwable exception) { } + @Override + public void addSessionMessage(WebServerMessage message) { + + } + @Override public SMSessionPrincipal getSessionPrincipal() { return null; diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java index 740c3eea6d..35e5827198 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java @@ -68,6 +68,7 @@ import org.jkiss.dbeaver.model.security.SMObjectType; import org.jkiss.dbeaver.model.security.user.SMObjectPermissions; import org.jkiss.dbeaver.model.sql.DBQuotaException; +import org.jkiss.dbeaver.model.websocket.event.MessageType; import org.jkiss.dbeaver.model.websocket.event.WSEventType; import org.jkiss.dbeaver.model.websocket.event.WSSessionLogUpdatedEvent; import org.jkiss.dbeaver.registry.DataSourceDescriptor; @@ -726,15 +727,20 @@ public void addSessionMessage(WebServerMessage message) { synchronized (sessionMessages) { sessionMessages.add(message); } - addSessionEvent(new WSSessionLogUpdatedEvent()); + addSessionEvent(new WSSessionLogUpdatedEvent( + WSEventType.SESSION_LOG_UPDATED, + this.userContext.getSmSessionId(), + this.userContext.getUserId(), + MessageType.ERROR, + message.getMessage())); } public void addInfoMessage(String message) { - addSessionMessage(new WebServerMessage(WebServerMessage.MessageType.INFO, message)); + addSessionMessage(new WebServerMessage(MessageType.INFO, message)); } public void addWarningMessage(String message) { - addSessionMessage(new WebServerMessage(WebServerMessage.MessageType.WARNING, message)); + addSessionMessage(new WebServerMessage(MessageType.WARNING, message)); } public List readLog(Integer maxEntries, Boolean clearLog) { diff --git a/server/bundles/io.cloudbeaver.server/plugin.xml b/server/bundles/io.cloudbeaver.server/plugin.xml index 71dcc26bb1..eb75b6ef1d 100644 --- a/server/bundles/io.cloudbeaver.server/plugin.xml +++ b/server/bundles/io.cloudbeaver.server/plugin.xml @@ -70,6 +70,9 @@ + + + diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/events/WSLogEventHandler.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/events/WSLogEventHandler.java new file mode 100644 index 0000000000..cef7816000 --- /dev/null +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/events/WSLogEventHandler.java @@ -0,0 +1,33 @@ +/* + * DBeaver - Universal Database Manager + * Copyright (C) 2010-2023 DBeaver Corp + * + * All Rights Reserved. + * + * NOTICE: All information contained herein is, and remains + * the property of DBeaver Corp and its suppliers, if any. + * The intellectual and technical concepts contained + * herein are proprietary to DBeaver Corp and its suppliers + * and may be covered by U.S. and Foreign Patents, + * patents in process, and are protected by trade secret or copyright law. + * Dissemination of this information or reproduction of this material + * is strictly forbidden unless prior written permission is obtained + * from DBeaver Corp. + */ +package io.cloudbeaver.server.events; + +import io.cloudbeaver.model.WebServerMessage; +import io.cloudbeaver.model.session.BaseWebSession; +import org.jkiss.code.NotNull; +import org.jkiss.dbeaver.model.websocket.event.WSSessionLogUpdatedEvent; + +public class WSLogEventHandler extends WSDefaultEventHandler { + + protected void updateSessionData(@NotNull BaseWebSession activeUserSession, @NotNull WSSessionLogUpdatedEvent event) { + activeUserSession.addSessionMessage(new WebServerMessage(event.getMessageType(), event.getMessage())); + } + + protected boolean isAcceptableInSession(@NotNull BaseWebSession activeUserSession, @NotNull WSSessionLogUpdatedEvent event) { + return WSWebUtils.isSessionIdEquals(activeUserSession, event.getSessionId()); + } +}