}
@Override
- protected VaadinPortletSession createApplication(PortletRequest request)
- throws PortletException {
- VaadinPortletSession application = super.createApplication(request);
+ protected void onVaadinSessionStarted(WrappedPortletRequest request,
+ VaadinPortletSession session) throws PortletException {
+ if (shouldCreateApplication(request)) {
+ // Must set current before running init()
+ VaadinSession.setCurrent(session);
+
+ // XXX Must update details here so they are available in init.
+ session.getBrowser().updateRequestDetails(request);
- // Must set current before running init()
- VaadinSession.setCurrent(application);
+ Application legacyApplication = getNewApplication(request
+ .getPortletRequest());
+ legacyApplication.doInit();
+ session.addUIProvider(legacyApplication);
+ }
- Application legacyApplication = getNewApplication(request);
- legacyApplication.doInit();
- application.addUIProvider(legacyApplication);
+ super.onVaadinSessionStarted(request, session);
+ }
- return application;
+ protected boolean shouldCreateApplication(WrappedPortletRequest request) {
+ return true;
}
}
}
}
- @Override
- protected VaadinServletSession createApplication(HttpServletRequest request)
+ protected boolean shouldCreateApplication(WrappedHttpServletRequest request)
throws ServletException {
- VaadinServletSession application = super.createApplication(request);
+ return true;
+ }
+
+ @Override
+ protected void onVaadinSessionStarted(WrappedHttpServletRequest request,
+ VaadinServletSession session) throws ServletException {
+
+ if (shouldCreateApplication(request)) {
+ // Must set current before running init()
+ VaadinSession.setCurrent(session);
- // Must set current before running init()
- VaadinSession.setCurrent(application);
+ // XXX Must update details here so they are available in init.
+ session.getBrowser().updateRequestDetails(request);
- Application legacyApplication = getNewApplication(request);
- legacyApplication.doInit();
- application.addUIProvider(legacyApplication);
+ Application legacyApplication = getNewApplication(request);
+ legacyApplication.doInit();
+ session.addUIProvider(legacyApplication);
+ }
- return application;
+ super.onVaadinSessionStarted(request, session);
}
}
if (restartApplication) {
closeApplication(application, request.getPortletSession(false));
- return createAndRegisterApplication(request);
+ return createAndRegisterApplication(wrappedRequest);
} else if (closeApplication) {
closeApplication(application, request.getPortletSession(false));
return null;
// No existing application was found
if (requestCanCreateApplication) {
- return createAndRegisterApplication(request);
+ return createAndRegisterApplication(wrappedRequest);
} else {
throw new SessionExpiredException();
}
application.removeFromSession();
}
- private VaadinSession createAndRegisterApplication(PortletRequest request)
- throws PortletException {
- VaadinSession newApplication = createApplication(request);
+ private VaadinSession createAndRegisterApplication(
+ WrappedPortletRequest request) throws PortletException {
+ VaadinPortletSession newApplication = createApplication();
try {
ServletPortletHelper.checkUiProviders(newApplication);
}
newApplication.storeInSession(new WrappedPortletSession(request
- .getPortletSession()));
+ .getPortletRequest().getPortletSession()));
Locale locale = request.getLocale();
newApplication.setLocale(locale);
newApplication.start(new SessionStartEvent(null, getVaadinService()
.getDeploymentConfiguration(), new PortletCommunicationManager(
newApplication)));
- addonContext.fireApplicationStarted(newApplication);
+ onVaadinSessionStarted(request, newApplication);
return newApplication;
}
- protected VaadinPortletSession createApplication(PortletRequest request)
- throws PortletException {
+ protected void onVaadinSessionStarted(WrappedPortletRequest request,
+ VaadinPortletSession session) throws PortletException {
+ addonContext.fireApplicationStarted(session);
+ try {
+ ServletPortletHelper.checkUiProviders(session);
+ } catch (ApplicationClassException e) {
+ throw new PortletException(e);
+ }
+ }
+
+ private VaadinPortletSession createApplication() throws PortletException {
VaadinPortletSession application = new VaadinPortletSession();
try {
* @throws ServletException
* @throws SessionExpiredException
*/
- private VaadinSession findApplicationInstance(HttpServletRequest request,
- RequestType requestType) throws MalformedURLException,
- ServletException, SessionExpiredException {
+ private VaadinSession findApplicationInstance(
+ WrappedHttpServletRequest request, RequestType requestType)
+ throws MalformedURLException, ServletException,
+ SessionExpiredException {
boolean requestCanCreateApplication = requestCanCreateApplication(
request, requestType);
}
private VaadinSession createAndRegisterApplication(
- HttpServletRequest request) throws ServletException,
+ WrappedHttpServletRequest request) throws ServletException,
MalformedURLException {
- VaadinSession newApplication = createApplication(request);
+ VaadinServletSession session = createVaadinSession(request);
- try {
- ServletPortletHelper.checkUiProviders(newApplication);
- } catch (ApplicationClassException e) {
- throw new ServletException(e);
- }
-
- newApplication.storeInSession(new WrappedHttpSession(request
- .getSession()));
+ session.storeInSession(new WrappedHttpSession(request.getSession()));
final URL applicationUrl = getApplicationUrl(request);
// Initial locale comes from the request
Locale locale = request.getLocale();
- newApplication.setLocale(locale);
- newApplication.start(new SessionStartEvent(applicationUrl,
- getVaadinService().getDeploymentConfiguration(),
- createCommunicationManager(newApplication)));
+ session.setLocale(locale);
+ session.start(new SessionStartEvent(applicationUrl, getVaadinService()
+ .getDeploymentConfiguration(),
+ createCommunicationManager(session)));
- addonContext.fireApplicationStarted(newApplication);
+ onVaadinSessionStarted(request, session);
- return newApplication;
+ return session;
+ }
+
+ protected void onVaadinSessionStarted(WrappedHttpServletRequest request,
+ VaadinServletSession session) throws ServletException {
+ addonContext.fireApplicationStarted(session);
+
+ try {
+ ServletPortletHelper.checkUiProviders(session);
+ } catch (ApplicationClassException e) {
+ throw new ServletException(e);
+ }
}
/**
}
/**
- * Creates a new application and registers it into WebApplicationContext
- * (aka session). This is not meant to be overridden. Override
- * getNewApplication to create the application instance in a custom way.
+ * Creates a new vaadin session.
*
* @param request
* @return
* @throws ServletException
* @throws MalformedURLException
*/
- protected VaadinServletSession createApplication(HttpServletRequest request)
+ private VaadinServletSession createVaadinSession(HttpServletRequest request)
throws ServletException {
- VaadinServletSession newApplication = new VaadinServletSession();
+ VaadinServletSession session = new VaadinServletSession();
try {
- ServletPortletHelper.initDefaultUIProvider(newApplication,
+ ServletPortletHelper.initDefaultUIProvider(session,
getVaadinService());
} catch (ApplicationClassException e) {
throw new ServletException(e);
}
- return newApplication;
+ return session;
}
private void handleServiceException(WrappedHttpServletRequest request,
}
@Override
- protected VaadinServletSession createApplication(HttpServletRequest request)
+ protected boolean shouldCreateApplication(WrappedHttpServletRequest request)
throws ServletException {
+ try {
+ return Application.class.isAssignableFrom(getClassToRun());
+ } catch (ClassNotFoundException e) {
+ throw new ServletException(e);
+ }
+ }
+
+ @Override
+ protected void onVaadinSessionStarted(WrappedHttpServletRequest request,
+ VaadinServletSession session) throws ServletException {
try {
final Class<?> classToRun = getClassToRun();
if (UI.class.isAssignableFrom(classToRun)) {
- VaadinServletSession application = new VaadinServletSession();
- application.addUIProvider(new AbstractUIProvider() {
+ session.addUIProvider(new AbstractUIProvider() {
@Override
- public Class<? extends UI> getUIClass(
- WrappedRequest request) {
+ public Class<? extends UI> getUIClass(WrappedRequest request) {
return (Class<? extends UI>) classToRun;
}
});
- return application;
} else if (Application.class.isAssignableFrom(classToRun)) {
- return super.createApplication(request);
+ // Avoid using own UIProvider for legacy Application
} else if (UIProvider.class.isAssignableFrom(classToRun)) {
- VaadinServletSession application = new VaadinServletSession();
- application
- .addUIProvider((UIProvider) classToRun.newInstance());
- return application;
+ session.addUIProvider((UIProvider) classToRun.newInstance());
} else {
throw new ServletException(classToRun.getCanonicalName()
+ " is neither an Application nor a UI");
+ getApplicationRunnerApplicationClassName(request)));
}
+ super.onVaadinSessionStarted(request, session);
}
private String getApplicationRunnerApplicationClassName(