Example usage for com.vaadin.server VaadinService getCurrentRequest

List of usage examples for com.vaadin.server VaadinService getCurrentRequest

Introduction

In this page you can find the example usage for com.vaadin.server VaadinService getCurrentRequest.

Prototype

public static VaadinRequest getCurrentRequest() 

Source Link

Document

Gets the currently processed Vaadin request.

Usage

From source file:com.hybridbpm.ui.HybridbpmUI.java

License:Apache License

public void logout() {
    HazelcastServer.removeDashboardNotificationEventTopic(user.getId().toString(), notificationListenerId);
    HazelcastServer.getDashboardEventTopic().removeMessageListener(dashboardListenerId);
    user = null;//from  w ww.  j  av  a 2s  . co  m
    CookieManager.setCookie(COOKIENAME_USERNAME, null, VaadinService.getCurrentRequest().getContextPath());
    VaadinSession.getCurrent().close();
    getUI().getPage().setLocation(VaadinService.getCurrentRequest().getContextPath());
    VaadinService.getCurrentRequest().getWrappedSession().invalidate();
}

From source file:com.jee.client.JeeclientUI.java

@Override
protected void init(VaadinRequest request) {
    new Navigator(this, this);
    getNavigator().addView(LoginForm.NAME, LoginForm.class);
    getNavigator().addView(MainView.NAME, MainView.class);
    getNavigator().addViewChangeListener(new ViewChangeListener() {

        @Override/*from www .  j a va  2 s  .c o m*/
        public boolean beforeViewChange(ViewChangeEvent event) {
            // Check if a user has logged in
            boolean isLoggedIn = VaadinService.getCurrentRequest().getWrappedSession()
                    .getAttribute(USER_NAME_ATTRIBUTE_NAME) != null;// getSession().getAttribute(USER_NAME_ATTRIBUTE_NAME) != null;
            boolean isLoginView = event.getNewView() instanceof LoginForm;

            if (!isLoggedIn && !isLoginView) {
                // Redirect to login view always if a user has not yet
                // logged in
                getNavigator().navigateTo(LoginForm.NAME);
                return false;

            } else if (isLoggedIn && isLoginView) {
                // If someone tries to access to login view while logged in,
                // then cancel
                return false;
            }

            return true;
        }

        @Override
        public void afterViewChange(ViewChangeEvent event) {

        }
    });

    WrappedSession session = request.getWrappedSession();
    HttpSession httpSession = ((WrappedHttpSession) session).getHttpSession();
    ServletContext servletContext = httpSession.getServletContext();
    applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
    messageSource = (ReloadableResourceBundleMessageSource) applicationContext.getBean("resource");
    userAdminManager = (VoucheringManager) applicationContext.getBean("userAdminManager");
    WebUtil.absolutePath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
    this.getLoadingIndicatorConfiguration().setFirstDelay(500);
    this.getLoadingIndicatorConfiguration().setSecondDelay(30000);
    this.getLoadingIndicatorConfiguration().setThirdDelay(80000);
}

From source file:com.lst.deploymentautomation.vaadin.core.LspsUI.java

License:Open Source License

/**
 * Logs out the current user.//w  w w  .j a  va  2s  .c om
 */
public void logout() {
    //close current view so that detach() on given component is called
    navigateTo("");

    //redirect to logout page
    getPage().setLocation(VaadinService.getCurrentRequest().getContextPath() + "/logout.jsp");
}

From source file:com.lst.deploymentautomation.vaadin.core.LspsUI.java

License:Open Source License

/**
 * Sets theme for UI and then refreshes page to propagate the change.
 * @param theme/*w  ww.j a v  a  2s  .c o m*/
 */
@Override
public void setTheme(String theme) {
    this.getUser().setSetting("theme", theme);
    VaadinService.getCurrentRequest().getWrappedSession().setAttribute("theme", theme);
    // store theme in browser local storage, so if default theme is changed, next time
    // user will see his chosen theme even before login.. and refresh
    JavaScript.getCurrent()
            .execute("" + "var storage = window.localStorage;" + "if(typeof(Storage)!=='undefined')"
                    + "storage.setItem('deployment-automationlication-theme-name', '" + theme + "');"
                    + "window.location.reload();" + "");
}

From source file:com.lst.deploymentautomation.vaadin.util.Utils.java

License:Open Source License

/**
 * Logs the given exception. Stacktrace is logged on the FINER level, message from the exception is logged on the FINE level.
 * @param x/*from  www .jav a 2  s  .  c o m*/
 * @param msg
 * @param logger
 */
public static void log(Throwable x, String msg, Logger logger) {
    String cause = x.getMessage() == null ? x.toString() : x.getMessage();
    logger.error(msg + " (" + VaadinService.getCurrentRequest().getRemoteUser() + "): " + cause);
    logger.info("stacktrace", x);
}

From source file:com.mcparland.john.vaadin_mvn_arch.samples.authentication.CurrentUser.java

License:Apache License

private static VaadinRequest getCurrentRequest() {
    VaadinRequest request = VaadinService.getCurrentRequest();
    if (request == null) {
        throw new IllegalStateException("No request bound to current thread");
    }//  www .  j  av a  2  s . co m
    return request;
}

From source file:com.parship.roperty.ui.persistence.service.RopertyUiSession.java

License:Apache License

public static void login(User user, boolean rememberMe) {
    VaadinService.getCurrentRequest().getWrappedSession().setAttribute("user", user);
    setLoginCookies(user, rememberMe);//  ww  w.  ja v  a 2s. co  m
}

From source file:com.parship.roperty.ui.persistence.service.RopertyUiSession.java

License:Apache License

public static void logout() {
    VaadinService.getCurrentRequest().getWrappedSession().removeAttribute("user");
    invalidateLoginCookies();
}

From source file:com.parship.roperty.ui.persistence.service.RopertyUiSession.java

License:Apache License

public static boolean isLoggedIn() {
    User user = (User) VaadinService.getCurrentRequest().getWrappedSession().getAttribute("user");

    if (user != null) {
        return true;
    }/*  w ww  .j a  v a  2 s.  c  o  m*/

    Cookie cookie = getCookieByName("ClouTree.user");

    if (cookie != null && cookie.getValue() != null && cookie.getValue().equals("true")) {
        return true;
    }
    return false;

}

From source file:com.parship.roperty.ui.persistence.service.RopertyUiSession.java

License:Apache License

public static User getUser() {
    User user = (User) VaadinService.getCurrentRequest().getWrappedSession().getAttribute("user");

    if (user != null) {
        return user;
    }//w w w .  j  av a 2 s.  c om
    return null;
}