com.vaadin.server.WrappedSession Java Examples

The following examples show how to use com.vaadin.server.WrappedSession. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VertxVaadin.java    From vertx-vaadin with MIT License 7 votes vote down vote up
private void configureSessionStore() {
    final Registration sessionInitListenerReg = this.service.addSessionInitListener(event -> {
        MessageConsumer<String> consumer = sessionExpiredHandler(vertx, msg ->
            Optional.of(event.getSession().getSession())
                .filter(session -> msg.body().equals(session.getId()))
                .ifPresent(WrappedSession::invalidate));
        AtomicReference<Registration> sessionDestroyListenerUnregister = new AtomicReference<>();
        sessionDestroyListenerUnregister.set(
            event.getService().addSessionDestroyListener(ev2 -> {
                consumer.unregister();
                sessionDestroyListenerUnregister.get().remove();
            })
        );

    });
    this.service.addServiceDestroyListener(event -> sessionInitListenerReg.remove());
}
 
Example #2
Source File: AppUI.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected void processLinkHandlerRequest(VaadinRequest request) {
    WrappedSession wrappedSession = request.getWrappedSession();
    //noinspection unchecked
    Map<String, String> params =
            (Map<String, String>) wrappedSession.getAttribute(LAST_REQUEST_PARAMS_ATTR);
    params = params != null ? params : Collections.emptyMap();

    try {
        String action = (String) wrappedSession.getAttribute(LAST_REQUEST_ACTION_ATTR);
        LinkHandler linkHandler = AppBeans.getPrototype(LinkHandler.NAME, app, action, params);
        if (app.connection.isConnected() && linkHandler.canHandleLink()) {
            linkHandler.handle();
        } else {
            app.linkHandler = linkHandler;
        }
    } catch (Exception e) {
        error(new com.vaadin.server.ErrorEvent(e));
    }
}
 
Example #3
Source File: LinkHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
/**
 * Called to handle the link.
 */
public void handle() {
    try {
        ExternalLinkContext linkContext = new ExternalLinkContext(requestParams, action, app);
        for (LinkHandlerProcessor processor : processors) {
            if (processor.canHandle(linkContext)) {
                processor.handle(linkContext);
                break;
            }
        }
    } finally {
        VaadinRequest request = VaadinService.getCurrentRequest();
        WrappedSession wrappedSession = request.getWrappedSession();
        wrappedSession.removeAttribute(AppUI.LAST_REQUEST_PARAMS_ATTR);
        wrappedSession.removeAttribute(AppUI.LAST_REQUEST_ACTION_ATTR);
    }
}
 
Example #4
Source File: DelayedEventBusPushStrategy.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
private void doDispatch(final List<TenantAwareEvent> events, final WrappedSession wrappedSession) {
    final SecurityContext userContext = (SecurityContext) wrappedSession
            .getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
    final SecurityContext oldContext = SecurityContextHolder.getContext();
    try {
        SecurityContextHolder.setContext(userContext);

        final List<EventContainer<TenantAwareEvent>> groupedEvents = groupEvents(events, userContext,
                eventProvider);

        vaadinUI.access(() -> {
            if (vaadinSession.getState() != State.OPEN) {
                return;
            }
            LOG.debug("UI EventBus aggregator of UI {} got lock on session.", vaadinUI.getUIId());
            groupedEvents.forEach(holder -> eventBus.publish(vaadinUI, holder));
            LOG.debug("UI EventBus aggregator of UI {} left lock on session.", vaadinUI.getUIId());
        }).get();
    } catch (InterruptedException | ExecutionException e) {
        LOG.warn("Wait for Vaadin session for UI {} interrupted!", vaadinUI.getUIId(), e);
        Thread.currentThread().interrupt();
    } finally {
        SecurityContextHolder.setContext(oldContext);
    }
}
 
Example #5
Source File: AppUI.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected boolean isLinkHandlerRequest(VaadinRequest request) {
    WrappedSession wrappedSession = request.getWrappedSession();
    if (wrappedSession == null) {
        return false;
    }

    String action = (String) wrappedSession.getAttribute(LAST_REQUEST_ACTION_ATTR);

    return webConfig.getLinkHandlerActions().contains(action);
}
 
Example #6
Source File: DelayedEventBusPushStrategy.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run() {
    LOG.debug("UI EventBus aggregator started for UI {}", vaadinUI.getUIId());
    final long timestamp = System.currentTimeMillis();

    final int size = queue.size();
    if (size <= 0) {
        LOG.debug("UI EventBus aggregator for UI {} has nothing to do.", vaadinUI.getUIId());
        return;
    }

    final WrappedSession wrappedSession = vaadinSession.getSession();
    if (wrappedSession == null) {
        return;
    }

    final List<TenantAwareEvent> events = new ArrayList<>(size);
    final int eventsSize = queue.drainTo(events);

    if (events.isEmpty()) {
        LOG.debug("UI EventBus aggregator for UI {} has nothing to do.", vaadinUI.getUIId());
        return;
    }

    LOG.debug("UI EventBus aggregator dispatches {} events for session {} for UI {}", eventsSize, vaadinSession,
            vaadinUI.getUIId());

    doDispatch(events, wrappedSession);

    LOG.debug("UI EventBus aggregator done with sending {} events in {} ms for UI {}", eventsSize,
            System.currentTimeMillis() - timestamp, vaadinUI.getUIId());

}
 
Example #7
Source File: VertxVaadinRequest.java    From vertx-vaadin with MIT License 4 votes vote down vote up
@Override
public WrappedSession getWrappedSession() {
    return getWrappedSession(true);
}
 
Example #8
Source File: VertxVaadinRequest.java    From vertx-vaadin with MIT License 4 votes vote down vote up
@Override
public WrappedSession getWrappedSession(boolean allowSessionCreation) {
    return Optional.ofNullable(routingContext.session())
        .map(ExtendedSession::adapt)
        .map(VertxWrappedSession::new).orElse(null);
}
 
Example #9
Source File: TestVaadinRequest.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public WrappedSession getWrappedSession() {
    return null;
}
 
Example #10
Source File: TestVaadinRequest.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public WrappedSession getWrappedSession(boolean allowSessionCreation) {
    return null;
}