mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 12:17:41 +08:00
PL-10709 VaadinSession init / destroy application events
This commit is contained in:
parent
23eb4eb881
commit
cedd803889
@ -18,15 +18,14 @@
|
||||
package com.haulmont.cuba.web.sys;
|
||||
|
||||
import com.google.common.hash.HashCode;
|
||||
import com.haulmont.cuba.core.global.AppBeans;
|
||||
import com.haulmont.cuba.core.global.Configuration;
|
||||
import com.haulmont.cuba.core.global.GlobalConfig;
|
||||
import com.haulmont.cuba.core.global.Messages;
|
||||
import com.haulmont.cuba.core.global.*;
|
||||
import com.haulmont.cuba.core.sys.AppContext;
|
||||
import com.haulmont.cuba.security.global.UserSession;
|
||||
import com.haulmont.cuba.web.App;
|
||||
import com.haulmont.cuba.web.WebConfig;
|
||||
import com.haulmont.cuba.web.auth.WebAuthConfig;
|
||||
import com.haulmont.cuba.web.sys.events.WebSessionDestroyedEvent;
|
||||
import com.haulmont.cuba.web.sys.events.WebSessionInitializedEvent;
|
||||
import com.haulmont.cuba.web.toolkit.ui.CubaFileUpload;
|
||||
import com.vaadin.server.*;
|
||||
import com.vaadin.server.communication.*;
|
||||
@ -69,10 +68,14 @@ public class CubaVaadinServletService extends VaadinServletService
|
||||
protected boolean testMode;
|
||||
protected boolean performanceTestMode;
|
||||
|
||||
protected Events events;
|
||||
|
||||
public CubaVaadinServletService(VaadinServlet servlet, DeploymentConfiguration deploymentConfiguration)
|
||||
throws ServiceException {
|
||||
super(servlet, deploymentConfiguration);
|
||||
|
||||
this.events = AppBeans.get(Events.NAME);
|
||||
|
||||
Configuration configuration = AppBeans.get(Configuration.NAME);
|
||||
webConfig = configuration.getConfig(WebConfig.class);
|
||||
webAuthConfig = configuration.getConfig(WebAuthConfig.class);
|
||||
@ -96,6 +99,8 @@ public class CubaVaadinServletService extends VaadinServletService
|
||||
|
||||
log.debug("HttpSession {} initialized, timeout={}sec",
|
||||
httpSession, wrappedSession.getMaxInactiveInterval());
|
||||
|
||||
events.publish(new WebSessionInitializedEvent(event.getSession()));
|
||||
});
|
||||
|
||||
addSessionDestroyListener(event -> {
|
||||
@ -108,6 +113,8 @@ public class CubaVaadinServletService extends VaadinServletService
|
||||
if (app != null) {
|
||||
app.cleanupBackgroundTasks();
|
||||
}
|
||||
|
||||
events.publish(new WebSessionDestroyedEvent(event.getSession()));
|
||||
});
|
||||
|
||||
setSystemMessagesProvider(systemMessagesInfo -> {
|
||||
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2018 Haulmont.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.haulmont.cuba.web.sys.events;
|
||||
|
||||
import com.vaadin.server.VaadinSession;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* Event that is fired when HTTP session is expired.
|
||||
* <br>
|
||||
* There is no SecurityContext available in the thread.
|
||||
*/
|
||||
public class WebSessionDestroyedEvent extends ApplicationEvent {
|
||||
public WebSessionDestroyedEvent(VaadinSession source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VaadinSession getSource() {
|
||||
return (VaadinSession) super.getSource();
|
||||
}
|
||||
|
||||
public VaadinSession getSession() {
|
||||
return getSource();
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2018 Haulmont.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.haulmont.cuba.web.sys.events;
|
||||
|
||||
import com.vaadin.server.VaadinSession;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* Event that is fired on the first request processing of the VaadinSession.
|
||||
* <br>
|
||||
* There is no SecurityContext available in the thread.
|
||||
*/
|
||||
public class WebSessionInitializedEvent extends ApplicationEvent {
|
||||
public WebSessionInitializedEvent(VaadinSession source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VaadinSession getSource() {
|
||||
return (VaadinSession) super.getSource();
|
||||
}
|
||||
|
||||
public VaadinSession getSession() {
|
||||
return getSource();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user