当前位置: 首页>>代码示例>>Java>>正文


Java WrappedSession类代码示例

本文整理汇总了Java中com.vaadin.server.WrappedSession的典型用法代码示例。如果您正苦于以下问题:Java WrappedSession类的具体用法?Java WrappedSession怎么用?Java WrappedSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WrappedSession类属于com.vaadin.server包,在下文中一共展示了WrappedSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createVaadinSession

import com.vaadin.server.WrappedSession; //导入依赖的package包/类
/**
 * Create a VaadinSession
 * @param locale Client locale
 * @return VaadinSession instance
 * @throws Exception Failed to create session
 */
protected VaadinSession createVaadinSession(Locale locale) throws Exception {
	WrappedSession wrappedSession = mock(WrappedSession.class);
	VaadinServletService vaadinService = mock(VaadinServletService.class);
	when(vaadinService.getDeploymentConfiguration())
			.thenReturn(new DefaultDeploymentConfiguration(VaadinServletService.class, getDeploymentProperties()));

	VaadinSession session = mock(VaadinSession.class);
	when(session.getState()).thenReturn(VaadinSession.State.OPEN);
	when(session.getSession()).thenReturn(wrappedSession);
	when(session.getService()).thenReturn(vaadinService);
	when(session.getSession().getId()).thenReturn(TEST_SESSION_ID);
	when(session.hasLock()).thenReturn(true);
	when(session.getLocale()).thenReturn(locale != null ? locale : Locale.US);
	return session;
}
 
开发者ID:holon-platform,项目名称:holon-vaadin,代码行数:22,代码来源:AbstractVaadinTest.java

示例2: testFromRequest

import com.vaadin.server.WrappedSession; //导入依赖的package包/类
@Test
public void testFromRequest() {

	final DeviceInfo di = DeviceInfo.create(VaadinService.getCurrentRequest());
	assertNotNull(di);

	VaadinSession session = mock(VaadinSession.class);
	when(session.getState()).thenReturn(VaadinSession.State.OPEN);
	when(session.getSession()).thenReturn(mock(WrappedSession.class));
	when(session.getService()).thenReturn(mock(VaadinServletService.class));
	when(session.getSession().getId()).thenReturn(TEST_SESSION_ID);
	when(session.hasLock()).thenReturn(true);
	when(session.getLocale()).thenReturn(Locale.US);
	when(session.getAttribute(DeviceInfo.SESSION_ATTRIBUTE_NAME)).thenReturn(di);
	CurrentInstance.set(VaadinSession.class, session);

	Optional<DeviceInfo> odi = DeviceInfo.get();

	assertTrue(odi.isPresent());

}
 
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:22,代码来源:TestDeviceInfo.java

示例3: processExternalLink

import com.vaadin.server.WrappedSession; //导入依赖的package包/类
public void processExternalLink(VaadinRequest request) {
    WrappedSession wrappedSession = request.getWrappedSession();

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

    if (webConfig.getLinkHandlerActions().contains(action)) {
        //noinspection unchecked
        Map<String, String> params =
                (Map<String, String>) wrappedSession.getAttribute(LAST_REQUEST_PARAMS_ATTR);
        params = params != null ? params : Collections.emptyMap();

        try {
            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));
        }
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:24,代码来源:AppUI.java

示例4: init

import com.vaadin.server.WrappedSession; //导入依赖的package包/类
@Override
public void init(VaadinRequest request) {
					
	final WrappedSession session = request.getWrappedSession();
	
	final VerticalLayout layout = new VerticalLayout();
	layout.setMargin(true);
	parent.setContent(layout);

	Button button = new Button("Click Me");
	button.addClickListener(new Button.ClickListener() {

		public void buttonClick(ClickEvent event) {
			
			Integer counter = (Integer)session.getAttribute("counter");		
			if (counter == null) { counter = 0; }
			counter++;
			session.setAttribute("counter", counter);		
			
			layout.addComponent(new Label("Thank you for clicking, counter:" + counter));			
		}
	});

	layout.addComponent(button);			
}
 
开发者ID:jmarranz,项目名称:relproxy_examples,代码行数:26,代码来源:VaadinUIDelegateImpl.java

示例5: doDispatch

import com.vaadin.server.WrappedSession; //导入依赖的package包/类
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);
    } finally {
        SecurityContextHolder.setContext(oldContext);
    }
}
 
开发者ID:eclipse,项目名称:hawkbit,代码行数:25,代码来源:DelayedEventBusPushStrategy.java

示例6: getAuthentication

import com.vaadin.server.WrappedSession; //导入依赖的package包/类
@Override
public Authentication getAuthentication() {
    final SecurityContext securityContext = SecurityContextHolder.getContext();
    Authentication authentication = securityContext.getAuthentication();

    if (authentication == null) {
        // The SecurityContextHolder only holds the Authentication when it is
        // processing the securityFilterChain. After it completes the chain
        // it clears the context holder.

        // Therefore, the Authentication object can be retrieved from the
        // location where the securityFilterChain or VaadinSecurity has left it,
        // within the HttpSession.
        LOGGER.debug("No authentication object bound to thread, trying to access the session directly");
        WrappedSession session = getSession();
        if (session != null) {
            SecurityContext context = (SecurityContext) session.getAttribute(springSecurityContextKey);
            authentication = context.getAuthentication();
        } else {
            LOGGER.debug("No session bound to current thread, cannot retrieve the authentication object");
        }
    }
    return authentication;
}
 
开发者ID:peholmst,项目名称:vaadin4spring,代码行数:25,代码来源:DefaultVaadinSharedSecurity.java

示例7: initializeLocale

import com.vaadin.server.WrappedSession; //导入依赖的package包/类
public static void initializeLocale(VaadinRequest request) {
	WrappedSession session = request.getWrappedSession();
	HttpSession httpSession = ((WrappedHttpSession) session).getHttpSession();
	ServletContext servletContext = httpSession.getServletContext();

	String defaultLanguage = servletContext.getInitParameter(LOCALE_CONFIG_DEFAULT_LANGUAGE);
	defaultLocale = new Locale(defaultLanguage);

	String language = request.getParameter(LOCALE_PARAM_LANGUAGE);

	if (null == language) {
		currentLocale = defaultLocale;
	} else {
		currentLocale = new Locale(language);
	}

	Messages.initMessageSource(currentLocale);
}
 
开发者ID:tilioteo,项目名称:hypothesis,代码行数:19,代码来源:LocaleManager.java

示例8: processExternalLink

import com.vaadin.server.WrappedSession; //导入依赖的package包/类
@Override
public void processExternalLink(VaadinRequest request) {
    WrappedSession wrappedSession = request.getWrappedSession();
    String action = (String) wrappedSession.getAttribute(LAST_REQUEST_ACTION_ATTR);
    if (NexbitLinkHandler.RESET_ACTION.equals(action)) {
        //noinspection unchecked
        Map<String, String> params =
                (Map<String, String>) wrappedSession.getAttribute(LAST_REQUEST_PARAMS_ATTR);
        if (params == null) {
            log.warn("Unable to process the external link: lastRequestParams not found in session");
            return;
        }

        try {
            LinkHandler linkHandler = AppBeans.getPrototype(LinkHandler.NAME, app, action, params);
            if (((NexbitLinkHandler)linkHandler).canHandleLink(action, params)) {
                linkHandler.handle();
                wrappedSession.setAttribute(LAST_REQUEST_ACTION_ATTR, null);
                return;
            }
        } catch (Exception e) {
            error(new com.vaadin.server.ErrorEvent(e));
        }
    }

    super.processExternalLink(request);
}
 
开发者ID:pfurini,项目名称:cuba-component-forgot-password,代码行数:28,代码来源:NexbitAppUI.java

示例9: run

import com.vaadin.server.WrappedSession; //导入依赖的package包/类
@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());

}
 
开发者ID:eclipse,项目名称:hawkbit,代码行数:34,代码来源:DelayedEventBusPushStrategy.java

示例10: getCurrentHttpSession

import com.vaadin.server.WrappedSession; //导入依赖的package包/类
private static WrappedSession getCurrentHttpSession() {
    VaadinSession s = VaadinSession.getCurrent();
    if (s == null) {
        throw new IllegalStateException(
                "No session found for current thread");
    }
    return s.getSession();
}
 
开发者ID:vaadin,项目名称:archetype-application-example,代码行数:9,代码来源:CurrentUser.java

示例11: login

import com.vaadin.server.WrappedSession; //导入依赖的package包/类
@Override
public Authentication login(Authentication authentication, boolean rememberMe) throws Exception {
    final HttpServletRequest request = new RememberMeRequestWrapper(getCurrentRequest(), rememberMe,
        getRememberMeParameter());
    final HttpServletResponse response = getCurrentResponse();

    try {
        LOGGER.debug("Attempting authentication of {}, rememberMe = {}", authentication, rememberMe);
        final Authentication fullyAuthenticated = getAuthenticationManager().authenticate(authentication);

        LOGGER.debug("Invoking session authentication strategy");
        sessionAuthenticationStrategy.onAuthentication(fullyAuthenticated, request, response);

        successfulAuthentication(fullyAuthenticated, request, response);
        return fullyAuthenticated;
    } catch (Exception e) {
        unsuccessfulAuthentication(request, response);
        throw e;
    } finally {
        if (saveContextInSessionAfterLogin) {
            LOGGER.debug("Saving security context in the session");
            WrappedSession session = getSession();
            if (session != null) {
                session.setAttribute(springSecurityContextKey, SecurityContextHolder.getContext());
            } else {
                LOGGER.warn(
                    "Tried to save security context in the session, but no session was bound to the current thread");
            }
        }
    }
}
 
开发者ID:peholmst,项目名称:vaadin4spring,代码行数:32,代码来源:DefaultVaadinSharedSecurity.java

示例12: getSession

import com.vaadin.server.WrappedSession; //导入依赖的package包/类
private static WrappedSession getSession() {
    VaadinSession vaadinSession = VaadinSession.getCurrent();
    if (vaadinSession != null) {
        return vaadinSession.getSession();
    } else {
        return null;
    }
}
 
开发者ID:peholmst,项目名称:vaadin4spring,代码行数:9,代码来源:DefaultVaadinSharedSecurity.java

示例13: onRequestStart

import com.vaadin.server.WrappedSession; //导入依赖的package包/类
@Override
public void onRequestStart(VaadinRequest request, VaadinResponse response) {
    final WrappedSession wrappedSession = request.getWrappedSession(false);
    VaadinSession session = null;
    if (wrappedSession != null) {
        session = VaadinSession.getForSession(request.getService(), wrappedSession);
    }

    SecurityContextHolder.clearContext();
    if (session != null) {
        logger.trace("Loading security context from VaadinSession {}", session);
        SecurityContext securityContext;
        session.lock();
        try {
            securityContext = (SecurityContext) session.getAttribute(SECURITY_CONTEXT_SESSION_ATTRIBUTE);
        } finally {
            session.unlock();
        }
        if (securityContext == null) {
            logger.trace("No security context found in VaadinSession {}", session);
        } else {
            logger.trace("Setting security context to {}", securityContext);
            SecurityContextHolder.setContext(securityContext);
        }
    } else {
        logger.trace("No VaadinSession available for retrieving the security context");
    }
}
 
开发者ID:peholmst,项目名称:vaadin4spring,代码行数:29,代码来源:SecurityContextVaadinRequestListener.java

示例14: initializePlugins

import com.vaadin.server.WrappedSession; //导入依赖的package包/类
private void initializePlugins(VaadinRequest request) {

		WrappedSession session = request.getWrappedSession();
		HttpSession httpSession = ((WrappedHttpSession) session).getHttpSession();
		ServletContext servletContext = httpSession.getServletContext();

		String configFileName = servletContext.getInitParameter(PluginManager.PLUGIN_CONFIG_LOCATION);

		if (configFileName != null && configFileName.length() > 0) {
			configFileName = servletContext.getRealPath(configFileName);
			File configFile = new File(configFileName);
			PluginManager.get().initializeFromFile(configFile);
		}
	}
 
开发者ID:tilioteo,项目名称:hypothesis,代码行数:15,代码来源:AbstractUIPresenter.java

示例15: getWrappedSession

import com.vaadin.server.WrappedSession; //导入依赖的package包/类
@Override
public WrappedSession getWrappedSession() {
    return getWrappedSession(true);
}
 
开发者ID:mcollovati,项目名称:vaadin-vertx-samples,代码行数:5,代码来源:VertxVaadinRequest.java


注:本文中的com.vaadin.server.WrappedSession类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。