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


Java VaadinService类代码示例

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


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

示例1: testFromRequest

import com.vaadin.server.VaadinService; //导入依赖的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

示例2: init

import com.vaadin.server.VaadinService; //导入依赖的package包/类
@Override
protected void init(VaadinRequest request) {

    VertxVaadinRequest req = (VertxVaadinRequest) request;
    Cookie cookie = new Cookie("myCookie", "myValue");
    cookie.setMaxAge(120);
    cookie.setPath(req.getContextPath());
    VaadinService.getCurrentResponse().addCookie(cookie);

    Label sessionAttributeLabel = new MLabel().withCaption("Session listener");


    String deploymentId = req.getService().getVertx().getOrCreateContext().deploymentID();

    setContent(new MVerticalLayout(
        new Header("Vert.x Vaadin Sample").setHeaderLevel(1),
        new Label(String.format("Verticle %s deployed on Vert.x", deploymentId)),
        new Label("Session created at " + Instant.ofEpochMilli(req.getWrappedSession().getCreationTime())),
        sessionAttributeLabel
    ).withFullWidth());
}
 
开发者ID:mcollovati,项目名称:vaadin-vertx-samples,代码行数:22,代码来源:SimpleUI.java

示例3: SpellChoiceForm

import com.vaadin.server.VaadinService; //导入依赖的package包/类
public SpellChoiceForm(Character character, DSClass dsClass) {
    super(CharacterClass.class);

    this.character = character;
    this.chosenClass = dsClass;

    String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
    FileResource resource = new FileResource(new File(basepath + "/WEB-INF/sound/selectSpell.mp3"));

    spellSound = new Audio();
    spellSound.setSource(resource);
    spellSound.setShowControls(false);
    spellSound.setAutoplay(false);

    setSavedHandler(this);
}
 
开发者ID:viydaag,项目名称:dungeonstory-java,代码行数:17,代码来源:SpellChoiceForm.java

示例4: createRememberMeCookie

import com.vaadin.server.VaadinService; //导入依赖的package包/类
private void createRememberMeCookie(final User user)
{
	try
	{
		final String rememberMeToken = createRememberMeToken(user);
		final Cookie rememberMeCookie = new Cookie(COOKIENAME_RememberMe, rememberMeToken);
		
		final int maxAge = (int)TimeUnit.SECONDS.convert(cookieMaxAgeDays, TimeUnit.DAYS);
		rememberMeCookie.setMaxAge(maxAge);
		
		final String path = "/"; // (VaadinService.getCurrentRequest().getContextPath());
		rememberMeCookie.setPath(path); 
		VaadinService.getCurrentResponse().addCookie(rememberMeCookie);
		logger.debug("Cookie added for {}: {} (maxAge={}, path={})", user, rememberMeToken, maxAge, path);
	}
	catch (final Exception e)
	{
		logger.warn("Failed creating cookie for user: {}. Skipped.", user, e);
	}
}
 
开发者ID:metasfresh,项目名称:metasfresh-procurement-webui,代码行数:21,代码来源:LoginRememberMeService.java

示例5: removeRememberMeCookie

import com.vaadin.server.VaadinService; //导入依赖的package包/类
private void removeRememberMeCookie()
{
	try
	{
		Cookie cookie = getRememberMeCookie();
		if (cookie == null)
		{
			return;
		}

		cookie = new Cookie(COOKIENAME_RememberMe, null);
		cookie.setValue(null);
		cookie.setMaxAge(0); // by setting the cookie maxAge to 0 it will deleted immediately
		cookie.setPath("/");
		VaadinService.getCurrentResponse().addCookie(cookie);
		
		logger.debug("Cookie removed");
	}
	catch (final Exception e)
	{
		logger.warn("Failed removing the cookie", e);
	}
}
 
开发者ID:metasfresh,项目名称:metasfresh-procurement-webui,代码行数:24,代码来源:LoginRememberMeService.java

示例6: getUserRemoteAddress

import com.vaadin.server.VaadinService; //导入依赖的package包/类
@Nullable
protected String getUserRemoteAddress() {
    VaadinRequest currentRequest = VaadinService.getCurrentRequest();

    String userRemoteAddress = null;

    if (currentRequest != null) {
        String xForwardedFor = currentRequest.getHeader("X_FORWARDED_FOR");
        if (StringUtils.isNotBlank(xForwardedFor)) {
            String[] strings = xForwardedFor.split(",");
            String userAddressFromHeader = StringUtils.trimToEmpty(strings[strings.length - 1]);

            if (StringUtils.isNotEmpty(userAddressFromHeader)) {
                userRemoteAddress = userAddressFromHeader;
            } else {
                userRemoteAddress = currentRequest.getRemoteAddr();
            }
        } else {
            userRemoteAddress = currentRequest.getRemoteAddr();
        }
    }

    return userRemoteAddress;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:25,代码来源:ConnectionImpl.java

示例7: setCookies

import com.vaadin.server.VaadinService; //导入依赖的package包/类
private void setCookies() {
    if (multiTenancyIndicator.isMultiTenancySupported()) {
        final Cookie tenantCookie = new Cookie(SP_LOGIN_TENANT, tenant.getValue().toUpperCase());
        tenantCookie.setPath("/");
        // 100 days
        tenantCookie.setMaxAge(HUNDRED_DAYS_IN_SECONDS);
        tenantCookie.setHttpOnly(true);
        tenantCookie.setSecure(uiProperties.getLogin().getCookie().isSecure());
        VaadinService.getCurrentResponse().addCookie(tenantCookie);
    }

    final Cookie usernameCookie = new Cookie(SP_LOGIN_USER, username.getValue());
    usernameCookie.setPath("/");
    // 100 days
    usernameCookie.setMaxAge(HUNDRED_DAYS_IN_SECONDS);
    usernameCookie.setHttpOnly(true);
    usernameCookie.setSecure(uiProperties.getLogin().getCookie().isSecure());
    VaadinService.getCurrentResponse().addCookie(usernameCookie);
}
 
开发者ID:eclipse,项目名称:hawkbit,代码行数:20,代码来源:AbstractHawkbitLoginUI.java

示例8: getLocaleChain

import com.vaadin.server.VaadinService; //导入依赖的package包/类
/**
 * Get Locale for i18n.
 *
 * @return String as locales
 */
private static String[] getLocaleChain() {
    String[] localeChain = null;
    // Fetch all cookies from the request
    final Cookie[] cookies = VaadinService.getCurrentRequest().getCookies();
    if (cookies == null) {
        return localeChain;
    }

    for (final Cookie c : cookies) {
        if (c.getName().equals(SPUIDefinitions.COOKIE_NAME) && !c.getValue().isEmpty()) {
            localeChain = c.getValue().split("#");
            break;
        }
    }
    return localeChain;
}
 
开发者ID:eclipse,项目名称:hawkbit,代码行数:22,代码来源:AbstractHawkbitUI.java

示例9: buttonClick

import com.vaadin.server.VaadinService; //导入依赖的package包/类
@Override
public void buttonClick(final ClickEvent event) {
	final ServiceResponse response = ApplicationMangerAccess.getApplicationManager().service(logoutRequest);


	if (ServiceResult.SUCCESS == response.getResult()) {
		UI.getCurrent().getNavigator().navigateTo(CommonsViews.MAIN_VIEW_NAME);
		UI.getCurrent().getSession().close();
		VaadinService.getCurrentRequest().getWrappedSession().invalidate();
	} else {
		Notification.show(LOGOUT_FAILED,
                  ERROR_MESSAGE,
                  Notification.Type.WARNING_MESSAGE);
		LOGGER.info(LOG_MSG_LOGOUT_FAILURE,logoutRequest.getSessionId());
	}
}
 
开发者ID:Hack23,项目名称:cia,代码行数:17,代码来源:LogoutClickListener.java

示例10: constructStartUrl

import com.vaadin.server.VaadinService; //导入依赖的package包/类
private String constructStartUrl(String uid, boolean returnBack) {
    StringBuilder builder = new StringBuilder();
    String contextUrl = ServletUtil.getContextURL((VaadinServletRequest) VaadinService.getCurrentRequest());
    builder.append(contextUrl);
    builder.append("/process/?");

    // client debug
    // builder.append("gwt.codesvr=127.0.0.1:9997&");

    builder.append("token=");
    builder.append(uid);
    builder.append("&fs");
    if (returnBack) {
        builder.append("&bk=true");
    }

    String lang = ControlledUI.getCurrentLanguage();
    if (lang != null) {
        builder.append("&lang=");
        builder.append(lang);
    }

    return builder.toString();
}
 
开发者ID:tilioteo,项目名称:hypothesis,代码行数:25,代码来源:PublicPacksPresenter.java

示例11: createEmailIcon

import com.vaadin.server.VaadinService; //导入依赖的package包/类
private Image createEmailIcon(EmailContact emailContact)
{
	final String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
	final FileResource resource = new FileResource(new File(basepath + "/images/email.png"));

	Image image = new Image(null, resource);
	image.setDescription("Click to send an email");
	image.setVisible(false);

	image.addClickListener(new MouseEventLogged.ClickListener()
	{
		private static final long serialVersionUID = 1L;

		@Override
		public void clicked(final com.vaadin.event.MouseEvents.ClickEvent event)
		{
			showMailForm(emailContact);

		}
	});

	return image;
}
 
开发者ID:bsutton,项目名称:scoutmaster,代码行数:24,代码来源:SchoolView.java

示例12: isUidlRequest

import com.vaadin.server.VaadinService; //导入依赖的package包/类
/**
 * Test if current request is an UIDL request
 * @return true if in UIDL request, false otherwise
 */
private boolean isUidlRequest() {
	VaadinRequest request = VaadinService.getCurrentRequest();
	
	if (request == null)
		return false;
	
	 String pathInfo = request.getPathInfo();

	 if (pathInfo == null) {
            return false;
	 }
	 
	 if (pathInfo.startsWith("/" + ApplicationConstants.UIDL_PATH)) {
            return true;
        }

        return false;
}
 
开发者ID:chelu,项目名称:jdal,代码行数:23,代码来源:VaadinAccessDeniedHandler.java

示例13: checkAuthentication

import com.vaadin.server.VaadinService; //导入依赖的package包/类
/**
 * Check authentication using {@link Authenticate} annotation on given view class or the {@link UI} class to which
 * navigator is bound.
 * @param navigationState Navigation state
 * @param viewConfiguration View configuration
 * @return <code>true</code> if authentication is not required or if it is required and the current
 *         {@link AuthContext} is authenticated, <code>false</code> otherwise
 * @throws ViewNavigationException Missing {@link AuthContext} from context or other unexpected error
 */
protected boolean checkAuthentication(final String navigationState, final ViewConfiguration viewConfiguration)
		throws ViewNavigationException {
	if (!suspendAuthenticationCheck) {
		Authenticate authc = (viewConfiguration != null)
				? viewConfiguration.getAuthentication().orElse(uiAuthenticate) : uiAuthenticate;
		if (authc != null) {

			// check auth context
			final AuthContext authContext = AuthContext.getCurrent().orElseThrow(() -> new ViewNavigationException(
					navigationState,
					"No AuthContext available as Context resource: failed to process Authenticate annotation on View or UI"));

			if (!authContext.getAuthentication().isPresent()) {
				// not authenticated, try to authenticate from request
				final VaadinRequest request = VaadinService.getCurrentRequest();
				if (request != null) {
					try {
						authContext.authenticate(VaadinHttpRequest.create(request));
						// authentication succeded
						return true;
					} catch (@SuppressWarnings("unused") AuthenticationException e) {
						// failed, ignore
					}
				}
				onAuthenticationFailed(authc, navigationState);
				return false;
			}

		}
	}
	return true;
}
 
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:42,代码来源:NavigatorActuator.java

示例14: ensureInited

import com.vaadin.server.VaadinService; //导入依赖的package包/类
/**
 * Ensure that a {@link DeviceInfo} is available from given Vaadin <code>session</code>. For successful
 * initialization, a {@link VaadinService#getCurrentRequest()} must be available.
 * @param session Vaadin session (not null)
 */
static void ensureInited(VaadinSession session) {
	ObjectUtils.argumentNotNull(session, "VaadinSession must be not null");
	session.access(() -> {
		if (session.getAttribute(SESSION_ATTRIBUTE_NAME) == null && VaadinService.getCurrentRequest() != null) {
			session.setAttribute(SESSION_ATTRIBUTE_NAME, create(VaadinService.getCurrentRequest()));
		}
	});
}
 
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:14,代码来源:DeviceInfo.java

示例15: init

import com.vaadin.server.VaadinService; //导入依赖的package包/类
@Override
protected void init(VaadinRequest request) {

	// Root layout
       final VerticalLayout root = new VerticalLayout();
       root.setSizeFull();

       root.setSpacing(false);
       root.setMargin(false);

       setContent(root);

       // Main panel
       springViewDisplay = new Panel();
       springViewDisplay.setSizeFull();

       root.addComponent(springViewDisplay);
       root.setExpandRatio(springViewDisplay, 1);

       // Footer
       Layout footer = getFooter();
       root.addComponent(footer);
       root.setExpandRatio(footer, 0);

       // Error handler
	UI.getCurrent().setErrorHandler(new UIErrorHandler());

	// Disable session expired notification, the page will be reloaded on any action
	VaadinService.getCurrent().setSystemMessagesProvider(
			systemMessagesInfo -> {
				CustomizedSystemMessages msgs = new CustomizedSystemMessages();
				msgs.setSessionExpiredNotificationEnabled(false);
				return msgs;
			});
}
 
开发者ID:vianneyfaivre,项目名称:Persephone,代码行数:36,代码来源:PersephoneUI.java


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