Example usage for com.vaadin.server VaadinRequest getRemoteHost

List of usage examples for com.vaadin.server VaadinRequest getRemoteHost

Introduction

In this page you can find the example usage for com.vaadin.server VaadinRequest getRemoteHost.

Prototype

public String getRemoteHost();

Source Link

Document

Returns the fully qualified name of the client or the last proxy that sent the request.

Usage

From source file:com.mycollab.web.DesktopApplication.java

License:Open Source License

private String printRequest(VaadinRequest request) {
    StringBuilder requestInfo = new StringBuilder();
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String attr = headerNames.nextElement();
        requestInfo.append(attr + ": " + request.getHeader(attr)).append('\n');
    }//w ww . j  a  v a  2 s  .c  o m
    requestInfo.append("Subdomain: " + Utils.getSubDomain(request)).append('\n');
    requestInfo.append("Remote address: " + request.getRemoteAddr()).append('\n');
    requestInfo.append("Path info: " + request.getPathInfo()).append('\n');
    requestInfo.append("Remote host: " + request.getRemoteHost()).append('\n');
    return requestInfo.toString();
}

From source file:com.mycollab.web.DesktopApplication.java

License:Open Source License

private void handleException(VaadinRequest request, Throwable e) {
    IgnoreException ignoreException = getExceptionType(e, IgnoreException.class);
    if (ignoreException != null) {
        return;/*from  w  ww  .ja  va2  s.co m*/
    }

    DebugException debugException = getExceptionType(e, DebugException.class);
    if (debugException != null) {
        LOG.error("Debug error", e);
        return;
    }

    SessionExpireException sessionExpireException = getExceptionType(e, SessionExpireException.class);
    if (sessionExpireException != null) {
        Page.getCurrent().getJavaScript().execute("window.location.reload();");
        return;
    }

    UsageExceedBillingPlanException usageBillingException = getExceptionType(e,
            UsageExceedBillingPlanException.class);
    if (usageBillingException != null) {
        if (UserUIContext.isAdmin()) {
            ConfirmDialogExt.show(UI.getCurrent(),
                    UserUIContext.getMessage(GenericI18Enum.WINDOW_ATTENTION_TITLE, MyCollabUI.getSiteName()),
                    UserUIContext.getMessage(GenericI18Enum.EXCEED_BILLING_PLAN_MSG_FOR_ADMIN),
                    UserUIContext.getMessage(GenericI18Enum.BUTTON_YES),
                    UserUIContext.getMessage(GenericI18Enum.BUTTON_NO), confirmDialog -> {
                        if (confirmDialog.isConfirmed()) {
                            Collection<Window> windowsList = UI.getCurrent().getWindows();
                            for (Window window : windowsList) {
                                window.close();
                            }
                            EventBusFactory.getInstance().post(
                                    new ShellEvent.GotoUserAccountModule(this, new String[] { "billing" }));
                        }
                    });

        } else {
            NotificationUtil.showErrorNotification(
                    UserUIContext.getMessage(GenericI18Enum.EXCEED_BILLING_PLAN_MSG_FOR_USER));
        }
        return;
    }

    UserInvalidInputException invalidException = getExceptionType(e, UserInvalidInputException.class);
    if (invalidException != null) {
        NotificationUtil.showWarningNotification(UserUIContext
                .getMessage(GenericI18Enum.ERROR_USER_INPUT_MESSAGE, invalidException.getMessage()));
        return;
    }

    UnsupportedFeatureException unsupportedException = getExceptionType(e, UnsupportedFeatureException.class);
    if (unsupportedException != null) {
        NotificationUtil.showFeatureNotPresentInSubscription();
        return;
    }

    ResourceNotFoundException resourceNotFoundException = getExceptionType(e, ResourceNotFoundException.class);
    if (resourceNotFoundException != null) {
        NotificationUtil.showWarningNotification(UserUIContext.getMessage(ErrorI18nEnum.RESOURCE_NOT_FOUND));
        LOG.error("404", resourceNotFoundException);
        return;
    }

    SecureAccessException secureAccessException = getExceptionType(e, SecureAccessException.class);
    if (secureAccessException != null) {
        NotificationUtil.showWarningNotification("You can not access the specific resource");
        EventBusFactory.getInstance()
                .post(new ShellEvent.GotoUserAccountModule(this, new String[] { "preview" }));
        return;
    }

    for (Class systemEx : systemExceptions) {
        Exception ex = (Exception) getExceptionType(e, systemEx);
        if (ex != null) {
            ConfirmDialog dialog = ConfirmDialogExt.show(DesktopApplication.this,
                    UserUIContext.getMessage(GenericI18Enum.WINDOW_ERROR_TITLE, MyCollabUI.getSiteName()),
                    UserUIContext.getMessage(GenericI18Enum.ERROR_USER_SYSTEM_ERROR, ex.getMessage()),
                    UserUIContext.getMessage(GenericI18Enum.BUTTON_YES),
                    UserUIContext.getMessage(GenericI18Enum.BUTTON_NO), confirmDialog -> {
                    });
            Button okBtn = dialog.getOkButton();
            BrowserWindowOpener opener = new BrowserWindowOpener("http://support.mycollab.com");
            opener.extend(okBtn);
            return;
        }
    }

    IllegalStateException asyncNotSupport = getExceptionType(e, IllegalStateException.class);
    if (asyncNotSupport != null && asyncNotSupport.getMessage().contains("!asyncSupported")) {
        ConfirmDialog dialog = ConfirmDialogExt.show(DesktopApplication.this,
                UserUIContext.getMessage(GenericI18Enum.WINDOW_ERROR_TITLE, MyCollabUI.getSiteName()),
                UserUIContext.getMessage(ErrorI18nEnum.WEBSOCKET_NOT_SUPPORT),
                UserUIContext.getMessage(GenericI18Enum.BUTTON_YES),
                UserUIContext.getMessage(GenericI18Enum.BUTTON_NO), confirmDialog -> {
                });
        Button okBtn = dialog.getOkButton();
        BrowserWindowOpener opener = new BrowserWindowOpener("http://support.mycollab.com");
        opener.extend(okBtn);
        if (request != null) {
            String remoteAddress = request.getRemoteHost();
            if (remoteAddress != null) {
                if (!ipLists.contains(remoteAddress)) {
                    LOG.error("Async not supported: " + printRequest(request));
                    ipLists.add(remoteAddress);
                }
            }
        }
        return;
    }

    EofException eofException = getExceptionType(e, EofException.class);
    if (eofException != null) {
        return;
    }
    LOG.error("Error", e);
    ConfirmDialog dialog = ConfirmDialogExt.show(DesktopApplication.this,
            UserUIContext.getMessage(GenericI18Enum.WINDOW_ERROR_TITLE, MyCollabUI.getSiteName()),
            UserUIContext.getMessage(GenericI18Enum.ERROR_USER_NOTICE_INFORMATION_MESSAGE),
            UserUIContext.getMessage(GenericI18Enum.BUTTON_YES),
            UserUIContext.getMessage(GenericI18Enum.BUTTON_NO), confirmDialog -> {
            });
    Button okBtn = dialog.getOkButton();
    BrowserWindowOpener opener = new BrowserWindowOpener("http://support.mycollab.com");
    opener.extend(okBtn);
}