PL-7494 Configuration property for PUSH mode

This commit is contained in:
Yuriy Artamonov 2016-07-07 16:51:47 +04:00
parent aacb96cb26
commit 039dd5031a
2 changed files with 39 additions and 3 deletions

View File

@ -258,4 +258,18 @@ public interface WebConfig extends Config {
@Property("cuba.web.appLogMaxItemsCount")
@DefaultInt(10)
int getAppLogMaxItemsCount();
/**
* @return true if push should use long polling transport instead of websocket+xhr
*/
@Property("cuba.web.pushLongPolling")
@DefaultBoolean(value = false)
boolean getUsePushLongPolling();
/**
* @return true if push is enabled
*/
@Property("cuba.web.pushEnabled")
@DefaultBoolean(value = true)
boolean getPushEnabled();
}

View File

@ -25,6 +25,8 @@ import com.haulmont.cuba.web.App;
import com.haulmont.cuba.web.WebConfig;
import com.vaadin.server.DefaultUIProvider;
import com.vaadin.server.UICreateEvent;
import com.vaadin.shared.communication.PushMode;
import com.vaadin.shared.ui.ui.Transport;
import org.apache.commons.lang.StringUtils;
import javax.servlet.http.Cookie;
@ -33,15 +35,13 @@ import java.util.Set;
/**
* Custom provider for possible extension
*
*/
public class CubaUIProvider extends DefaultUIProvider {
protected Configuration configuration = AppBeans.get(Configuration.NAME);
@Override
public String getTheme(UICreateEvent event) {
// get theme from cookies before app ui initialized for smooth theme enabling
Configuration configuration = AppBeans.get(Configuration.NAME);
WebConfig webConfig = configuration.getConfig(WebConfig.class);
GlobalConfig globalConfig = configuration.getConfig(GlobalConfig.class);
@ -74,4 +74,26 @@ public class CubaUIProvider extends DefaultUIProvider {
}
return null;
}
@Override
public PushMode getPushMode(UICreateEvent event) {
WebConfig webConfig = configuration.getConfig(WebConfig.class);
if (!webConfig.getPushEnabled()) {
return PushMode.DISABLED;
}
return super.getPushMode(event);
}
@Override
public Transport getPushTransport(UICreateEvent event) {
WebConfig webConfig = configuration.getConfig(WebConfig.class);
if (webConfig.getUsePushLongPolling()) {
return Transport.LONG_POLLING;
}
return super.getPushTransport(event);
}
}