List of usage examples for com.vaadin.server VaadinServletRequest getHttpServletRequest
public HttpServletRequest getHttpServletRequest()
From source file:fr.univlorraine.mondossierweb.GenericUI.java
License:Apache License
public String getIpClient() { if (!StringUtils.hasText(ipClient)) { VaadinRequest vr = VaadinService.getCurrentRequest(); VaadinServletRequest vsRequest = (VaadinServletRequest) vr; HttpServletRequest hsRequest = vsRequest.getHttpServletRequest(); String ip = hsRequest.getHeader("x-forwarded-for"); if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = hsRequest.getHeader("X_FORWARDED_FOR"); } else {//from ww w. ja v a 2 s.c o m //Si x-forwarded-for contient plusieurs IP, on prend la deuxime if (ip.contains(",")) { ip = ip.split(",")[1]; } } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = hsRequest.getHeader("X-Forwarded-For"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = hsRequest.getHeader("HTTP_X_FORWARDED_FOR"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = hsRequest.getHeader("Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = hsRequest.getHeader("WL-Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = hsRequest.getRemoteAddr(); } ipClient = ip; } return ipClient; }
From source file:org.bubblecloud.ilves.site.DefaultSiteUI.java
License:Apache License
@Override protected Site constructSite(final VaadinRequest request) { // Construct entity manager for this site context. final EntityManager entityManager = entityManagerFactory.createEntityManager(); // Construct audit entity manager for this site context. final EntityManager auditEntityManager = entityManagerFactory.createEntityManager(); // Choose company for this site context. final VaadinServletRequest servletRequest = (VaadinServletRequest) VaadinService.getCurrentRequest(); // The virtual host based on URL. final Company company = resolveCompany(entityManager, servletRequest); final SiteContext siteContext = new SiteContext(entityManager, auditEntityManager, servletRequest, securityProvider);/*from w w w . j ava 2s . c o m*/ siteContext.putObject(EntityManager.class, entityManager); siteContext.putObject(EntityManagerFactory.class, entityManagerFactory); siteContext.putObject(Company.class, company); final X509Certificate[] clientCertificates = (X509Certificate[]) servletRequest.getHttpServletRequest() .getAttribute("javax.servlet.request.X509Certificate"); if (clientCertificates != null && clientCertificates.length == 1 && securityProvider.getUserFromSession() == null && company != null && company.isCertificateLogin()) { final User user = UserClientCertificateCache.getUserByCertificate(clientCertificates[0], true); if (user != null && user.getOwner().equals(company)) { securityProvider.setUser(user, UserDao.getUserGroups(entityManager, company, user)); LOGGER.info("User certificate login: " + user.getEmailAddress() + " Remote address: " + servletRequest.getHttpServletRequest().getRemoteAddr() + ":" + servletRequest.getHttpServletRequest().getRemotePort() + ")"); } } addCredentialPostRequestHandler(); analyser = new SiteAnalyser(this, company.getGaTrackingId()); this.getNavigator().addViewChangeListener(analyser); return new Site(SiteMode.PRODUCTION, contentProvider, localizationProvider, securityProvider, siteContext); }
From source file:org.bubblecloud.ilves.site.DefaultSiteUI.java
License:Apache License
public static Company resolveCompany(EntityManager entityManager, VaadinServletRequest servletRequest) { final String hostName = servletRequest.getHttpServletRequest().getServerName(); Company company = CompanyDao.getCompany(entityManager, hostName); if (company == null) { company = CompanyDao.getCompany(entityManager, "*"); }//from w w w .j a v a 2s . c o m return company; }
From source file:org.vaadin.addons.sitekit.site.AbstractSiteUI.java
License:Apache License
@Override protected final void init(final VaadinRequest request) { final VaadinServletRequest servletRequest = (VaadinServletRequest) VaadinService.getCurrentRequest(); final StringBuffer urlBuilder = servletRequest.getHttpServletRequest().getRequestURL(); final String queryString = servletRequest.getHttpServletRequest().getQueryString(); if (queryString != null) { urlBuilder.append('?'); urlBuilder.append(queryString);//from w w w .j a v a2 s.c o m } navigator = new SiteNavigator(this, this); site = constructSite(request); navigator.addViewChangeListener(site); navigator.addProvider(site); site.initialize(); }
From source file:org.vaadin.addons.sitekit.site.DefaultSiteUI.java
License:Apache License
@Override protected Site constructSite(final VaadinRequest request) { final SiteContext siteContext = new SiteContext(); // Construct entity manager for this site context. final EntityManager entityManager = entityManagerFactory.createEntityManager(); siteContext.putObject(EntityManager.class, entityManager); // Choose company for this site context. final VaadinServletRequest servletRequest = (VaadinServletRequest) VaadinService.getCurrentRequest(); final String hostName = servletRequest.getHttpServletRequest().getServerName(); final Company company = CompanyDao.getCompany(entityManager, hostName); if (company == null) { siteContext.putObject(Company.class, CompanyDao.getCompany(entityManager, "*")); } else {//from w ww . j av a2 s .co m siteContext.putObject(Company.class, company); } return new Site(SiteMode.PRODUCTION, contentProvider, localizationProvider, securityProvider, siteContext); }
From source file:pl.exsio.plupload.PluploadReceiver.java
License:Open Source License
@Override public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { if (request.getPathInfo() != null && request.getPathInfo().endsWith(UPLOAD_ACTION_PATH)) { if (request instanceof VaadinServletRequest) { VaadinServletRequest vsr = (VaadinServletRequest) request; HttpServletRequest req = vsr.getHttpServletRequest(); if (ServletFileUpload.isMultipartContent(req)) { try { synchronized (this) { ServletFileUpload upload = new ServletFileUpload(); FileItemIterator items = upload.getItemIterator(req); PluploadChunk chunk = PluploadChunkFactory.create(items); PluploadChunkHandler fileHandler = this.getExpectedFileHandler(chunk.getFileId()); fileHandler.handleUploadedChunk(chunk); this.writeResponse(chunk, response); }// w w w . j ava2s . c om } catch (Exception ex) { response.getWriter().append("file upload unsuccessful, because of " + ex.getClass().getName() + ":" + ex.getMessage()); throw new IOException( "There was a problem during processing of uploaded chunk. Nested exceptions may have more info.", ex); } return true; } } } return false; }