@Override
public void init(PortletConfig config) throws PortletException {
CurrentInstance.clearAll();
- setCurrent(this);
super.init(config);
Properties initParameters = new Properties();
PortletResponse response) throws PortletException, IOException {
CurrentInstance.clearAll();
- setCurrent(this);
try {
getService().handleRequest(createVaadinRequest(request),
createVaadinResponse(response));
* portlet is defined (see {@link InheritableThreadLocal}). In other cases,
* (e.g. from background threads started in some other way), the current
* portlet is not automatically defined.
+ * <p>
+ * The current portlet is derived from the current service using
+ * {@link VaadinService#getCurrent()}
*
* @return the current vaadin portlet instance if available, otherwise
* <code>null</code>
*
- * @see #setCurrent(VaadinPortlet)
- *
* @since 7.0
*/
public static VaadinPortlet getCurrent() {
- return CurrentInstance.get(VaadinPortlet.class);
- }
-
- /**
- * Sets the current Vaadin portlet. This method is used by the framework to
- * set the current portlet whenever a new request is processed and it is
- * cleared when the request has been processed.
- * <p>
- * The application developer can also use this method to define the current
- * portlet outside the normal request handling, e.g. when initiating custom
- * background threads.
- * </p>
- *
- * @param portlet
- * the Vaadin portlet to register as the current portlet
- *
- * @see #getCurrent()
- * @see InheritableThreadLocal
- */
- public static void setCurrent(VaadinPortlet portlet) {
- CurrentInstance.setInheritable(VaadinPortlet.class, portlet);
+ VaadinService vaadinService = CurrentInstance.get(VaadinService.class);
+ if (vaadinService instanceof VaadinPortletService) {
+ VaadinPortletService vps = (VaadinPortletService) vaadinService;
+ return vps.getPortlet();
+ } else {
+ return null;
+ }
}
}
public void init(javax.servlet.ServletConfig servletConfig)
throws ServletException {
CurrentInstance.clearAll();
- setCurrent(this);
super.init(servletConfig);
Properties initParameters = new Properties();
* servlet is defined (see {@link InheritableThreadLocal}). In other cases,
* (e.g. from background threads started in some other way), the current
* servlet is not automatically defined.
+ * <p>
+ * The current servlet is derived from the current service using
+ * {@link VaadinService#getCurrent()}
*
* @return the current Vaadin servlet instance if available, otherwise
* <code>null</code>
*
- * @see #setCurrent(VaadinServlet)
- *
* @since 7.0
*/
public static VaadinServlet getCurrent() {
- return CurrentInstance.get(VaadinServlet.class);
- }
-
- /**
- * Sets the current Vaadin servlet. This method is used by the framework to
- * set the current servlet whenever a new request is processed and it is
- * cleared when the request has been processed.
- * <p>
- * The application developer can also use this method to define the current
- * servlet outside the normal request handling, e.g. when initiating custom
- * background threads.
- * </p>
- *
- * @param servlet
- * the Vaadin servlet to register as the current servlet
- *
- * @see #getCurrent()
- * @see InheritableThreadLocal
- */
- public static void setCurrent(VaadinServlet servlet) {
- CurrentInstance.setInheritable(VaadinServlet.class, servlet);
+ VaadinService vaadinService = CurrentInstance.get(VaadinService.class);
+ if (vaadinService instanceof VaadinServletService) {
+ VaadinServletService vss = (VaadinServletService) vaadinService;
+ return vss.getServlet();
+ } else {
+ return null;
+ }
}
protected DeploymentConfiguration createDeploymentConfiguration(
return;
}
CurrentInstance.clearAll();
- setCurrent(this);
VaadinServletRequest vaadinRequest = createVaadinRequest(request);
VaadinServletResponse vaadinResponse = createVaadinResponse(response);
}
if (isStaticResourceRequest(request)) {
- serveStaticResources(request, response);
- return;
+ // Define current servlet and service, but no request and response
+ getService().setCurrentInstances(null, null);
+ try {
+ serveStaticResources(request, response);
+ return;
+ } finally {
+ CurrentInstance.clearAll();
+ }
}
try {
getService().handleRequest(vaadinRequest, vaadinResponse);
import java.util.Map.Entry;
import com.vaadin.server.VaadinPortlet;
-import com.vaadin.server.VaadinPortletService;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinResponse;
import com.vaadin.server.VaadinService;
import com.vaadin.server.VaadinServlet;
-import com.vaadin.server.VaadinServletService;
import com.vaadin.server.VaadinSession;
import com.vaadin.ui.UI;
private final Object instance;
private final boolean inheritable;
- private static boolean portletAvailable = false;
- {
- try {
- /*
- * VaadinPortlet depends on portlet API which is available only if
- * running in a portal.
- */
- portletAvailable = (VaadinPortlet.class.getName() != null);
- } catch (Throwable t) {
- }
- }
-
private static InheritableThreadLocal<Map<Class<?>, CurrentInstance>> instances = new InheritableThreadLocal<Map<Class<?>, CurrentInstance>>() {
@Override
protected Map<Class<?>, CurrentInstance> childValue(
VaadinSession.setCurrent(session);
VaadinService.setCurrent(service);
- if (service instanceof VaadinServletService) {
- old.put(VaadinServlet.class,
- new CurrentInstance(VaadinServlet.getCurrent(), true));
- VaadinServlet.setCurrent(((VaadinServletService) service)
- .getServlet());
- } else if (portletAvailable && service instanceof VaadinPortletService) {
- old.put(VaadinPortlet.class,
- new CurrentInstance(VaadinPortlet.getCurrent(), true));
- VaadinPortlet.setCurrent(((VaadinPortletService) service)
- .getPortlet());
- }
-
return old;
}
}