本文整理汇总了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());
}
示例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());
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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;
}
示例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());
}
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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()));
}
});
}
示例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;
});
}