Hi
I find solution my problem in topic https://www.cuba-platform.com/discuss/t/unable-to-receive-globalevent-separate-tomcat-for-app-war-app-core-war/7149
but I don’t understand first item
“Changing data object type in GlobalUiEvent into String”
GlobalUiEvent
is the interface. How have I an understanding of this tip ?
Can I look to any example ?
Hi @andrzej.paluch72
Yess sorry for late response,
-
Create Class that extends GlobalApplicationEvent
and implements GlobalUiEvent
on that class construction set one paramater as String type
public class MasterDataPropagateEvents extends GlobalApplicationEvent implements
GlobalUiEvent {`
private String MasterDataStr="";
public MasterDataPropagateEvents(Objec source,String data) {
super(source);
this.MasterDataStr=data;
}
@Override
public getSource(){
return super.getSource();
}
public String getMasterDataStr() {
return this.MasterDataStr;
}
}
-
After that create bean Class that has @Inject Events from import com.haulmont.cuba.core.global.Events package on it, so we can publish data to GUI screen
public String sendUiNotificationEvent(FosterMasterDataRevb message) {
MasterDataPropagateEvents propagateEvents =new MasterDataPropagateEvents(this,
message);
events.publish(propagateEvents);
return "done";
}
-
Call #2 class in Entity listener class and execute sendUiNotificationEvent
-
Create method to receive event in your GUI Screen just like below
@EventListener
public void onUiNotificationEvent(MasterDataPropagateEvents event) {
System.out.println(event.getMasterDataStr());
}
Hi
Thanks for reply.
I have got still problem when app.war and app-core.war are sperate.
- First of all I change manually
websocket-sping.xml
like below in cubaglevt-core-0.3.0.jar
cubaglevt-core-0.3.0.jar (12.7 KB)
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:websocket="http://www.springframework.org/schema/websocket"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/websocket
http://www.springframework.org/schema/websocket/spring-websocket.xsd">
<websocket:handlers>
<websocket:mapping path="/handler" handler="cubaglevt_WebSocketServer"/>
<websocket:sockjs/>
</websocket:handlers>
<bean class="org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean">
<property name="maxTextMessageBufferSize" value="281920"/>
<property name="maxBinaryMessageBufferSize" value="281920"/>
</bean>
</beans>
-
I create class UiNotificationEvent
in global project
import com.haulmont.addon.globalevents.GlobalApplicationEvent;
import com.haulmont.addon.globalevents.GlobalUiEvent;
import com.haulmont.cuba.security.global.UserSession;
public class UiNotificationEvent extends GlobalApplicationEvent implements GlobalUiEvent {
private static final long serialVersionUID = 7852612799484215742L;
private String message;
private UserSession userSession;
private NotyficationEvent type;
public UiNotificationEvent(Object source, String message, UserSession userSession, NotyficationEvent type) {
super(source);
this.message = message;
this.userSession = userSession;
this.type = type;
}
public String getMessage() {
return message;
}
public String getMessageForSession(UserSession session) {
if (session.getId().equals(userSession.getId()))
return getMessage();
else
return null;
}
public UserSession getUserSession() {
return userSession;
}
public NotyficationEvent getNotyficationType() {
return type;
}
}
3 Next I create bean and invoke UiNotificationEvent
e.g
UserSession userSession = userSessionSource.getUserSession();
events.publish(new UiNotificationEvent(userSession.getUser(), getChangeStatusAllowedMessage(), userSession,
NotyficationEvent.TRAY));
-
In main window I catch event like below
@Order(15)
@EventListener
protected void showNotification(UiNotificationEvent event) {
UserSession userSession = userSessionSource.getUserSession();
if (userSession.getId().equals(event.getUserSession().getId())) {
NotyficationEvent type = event.getNotyficationType();
if (type.equals(NotyficationEvent.TRAY))
showNotification(event.getMessage(), NotificationType.TRAY);
else if (type.equals(NotyficationEvent.ERROR))
showNotification(event.getMessage(), NotificationType.ERROR);
else if (type.equals(NotyficationEvent.WARM))
showNotification(event.getMessage(), NotificationType.WARNING);
else
showNotification(event.getMessage(), NotificationType.HUMANIZED);
}
}
I see I have’t method getSource
in UiNotificationEvent
. Is it necessary ?
> public getSource(){
> return super.getSource();
> ```
Hi
Log when cuba.useLocalServiceInvocation=true below
2019-07-09 18:24:18.259 DEBUG [http-nio-8080-exec-7/app-core/admin] com.haulmont.addon.globalevents.core.WebSocketServer - Sending com.company.erp.service.events.UiNotificationEvent[source=com.haulmont.cuba.security.entity.User-60885987-1b61-4247-94c7-dff348347f93 [detached]] to {WebSocketServerSockJsSession[id=188ec88a20254b1faa50b72713636bd0]=true}
2019-07-09 18:24:18.259 DEBUG [http-nio-8080-exec-7/app-core/admin] com.haulmont.addon.globalevents.core.WebSocketServer - Sending message TextMessage payload=[rO0ABXNyAD..], byteCount=19624, last=true] to WebSocketServerSockJsSession[id=188ec88a20254b1faa50b72713636bd0]
2019-07-09 18:24:18.274 INFO [http-nio-8080-exec-1] com.haulmont.addon.globalevents.core.WebSocketServer - Closed session WebSocketServerSockJsSession[id=188ec88a20254b1faa50b72713636bd0] with status CloseStatus[code=1009, reason=The decoded text message was too big for the output buffer and the endpoint does not support partial messages]
2019-07-09 18:24:18.321 INFO [WebSocketClient-AsyncIO-1] com.haulmont.addon.globalevents.transport.AbstractWebSocketClient - Closed WebSocketClientSockJsSession[id='188ec88a20254b1faa50b72713636bd0, url=http://localhost:8080/app-core/cubaglevt-ws/handler]
2019-07-09 18:24:18.337 DEBUG [http-nio-8080-exec-2/app-core/admin] com.haulmont.cuba.core.app.RdbmsStore - loadList: metaClass=erp$Documents, view=com.company.erp.entity.documents.Documents/documents-view, query=select e from erp$Documents e where (e.docdate >= :component_dateFrom and e.docdate <= :component_dateTo and e.ledger.id = :component_ledger and e.department.id = :component_department) order by e.entrydate, max=50
Log when cuba.useLocalServiceInvocation=false below
com.company.erp.entity.documents.DocumentSpecyfication-28702 [new], com.company.erp.entity.documents.DocumentSpecyfication-28703 [new], com.company.erp.entity.documents.DocumentsDescription-33702 [new]], removeInstances=[]
2019-07-09 19:03:45.519 DEBUG [http-nio-8080-exec-2/app-core/admin] com.haulmont.cuba.core.app.RdbmsStore - load: metaClass=erp$Customers, id=null, view=com.company.erp.entity.customers.Customers/customers-view
2019-07-09 19:03:45.550 DEBUG [http-nio-8080-exec-5/app-core/admin] com.haulmont.cuba.core.app.RdbmsStore - load: metaClass=erp$PaymentsForm, id=null, view=com.company.erp.entity.customers.PaymentsForm/_base
2019-07-09 19:03:45.644 DEBUG [http-nio-8080-exec-3/app-core/admin] com.haulmont.cuba.core.app.RdbmsStore - load: metaClass=erp$Documents, id=38302, view=com.company.erp.entity.documents.Documents/documents-view
2019-07-09 19:03:45.722 DEBUG [http-nio-8080-exec-10/app-core/admin] com.haulmont.addon.globalevents.core.WebSocketServer - Sending com.company.erp.service.events.UiNotificationEvent[source=com.haulmont.cuba.security.entity.User-60885987-1b61-4247-94c7-dff348347f93 [detached]] to {}
2019-07-09 19:03:45.753 DEBUG [http-nio-8080-exec-9/app-core/admin] com.haulmont.cuba.core.app.RdbmsStore - loadList: metaClass=erp$Documents, view=com.company.erp.entity.documents.Documents/documents-view, query=select e from erp$Documents e where (e.docdate >= :component_dateFrom and e.docdate <= :component_dateTo and e.ledger.id = :component_ledger and e.department.id = :component_department) order by e.entrydate, max=50
strange log files, it supposes to be resulting in opposite logs, cuba.userLocalService Invocation=false should have WebSocket on it.
Anyway, do you sure only send String message? From your code above I saw you try to send data UserSession Object
Yes I publish more information and sesion too. I need this parametr because in other way notification is send for all session.
UserSession userSession = userSessionSource.getUserSession();
events.publish(new UiNotificationEvent(userSession.getUser(), getChangeStatusAllowedMessage(), userSession,
NotyficationEvent.TRAY));
Ok I try it. Can I use for this variable source?
well in my case I’m not changing variable resource at all, Simply overide it as it is ,from parent Class
so how is your websocket going ?
Hi
I haven’t time for see about this problem this week. I figure then I have to add log in service and web leayer. Maybe this help me resolve problem.
Andrzej