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.parship.roperty.ui.persistence.service.RopertyUiSession.java

License:Apache License

private static void invalidateAllCookies() {
    Cookie[] cookies = VaadinService.getCurrentRequest().getCookies();

    // Iterate to invalidate
    for (Cookie cookie : cookies) {
        if (cookie.getName().startsWith("ClouTree.")) {
            cookie.setValue(null);// ww w  .j  a va2s .  c o  m
            cookie.setMaxAge(0);
        }
    }
}

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

License:Apache License

private static void createCookie(String key, String value, int ttl) {
    Cookie cookie = new Cookie(key, value);
    cookie.setMaxAge(ttl);/* w  w w .ja v a2s.co m*/
    cookie.setPath(VaadinService.getCurrentRequest().getContextPath());
    VaadinService.getCurrentResponse().addCookie(cookie);
}

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

License:Apache License

private static Cookie getCookieByName(String name) {
    // Fetch all cookies from the request
    Cookie[] cookies = VaadinService.getCurrentRequest().getCookies();

    // Iterate to find cookie by its name
    for (Cookie cookie : cookies) {
        if (name.equals(cookie.getName())) {
            return cookie;
        }//  www .j  a v a 2 s.  c om
    }
    return null;
}

From source file:com.peergreen.webconsole.core.vaadin7.BaseUI.java

License:Open Source License

private Cookie getCookieByName(String name) {
    // Fetch all cookies from the request
    Cookie[] cookies = VaadinService.getCurrentRequest().getCookies();

    // Iterate to find cookie by its name
    for (Cookie cookie : cookies) {
        if (name.equals(cookie.getName())) {
            return cookie;
        }/*from   www  .ja  va 2 s  . c o m*/
    }

    return null;
}

From source file:com.selzlein.lojavirtual.vaadin.core.LspsUI.java

License:Open Source License

/**
 * Sets theme for UI and then refreshes page to propagate the change correctly.
 * <p></p>//from ww w. j  a va 2  s  .  c  o m
 * If the page is not reloaded and the theme metrics changes, all Vaadin components will have trouble recomputing its sizes
 * (e.g. table).
 * @param theme
 */
public void setThemeAndReload(String theme) {
    log.info("Setting theme to " + theme);
    this.getUser().setSetting("theme", theme);
    VaadinService.getCurrentRequest().getWrappedSession().setAttribute("theme", theme);
    storeThemeInStorage(theme);
    JavaScript.getCurrent().execute("" + "window.location.reload();" + "");
}

From source file:com.wcs.wcslib.vaadin.widget.recaptcha.ReCaptcha.java

License:Apache License

/**
 * Validates the answer with server-side ReCaptcha api.
 * When the answer is empty returns false.
 * When the answer is valid, this method will return true for the first time only.
 * When the answer is invalid, you have to reload to get a new chance to pass.
 * This behavior comes from ReCaptcha.// w w  w. ja  v a2 s  . c o  m
 * Recaptcha4j used for handling the api.
 *
 * @return valid, or not
 */
public boolean validate() {
    if (isEmpty()) {
        return false;
    }
    String remoteAddr = VaadinService.getCurrentRequest().getRemoteAddr();
    ReCaptchaResponse reCaptchaResponse = getRecaptcha4j().checkAnswer(remoteAddr, challenge, response);
    return reCaptchaResponse.isValid();
}

From source file:de.kaiserpfalzEdv.vaadin.VaadinCurrentUserStore.java

License:Apache License

private static WrappedSession getCurrentSession() {
    VaadinRequest request = VaadinService.getCurrentRequest();
    if (request == null) {
        throw new IllegalStateException("No request bound to current thread");
    }/*from   www.  j  a  v a2  s . c om*/
    return request.getWrappedSession();
}

From source file:de.metas.procurement.webui.LoggingConfiguration.java

License:Open Source License

public void updateMDC() {
    ////w  w  w . ja  v a  2s. c om
    // Remote address
    try {
        final VaadinRequest vaadinRequest = VaadinService.getCurrentRequest();
        if (vaadinRequest != null) {
            final String remoteAddr = vaadinRequest.getRemoteAddr();
            MDC.put(MDC_Param_RemoteAddr, remoteAddr);
        }
    } catch (final Exception e) {
        e.printStackTrace();
        MDC.put(MDC_Param_RemoteAddr, "?");
    }

    //
    // LoggedUser
    try {
        final MFSession mfSession = MFProcurementUI.getCurrentMFSession();
        if (mfSession != null) {
            final User user = mfSession.getUser();
            if (user != null) {
                final String email = user.getEmail();
                if (email != null) {
                    MDC.put(MDC_Param_LoggedUser, email);
                }
            }
        }

    } catch (final Exception e) {
        e.printStackTrace();
        MDC.put(MDC_Param_LoggedUser, "?");
    }

    //
    // UserAgent
    try {
        final Page page = Page.getCurrent();
        if (page != null) {
            final WebBrowser webBrowser = page.getWebBrowser();
            if (webBrowser != null) {
                final String userAgent = webBrowser.getBrowserApplication();
                MDC.put(MDC_Param_UserAgent, userAgent);
            }
        }
    } catch (final Exception e) {
        e.printStackTrace();
        MDC.put(MDC_Param_UserAgent, "?");
    }

    //
    // SessionId
    try {
        final VaadinSession session = VaadinSession.getCurrent();
        if (session != null) {
            final int sessionId = System.identityHashCode(session);
            MDC.put(MDC_Param_SessionId, Integer.toString(sessionId));
        }
    } catch (final Exception e) {
        e.printStackTrace();
        MDC.put(MDC_Param_SessionId, "?");
    }

    //
    // UI Id
    try {
        final UI ui = UI.getCurrent();
        if (ui != null) {
            final int uiId = ui.getUIId();
            MDC.put(MDC_Param_UIId, Integer.toString(uiId));
        }
    } catch (final Exception e) {
        e.printStackTrace();
        MDC.put(MDC_Param_UIId, "?");
    }
}

From source file:de.metas.procurement.webui.service.impl.LoginRememberMeService.java

License:Open Source License

private Cookie getRememberMeCookie() {
    final VaadinRequest vaadinRequest = VaadinService.getCurrentRequest();
    if (vaadinRequest == null) {
        logger.warn(//from w ww.j  av  a2  s . co m
                "Could not get the VaadinRequest. It might be that we are called from a websocket connection.");
        return null;
    }

    //
    // Get the remember me cookie
    final Cookie[] cookies = vaadinRequest.getCookies();
    if (cookies == null) {
        return null;
    }

    for (final Cookie cookie : cookies) {
        if (COOKIENAME_RememberMe.equals(cookie.getName())) {
            return cookie;
        }
    }

    return null;
}

From source file:de.metas.ui.web.base.util.impl.HttpSessionProvider.java

License:Open Source License

@Override
public HttpServletRequest getCurrentRequest() {
    final VaadinRequest request = VaadinService.getCurrentRequest();
    if (request instanceof VaadinServletRequest) {
        return (VaadinServletRequest) request;
    } else {/*  w  w  w. j a va2 s  .  c  om*/
        throw new AdempiereException("Invalid request: " + request);
    }
}