本文整理汇总了Java中com.vaadin.server.VaadinServletService类的典型用法代码示例。如果您正苦于以下问题:Java VaadinServletService类的具体用法?Java VaadinServletService怎么用?Java VaadinServletService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VaadinServletService类属于com.vaadin.server包,在下文中一共展示了VaadinServletService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createVaadinSession
import com.vaadin.server.VaadinServletService; //导入依赖的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;
}
示例2: buildVaadinRequest
import com.vaadin.server.VaadinServletService; //导入依赖的package包/类
@SuppressWarnings("serial")
@Override
protected VaadinServletRequest buildVaadinRequest(String location) {
return new SpringVaadinServletRequest(request, (VaadinServletService) vaadinSession.getService(), false) {
/*
* (non-Javadoc)
* @see javax.servlet.ServletRequestWrapper#getParameter(java.lang.String)
*/
@Override
public String getParameter(String name) {
if ("v-loc".equals(name)) {
return location;
}
return super.getParameter(name);
}
};
}
示例3: buildVaadinRequest
import com.vaadin.server.VaadinServletService; //导入依赖的package包/类
/**
* Build VaadinServletRequest using a location
* @param location Page location
* @return VaadinServletRequest
*/
@SuppressWarnings("serial")
protected VaadinServletRequest buildVaadinRequest(final String location) {
return new VaadinServletRequest(buildHttpServletRequest(), (VaadinServletService) vaadinSession.getService()) {
/*
* (non-Javadoc)
* @see javax.servlet.ServletRequestWrapper#getParameter(java.lang.String)
*/
@Override
public String getParameter(String name) {
if ("v-loc".equals(name)) {
return location;
}
return super.getParameter(name);
}
};
}
示例4: testFromRequest
import com.vaadin.server.VaadinServletService; //导入依赖的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());
}
示例5: getStaticFileLocation
import com.vaadin.server.VaadinServletService; //导入依赖的package包/类
@Override
public String getStaticFileLocation(VaadinRequest request) {
String staticFileLocation;
// if property is defined in configurations, use that
staticFileLocation = getDeploymentConfiguration().getResourcesPath();
if (staticFileLocation != null) {
return staticFileLocation;
}
VertxVaadinRequest vertxRequest = (VertxVaadinRequest) request;
String requestedPath = vertxRequest.getRequest().path()
.substring(
Optional.ofNullable(vertxRequest.getRoutingContext().mountPoint())
.map(String::length).orElse(0)
);
return VaadinServletService.getCancelingRelativePath(requestedPath);
}
示例6: validate
import com.vaadin.server.VaadinServletService; //导入依赖的package包/类
@Override
public boolean validate(String username, String password) {
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);
try {
Authentication auth = this.authenticationManager.authenticate(token);
if (auth.isAuthenticated()) {
// execute session authentication strategy
if (this.sessionStrategy != null)
this.sessionStrategy.onAuthentication(auth, VaadinServletService.getCurrentServletRequest(),
VaadinServletService.getCurrentResponse());
SecurityContextHolder.getContext().setAuthentication(auth);
// save request in context session
VaadinSession.getCurrent().getSession().setAttribute(
HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
SecurityContextHolder.getContext());
return true;
}
SecurityContextHolder.clearContext();
return false;
}
catch(AuthenticationException ae) {
SecurityContextHolder.clearContext();
return false;
}
}
示例7: createServletService
import com.vaadin.server.VaadinServletService; //导入依赖的package包/类
@Override
protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration)
throws ServiceException {
JMeterService service = new JMeterService(this, deploymentConfiguration);
service.init();
return service;
}
示例8: getLogoutUrl
import com.vaadin.server.VaadinServletService; //导入依赖的package包/类
private String getLogoutUrl() {
if (VaadinServletService.getCurrentRequest() != null) {
return VaadinServletService.getCurrentRequest().getContextPath();
} else {
return "https://" + this.server.getServerIpAddress() + "/";
}
}
示例9: getCurrentPageUrl
import com.vaadin.server.VaadinServletService; //导入依赖的package包/类
private static String getCurrentPageUrl(ServerApi server) {
String url;
if (Page.getCurrent() != null && Page.getCurrent().getLocation() != null) {
url = Page.getCurrent().getLocation().toString();
} else if (VaadinServletService.getCurrentRequest() != null) {
url = VaadinServletService.getCurrentRequest().getContextPath();
} else {
url = "https://" + server.getServerIpAddress() + "/";
}
// Workaround bug in URL generation
url = url.replace("#!", "/#!");
url = url.replace("//#!", "/#!");
return url;
}
示例10: createServletService
import com.vaadin.server.VaadinServletService; //导入依赖的package包/类
@Override
protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration)
throws ServiceException {
VaadinServletService servletService = super.createServletService(deploymentConfiguration);
servletService.addSessionInitListener(e -> e.getSession().addUIProvider(this.uiProvider));
servletService.addSessionInitListener(e -> sessions.add(e.getSession()));
servletService.addSessionDestroyListener(e -> sessions.remove(e.getSession()));
return servletService;
}
示例11: servletInitialized
import com.vaadin.server.VaadinServletService; //导入依赖的package包/类
@Override
protected void servletInitialized() throws ServletException {
super.servletInitialized();
// register session init/destroy listeners
final VaadinServletService service = getService();
sessionInitListeners.forEach(listener -> service.addSessionInitListener(listener));
sessionDestroyListeners.forEach(listener -> service.addSessionDestroyListener(listener));
}
示例12: listen
import com.vaadin.server.VaadinServletService; //导入依赖的package包/类
public void listen(@Observes
AnswerSavedEvent event) {
RespondentAccount respondent = (RespondentAccount) VaadinServletService.getCurrentServletRequest()
.getUserPrincipal();
Integer questionnaireId = respondent.getGrantedquestionnaireIds().iterator().next();
Answer answer = event.getAnswer();
String questionCode = event.getQuestionCode();
logger.debug("Trying to save answer: {} for questionnair identified with id = {} and questionCode = {}",
answer, questionnaireId, questionCode);
questionnaireResource.saveAnswer(answer, questionnaireId, questionCode);
}
示例13: testServletInitializedMethod
import com.vaadin.server.VaadinServletService; //导入依赖的package包/类
@Test
public void testServletInitializedMethod() throws Exception {
// expect adding session init listener
VaadinServletService servletService = createMock(VaadinServletService.class);
Whitebox.setInternalState(servlet, "servletService", servletService);
servletService.addSessionInitListener(sessionInitListenerMock);
replayAll();
try {
servlet.servletInitialized();
} finally {
verifyAll();
}
}
示例14: createServletService
import com.vaadin.server.VaadinServletService; //导入依赖的package包/类
@Override
protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) throws ServiceException {
VaadinServletService servletService = super.createServletService(deploymentConfiguration);
servletService.addSessionInitListener(new SessionInitListener() {
@Override
public void sessionInit(SessionInitEvent sessionInitEvent) throws ServiceException {
sessionInitEvent.getSession().addUIProvider(provider);
}
});
return servletService;
}
示例15: modifyBootstrapPage
import com.vaadin.server.VaadinServletService; //导入依赖的package包/类
@Override
public void modifyBootstrapPage(BootstrapPageResponse response) {
ViewPortSettings viewPortSettings2 = selectViewPortSettings(response);
if (viewPortSettings2 != null) {
viewPortSettings2.modifyBootstrapPage(response);
}
if (getWebAppSettings() != null) {
getWebAppSettings().modifyBootstrapPage(response);
}
if (getApplicationIcons() != null) {
getApplicationIcons().modifyBootstrapPage(response);
}
if (getApplicationCacheSettings() != null) {
OfflineModeEnabled offline = null;
CacheManifestEnabled manifest = null;
Class<?> clazz = response.getUiClass();
if (clazz != null) {
offline = clazz.getAnnotation(OfflineModeEnabled.class);
manifest = clazz.getAnnotation(CacheManifestEnabled.class);
}
if (response.getSession().getService() instanceof VaadinServletService) {
clazz = ((VaadinServletService) response.getSession()
.getService()).getServlet().getClass();
if (offline == null) {
offline = clazz.getAnnotation(OfflineModeEnabled.class);
}
if (manifest == null) {
manifest = clazz.getAnnotation(CacheManifestEnabled.class);
}
}
getApplicationCacheSettings().setCacheManifestEnabled(
manifest == null || manifest.value());
getApplicationCacheSettings().setOfflineModeEnabled(
offline == null || offline.value());
getApplicationCacheSettings().modifyBootstrapPage(response);
}
}