DeploymentConfiguration configuration = CurrentInstance
.get(DeploymentConfiguration.class);
if (configuration == null) {
// Not in cache, try to find a VaadinSession to get it from
VaadinSession session = VaadinSession.getCurrent();
if (session == null) {
/*
* There's no current session, request or response when serving
* static resources, but there's still the current request
* maintained by AppliationRunnerServlet, and there's most
* likely also a HttpSession containing a VaadinSession for that
* request.
*/
HttpServletRequest currentRequest = request.get();
if (currentRequest != null) {
HttpSession httpSession = currentRequest.getSession(false);
if (httpSession != null) {
Map<Class<?>, CurrentInstance> oldCurrent = CurrentInstance
.setCurrent((VaadinSession) null);
try {
session = getService().findVaadinSession(
new VaadinServletRequest(currentRequest,
getService()));
} finally {
/*
* Clear some state set by findVaadinSession to
* avoid accidentally depending on it when coding on
* e.g. static request handling.
*/
CurrentInstance.restoreInstances(oldCurrent);
currentRequest.removeAttribute(VaadinSession.class
.getName());
}
}
}
}
if (session != null) {
String name = ApplicationRunnerServlet.class.getName()
+ ".deploymentConfiguration";
try {
session.lock();
configuration = (DeploymentConfiguration) session
.getAttribute(name);
if (configuration == null) {
Class<?> classToRun;
try {
classToRun = getClassToRun();
} catch (ClassNotFoundException e) {
/*
* This happens e.g. if the UI class defined in the
* URL is not found or if this servlet just serves
* static resources while there's some other servlet
* that serves the UI (e.g. when using /run-push/).
*/
return originalConfiguration;
}
CustomDeploymentConfiguration customDeploymentConfiguration = classToRun
.getAnnotation(CustomDeploymentConfiguration.class);
if (customDeploymentConfiguration != null) {
Properties initParameters = new Properties(
originalConfiguration.getInitParameters());
for (Conf entry : customDeploymentConfiguration
.value()) {
initParameters.put(entry.name(), entry.value());
}
configuration = new DefaultDeploymentConfiguration(
getClass(), initParameters);
} else {
configuration = originalConfiguration;
}
session.setAttribute(name, configuration);
}
} finally {
session.unlock();
}
CurrentInstance.set(DeploymentConfiguration.class,
configuration);