use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.
the class BootstrapHandler method getApplicationParameters.
private static JsonObject getApplicationParameters(VaadinRequest request, VaadinSession session) {
VaadinService vaadinService = session.getService();
DeploymentConfiguration deploymentConfiguration = session.getConfiguration();
final boolean productionMode = deploymentConfiguration.isProductionMode();
JsonObject appConfig = Json.createObject();
appConfig.put(ApplicationConstants.FRONTEND_URL_ES6, deploymentConfiguration.getEs6FrontendPrefix());
appConfig.put(ApplicationConstants.FRONTEND_URL_ES5, deploymentConfiguration.getEs5FrontendPrefix());
if (!productionMode) {
JsonObject versionInfo = Json.createObject();
versionInfo.put("vaadinVersion", Version.getFullVersion());
String atmosphereVersion = AtmospherePushConnection.getAtmosphereVersion();
if (atmosphereVersion != null) {
versionInfo.put("atmosphereVersion", atmosphereVersion);
}
appConfig.put("versionInfo", versionInfo);
}
// Use locale from session if set, else from the request
Locale locale = ServletHelper.findLocale(session, request);
// Get system messages
SystemMessages systemMessages = vaadinService.getSystemMessages(locale, request);
if (systemMessages != null) {
JsonObject sessExpMsg = Json.createObject();
putValueOrNull(sessExpMsg, CAPTION, systemMessages.getSessionExpiredCaption());
putValueOrNull(sessExpMsg, MESSAGE, systemMessages.getSessionExpiredMessage());
putValueOrNull(sessExpMsg, URL, systemMessages.getSessionExpiredURL());
appConfig.put("sessExpMsg", sessExpMsg);
}
String contextRoot = ServletHelper.getContextRootRelativePath(request) + "/";
appConfig.put(ApplicationConstants.CONTEXT_ROOT_URL, contextRoot);
if (!productionMode) {
appConfig.put("debug", true);
}
if (deploymentConfiguration.isRequestTiming()) {
appConfig.put("requestTiming", true);
}
appConfig.put("heartbeatInterval", deploymentConfiguration.getHeartbeatInterval());
boolean sendUrlsAsParameters = deploymentConfiguration.isSendUrlsAsParameters();
if (!sendUrlsAsParameters) {
appConfig.put("sendUrlsAsParameters", false);
}
return appConfig;
}
use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.
the class BootstrapHandler method createAndInitUI.
protected BootstrapContext createAndInitUI(Class<? extends UI> uiClass, VaadinRequest request, VaadinResponse response, VaadinSession session) {
UI ui = ReflectTools.createInstance(uiClass);
PushConfiguration pushConfiguration = ui.getPushConfiguration();
ui.getInternals().setSession(session);
ui.setLocale(session.getLocale());
BootstrapContext context = new BootstrapContext(request, response, session, ui);
Optional<Push> push = context.getPageConfigurationAnnotation(Push.class);
DeploymentConfiguration deploymentConfiguration = context.getSession().getService().getDeploymentConfiguration();
PushMode pushMode = push.map(Push::value).orElseGet(deploymentConfiguration::getPushMode);
pushConfiguration.setPushMode(pushMode);
pushConfiguration.setPushUrl(deploymentConfiguration.getPushURL());
push.map(Push::transport).ifPresent(pushConfiguration::setTransport);
// Set thread local here so it is available in init
UI.setCurrent(ui);
ui.doInit(request, session.getNextUIid());
session.addUI(ui);
// After init and adding UI to session fire init listeners.
session.getService().fireUIInitListeners(ui);
return context;
}
use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.
the class BootstrapHandler method appendWebComponentsPolyfills.
private static void appendWebComponentsPolyfills(Element head, BootstrapContext context) {
Optional<WebComponents> webComponents = AnnotationReader.getAnnotationFor(context.getUI().getClass(), WebComponents.class);
DeploymentConfiguration config = context.getSession().getConfiguration();
String webComponentsPolyfillBase = config.getWebComponentsPolyfillBase().orElse(null);
if (webComponentsPolyfillBase == null) {
return;
}
assert webComponentsPolyfillBase.endsWith("/");
boolean loadEs5Adapter = config.getBooleanProperty(Constants.LOAD_ES5_ADAPTERS, webComponents.map(WebComponents::loadEs5Adapter).orElse(true));
if (loadEs5Adapter && !context.getSession().getBrowser().isEs6Supported()) {
// This adapter is required since lots of our current customers use
// polymer-cli to transpile sources,
// this tool adds babel-helpers dependency into each file, see:
// https://github.com/Polymer/polymer-cli/blob/master/src/build/build.ts#L64
// and
// https://github.com/Polymer/polymer-cli/blob/master/src/build/optimize-streams.ts#L119
head.appendChild(createInlineJavaScriptElement(BABEL_HELPERS_JS));
}
head.appendChild(createJavaScriptElement(context.getUriResolver().resolveVaadinUri(webComponentsPolyfillBase + "webcomponents-loader.js"), false));
}
use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.
the class BundleFilterInitializer method serviceInit.
@Override
public void serviceInit(ServiceInitEvent event) {
DeploymentConfiguration deploymentConfiguration = event.getSource().getDeploymentConfiguration();
if (deploymentConfiguration.isProductionMode()) {
VaadinUriResolver es6ContextPathResolver = new VaadinUriResolver() {
@Override
protected String getContextRootUrl() {
return "/";
}
@Override
protected String getFrontendRootUrl() {
return deploymentConfiguration.getEs6FrontendPrefix();
}
};
Map<String, Set<String>> importsInBundles = readBundleDependencies(event, es6ContextPathResolver);
if (!importsInBundles.isEmpty()) {
if (importsInBundles.values().stream().noneMatch(importSet -> importSet.contains(BundleDependencyFilter.MAIN_BUNDLE_URL))) {
throw new IllegalArgumentException(String.format("Attempted to initialize BundleDependencyFilter with an " + "import to bundle mapping which does not contain the main bundle %s", BundleDependencyFilter.MAIN_BUNDLE_URL));
}
event.addDependencyFilter(new BundleDependencyFilter(importsInBundles));
}
}
}
use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.
the class CompositeTest method setup.
@Before
public void setup() {
compositeWithComponent = new CompositeWithComponent() {
@Override
public String toString() {
return "Composite";
}
};
layoutWithSingleComponentComposite = new TestLayout() {
@Override
public String toString() {
return "Layout";
}
};
layoutWithSingleComponentComposite.addComponent(compositeWithComponent);
((TracksAttachDetach) componentInsideLayoutInsideComposite).track();
compositeWithComponent.track();
layoutInsideComposite.track();
layoutWithSingleComponentComposite.track();
Assert.assertNull(VaadinService.getCurrent());
VaadinService service = Mockito.mock(VaadinService.class);
DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
Mockito.when(configuration.isProductionMode()).thenReturn(true);
Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
VaadinService.setCurrent(service);
}
Aggregations