use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.
the class VaadinServletTest method resolveTranslation_for_servlet_with_path.
@Test
public void resolveTranslation_for_servlet_with_path() throws MalformedURLException {
request = Mockito.mock(VaadinServletRequest.class);
CurrentInstance.set(VaadinRequest.class, request);
DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
Mockito.when(((VaadinServletRequest) request).getServletPath()).thenReturn("/app/");
Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
Mockito.when(configuration.isProductionMode()).thenReturn(false);
Mockito.when(factory.getUriResolver(request)).thenReturn(vaadinUriResolver);
String path = "/src/foo";
String resolved = "./../src/bar";
Mockito.when(vaadinUriResolver.resolveVaadinUri(path)).thenReturn(resolved);
Mockito.when(vaadinUriResolver.resolveVaadinUri("/theme/foo")).thenReturn("./../theme/foo");
Mockito.when(context.getResource("/./theme/foo")).thenReturn(new URL("http://theme/foo"));
String urlTranslation = servlet.getUrlTranslation(new MyTheme(), path);
Assert.assertEquals("/theme/foo", urlTranslation);
}
use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.
the class WebJarServerTest method init.
@Before
public void init() throws Exception {
DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
Mockito.when(configuration.getDevelopmentFrontendPrefix()).thenReturn(Constants.FRONTEND_URL_DEV_DEFAULT);
VaadinServletService servletService = Mockito.mock(VaadinServletService.class);
ServletContext servletContext = Mockito.mock(ServletContext.class);
servlet = new VaadinServlet() {
@Override
protected VaadinServletService createServletService() throws ServletException, ServiceException {
return servletService;
}
@Override
public ServletContext getServletContext() {
return servletContext;
}
};
Mockito.when(servletService.getDeploymentConfiguration()).thenReturn(configuration);
Mockito.when(configuration.areWebJarsEnabled()).thenReturn(true);
servlet.init(Mockito.mock(ServletConfig.class));
Field webJarServerField = VaadinServlet.class.getDeclaredField("webJarServer");
webJarServerField.setAccessible(true);
webJarServer = (WebJarServer) webJarServerField.get(servlet);
// webJarServer = new WebJarServer(configuration);
// context = Mockito.mock(ServletContext.class);
Mockito.when(servletContext.getResource(GRID_WEBJAR)).thenReturn(new URL("http://localhost:8080" + GRID_DEPENDENCY));
}
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 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));
}
}
}
Aggregations