import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
+import com.vaadin.util.CurrentInstance;
+
/**
* A generic request to the server, wrapping a more specific request type, e.g.
* HttpServletReqest or PortletRequest.
*/
public Enumeration<String> getHeaders(String name);
+ /**
+ * Gets the currently processed Vaadin request. The current request is
+ * automatically defined when the request is started. The current request
+ * can not be used in e.g. background threads because of the way server
+ * implementations reuse request instances.
+ *
+ * @return the current Vaadin request instance if available, otherwise
+ * <code>null</code>
+ * @since 8.1
+ */
+ public static VaadinRequest getCurrent() {
+ return CurrentInstance.get(VaadinRequest.class);
+ }
}
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
+import com.vaadin.util.CurrentInstance;
+
/**
* A generic response from the server, wrapping a more specific response type,
* e.g. HttpServletResponse or PortletResponse.
* @since 7.3.8
*/
public void setContentLength(int len);
+
+ /**
+ * Gets the currently processed Vaadin response. The current response is
+ * automatically defined when the request is started. The current response
+ * can not be used in e.g. background threads because of the way server
+ * implementations reuse response instances.
+ *
+ * @return the current Vaadin response instance if available, otherwise
+ * <code>null</code>
+ * @since 8.1
+ */
+ public static VaadinResponse getCurrent() {
+ return CurrentInstance.get(VaadinResponse.class);
+ }
}
* @see #setCurrentInstances(VaadinRequest, VaadinResponse)
*/
public static VaadinRequest getCurrentRequest() {
- return CurrentInstance.get(VaadinRequest.class);
+ return VaadinRequest.getCurrent();
}
/**
* @see #setCurrentInstances(VaadinRequest, VaadinResponse)
*/
public static VaadinResponse getCurrentResponse() {
- return CurrentInstance.get(VaadinResponse.class);
+ return VaadinResponse.getCurrent();
}
/**
*/
private int getUidlRequestTimeout(VaadinSession session) {
return getDeploymentConfiguration().isCloseIdleSessions()
- ? session.getSession().getMaxInactiveInterval() : -1;
+ ? session.getSession().getMaxInactiveInterval()
+ : -1;
}
/**
/**
* Returns whether the given session is active or whether it can be closed.
* <p>
- * A session is active if and only if its {@link VaadinSession#getState()} returns {@link State#OPEN}
- * and {@link #getUidlRequestTimeout(VaadinSession) getUidlRequestTimeout}
- * is negative or has not yet expired.
+ * A session is active if and only if its {@link VaadinSession#getState()}
+ * returns {@link State#OPEN} and
+ * {@link #getUidlRequestTimeout(VaadinSession) getUidlRequestTimeout} is
+ * negative or has not yet expired.
*
* @param session
* The session whose status to check
* <p>
* The framework collects filters from the {@link SessionInitEvent} where
* session init listeners can add them. This method is called with the
- * combined list to optionally modify it, and the result is then stored
- * by the caller as the final list to use.
+ * combined list to optionally modify it, and the result is then stored by
+ * the caller as the final list to use.
* <p>
* The filters are called in the order the session init listeners are
* called, which is undefined. If you need a specific order, you can
public VaadinServletService getService() {
return vaadinService;
}
+
+ /**
+ * Gets the currently processed Vaadin servlet request. The current request
+ * is automatically defined when the request is started. The current request
+ * can not be used in e.g. background threads because of the way server
+ * implementations reuse request instances.
+ *
+ *
+ * @return the current Vaadin servlet request instance if available,
+ * otherwise <code>null</code>
+ * @since 8.1
+ */
+ public static VaadinServletRequest getCurrent() {
+ VaadinRequest currentRequest = VaadinRequest.getCurrent();
+ if (currentRequest instanceof VaadinServletRequest) {
+ return (VaadinServletRequest) currentRequest;
+ } else {
+ return null;
+ }
+ }
+
}
public VaadinServletService getService() {
return vaadinService;
}
+
+ /**
+ * Gets the currently processed Vaadin servlet response. The current
+ * response is automatically defined when the request is started. The
+ * current response can not be used in e.g. background threads because of
+ * the way server implementations reuse response instances.
+ *
+ * @return the current Vaadin servlet response instance if available,
+ * otherwise <code>null</code>
+ * @since 8.1
+ */
+ public static VaadinServletResponse getCurrent() {
+ VaadinResponse currentResponse = VaadinResponse.getCurrent();
+ if (currentResponse instanceof VaadinServletResponse) {
+ return (VaadinServletResponse) currentResponse;
+ } else {
+ return null;
+ }
+ }
+
}
}
public static HttpServletRequest getCurrentServletRequest() {
- VaadinRequest currentRequest = VaadinService.getCurrentRequest();
- if (currentRequest instanceof VaadinServletRequest) {
- return (VaadinServletRequest) currentRequest;
- } else {
- return null;
- }
+ return VaadinServletRequest.getCurrent();
}
public static VaadinServletResponse getCurrentResponse() {
- return (VaadinServletResponse) VaadinService.getCurrentResponse();
+ return VaadinServletResponse.getCurrent();
}
@Override