List of usage examples for com.vaadin.server VaadinRequest getHeader
public String getHeader(String headerName);
From source file:annis.gui.requesthandler.BinaryRequestHandler.java
License:Apache License
public void sendResponse(VaadinSession session, VaadinRequest request, VaadinResponse pureResponse, boolean sendContent) throws IOException { if (!(pureResponse instanceof VaadinServletResponse)) { pureResponse.sendError(500, "Binary requests only work with servlets"); }// w ww . j a v a 2 s.co m VaadinServletResponse response = (VaadinServletResponse) pureResponse; Map<String, String[]> binaryParameter = request.getParameterMap(); String toplevelCorpusName = binaryParameter.get("toplevelCorpusName")[0]; String documentName = binaryParameter.get("documentName")[0]; String mimeType = null; if (binaryParameter.containsKey("mime")) { mimeType = binaryParameter.get("mime")[0]; } try { // always set the buffer size to the same one we will use for coyping, // otherwise we won't notice any client disconnection response.reset(); response.setCacheTime(-1); response.resetBuffer(); response.setBufferSize(BUFFER_SIZE); // 4K String requestedRangeRaw = request.getHeader("Range"); WebResource binaryRes = Helper.getAnnisWebResource().path("query").path("corpora") .path(urlPathEscape.escape(toplevelCorpusName)).path(urlPathEscape.escape(documentName)) .path("binary"); WebResource metaBinaryRes = Helper.getAnnisWebResource().path("meta").path("binary") .path(urlPathEscape.escape(toplevelCorpusName)).path(urlPathEscape.escape(documentName)); // tell client that we support byte ranges response.setHeader("Accept-Ranges", "bytes"); Preconditions.checkNotNull(mimeType, "No mime type given (parameter \"mime\""); AnnisBinaryMetaData meta = getMatchingMetadataFromService(metaBinaryRes, mimeType); if (meta == null) { response.sendError(404, "Binary file not found"); return; } ContentRange fullRange = new ContentRange(0, meta.getLength() - 1, meta.getLength()); ContentRange r = fullRange; try { if (requestedRangeRaw != null) { List<ContentRange> requestedRanges = ContentRange.parseFromHeader(requestedRangeRaw, meta.getLength(), 1); if (!requestedRanges.isEmpty()) { r = requestedRanges.get(0); } } long contentLength = (r.getEnd() - r.getStart() + 1); boolean useContentRange = !fullRange.equals(r); response.setContentType(meta.getMimeType()); if (useContentRange) { response.setHeader("Content-Range", r.toString()); } response.setContentLength((int) contentLength); response.setStatus(useContentRange ? 206 : 200); response.flushBuffer(); if (sendContent) { try (OutputStream out = response.getOutputStream();) { writeFromServiceToClient(r.getStart(), contentLength, binaryRes, out, mimeType); } } } catch (ContentRange.InvalidRangeException ex) { response.setHeader("Content-Range", "bytes */" + meta.getLength()); response.sendError(416, "Requested range not satisfiable: " + ex.getMessage()); return; } } catch (IOException ex) { log.warn("IOException in BinaryRequestHandler", ex); response.setStatus(500); } catch (ClientHandlerException | UniformInterfaceException ex) { log.error(null, ex); response.setStatus(500); } }
From source file:com.esofthead.mycollab.web.DesktopApplication.java
License:Open Source License
@Override protected void init(VaadinRequest request) { LOG.debug("Init mycollab application {} associate with session {}", this.toString(), VaadinSession.getCurrent()); LOG.debug("Register default error handler"); VaadinSession.getCurrent().setErrorHandler(new DefaultErrorHandler() { private static final long serialVersionUID = 1L; @Override//from w ww .j a v a 2s.co m public void error(com.vaadin.server.ErrorEvent event) { Throwable e = event.getThrowable(); handleException(e); } }); initialUrl = this.getPage().getUriFragment(); MyCollabSession.putVariable(CURRENT_APP, this); currentContext = new AppContext(); postSetupApp(request); try { currentContext.initDomain(initialSubDomain); } catch (SubDomainNotExistException e) { this.setContent(new NoSubDomainExistedWindow(initialSubDomain)); return; } mainWindowContainer = new MainWindowContainer(); this.setContent(mainWindowContainer); getPage().addUriFragmentChangedListener(new UriFragmentChangedListener() { private static final long serialVersionUID = 1L; @Override public void uriFragmentChanged(UriFragmentChangedEvent event) { enter(event.getUriFragment()); } }); EventBusFactory.getInstance().register(new ShellErrorHandler()); String userAgent = request.getHeader("user-agent"); if (isInNotSupportedBrowserList(userAgent.toLowerCase())) { NotificationUtil .showWarningNotification("Your browser is out of date. Some features of MyCollab will not" + " behave correctly. You should upgrade to the newer browser."); } }
From source file:com.foc.vaadin.FocWebApplication.java
License:Apache License
public void initialize(VaadinRequest vaadinRequest, ServletContext servletContext, HttpSession httpSession, boolean webServicesOnly) { // setTheme(FocVaadinTheme.THEME_NAME); // Page.getCurrent().setUriFragment("01barmaja"); Globals.logString("FocWebApplication.init 111"); setErrorHandler(new DefaultErrorHandler() { @Override/* ww w . j a v a2 s . c o m*/ public void error(com.vaadin.server.ErrorEvent event) { Globals.logString("Error - 1"); Throwable throwable = event != null ? event.getThrowable() : null; Globals.logString("Error - 2"); if (throwable != null && throwable instanceof Exception) { Globals.logString("Error - 3"); Globals.logException((Exception) throwable); Globals.logString("Error - 4"); } // Do the default error handling (optional) doDefault(event); } }); String userAgent = vaadinRequest != null ? vaadinRequest.getHeader("User-Agent") : null; isMobile = Utils.isMobile(userAgent); Globals.logString("FocWebApplication.init 2"); // isMobile = Globals.isTouchDevice(); String path = vaadinRequest != null ? vaadinRequest.getPathInfo() : null; Globals.logString("FocWebApplication.init 3"); if (path != null && !path.isEmpty() && path.length() > 1) { path = path.substring(1); isMobile = path.toLowerCase().trim().equals("m"); } Globals.logString("FocWebApplication.init 4"); addStyleName("focMainWindow"); Globals.logString("FocWebApplication.init 5"); // FocWebApplication.setInstanceForThread(this); setSessionIfEmpty(httpSession); Globals.logString("FocWebApplication.init 6"); startApplicationServer(servletContext, webServicesOnly); Globals.logString("FocWebApplication.init 7"); FocWebServer focWebServer = FocWebServer.getInstance(); if (focWebServer == null) { Globals.logString("FocWebApplication.init 8 - SERVER IS NULL"); } else { Globals.logString("FocWebApplication.init 8 - SERVER OK"); } focWebServer.addApplication(this); Globals.logString("FocWebApplication.init 9"); }
From source file:com.haulmont.cuba.web.security.ConnectionImpl.java
License:Apache License
@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(); }//www. j av a2 s.co m } else { userRemoteAddress = currentRequest.getRemoteAddr(); } } return userRemoteAddress; }
From source file:com.mycollab.vaadin.MyCollabUIProvider.java
License:Open Source License
@Override public Class<? extends UI> getUIClass(UIClassSelectionEvent event) { VaadinRequest request = event.getRequest(); String uiClass;/*from w w w. j a va 2 s . c o m*/ String userAgent; try { userAgent = request.getHeader("user-agent").toLowerCase(); } catch (Exception e) { return null; } uiClass = userAgent.contains("mobile") ? MOBILE_APP : DESKTOP_APP; try { return (Class<? extends UI>) Class.forName(uiClass); } catch (ClassNotFoundException e) { throw new MyCollabException(e); } }
From source file:com.mycollab.vaadin.Utils.java
License:Open Source License
public static boolean isTablet(VaadinRequest request) { try {// ww w . j ava 2s. com String userAgent = request.getHeader("user-agent").toLowerCase(); return userAgent.contains("ipad"); } catch (Exception e) { return false; } }
From source file:com.mycollab.web.DesktopApplication.java
License:Open Source License
@Override protected void init(final VaadinRequest request) { broadcastReceiverService = AppContextUtil.getSpringBean(BroadcastReceiverService.class); if (SiteConfiguration.getPullMethod() == SiteConfiguration.PullMethod.push) { getPushConfiguration().setPushMode(PushMode.MANUAL); }/*from w w w. j a v a2 s .c o m*/ VaadinSession.getCurrent().setErrorHandler(new DefaultErrorHandler() { private static final long serialVersionUID = 1L; @Override public void error(com.vaadin.server.ErrorEvent event) { Throwable e = event.getThrowable(); handleException(request, e); } }); setCurrentFragmentUrl(this.getPage().getUriFragment()); currentContext = new UserUIContext(); postSetupApp(request); EventBusFactory.getInstance().register(new ShellErrorHandler()); mainWindowContainer = new MainWindowContainer(); this.setContent(mainWindowContainer); getPage().setTitle("MyCollab - Online project management"); getPage().addUriFragmentChangedListener( uriFragmentChangedEvent -> enter(uriFragmentChangedEvent.getUriFragment())); String userAgent = request.getHeader("user-agent"); if (isInNotSupportedBrowserList(userAgent.toLowerCase())) { NotificationUtil.showWarningNotification(UserUIContext.getMessage(ErrorI18nEnum.BROWSER_OUT_UP_DATE)); } }
From source file:com.mycollab.web.DesktopApplication.java
License:Open Source License
private String printRequest(VaadinRequest request) { StringBuilder requestInfo = new StringBuilder(); Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String attr = headerNames.nextElement(); requestInfo.append(attr + ": " + request.getHeader(attr)).append('\n'); }// ww w . j a v a 2 s . c o m requestInfo.append("Subdomain: " + Utils.getSubDomain(request)).append('\n'); requestInfo.append("Remote address: " + request.getRemoteAddr()).append('\n'); requestInfo.append("Path info: " + request.getPathInfo()).append('\n'); requestInfo.append("Remote host: " + request.getRemoteHost()).append('\n'); return requestInfo.toString(); }
From source file:edu.nps.moves.mmowgli.CACManager.java
License:Open Source License
public static CACData findCAC(VaadinRequest req) { CACData cData = new CACData(); String val = req.getHeader(CAC_CLIENT_VERIFY_HEADER); String client;/*ww w .j a va2 s. co m*/ String cert; if (val != null) { if (val.equals(VERIFY_SUCCESS)) { client = req.getHeader(CAC_CLIENT_DN_HEADER); if (client != null) { cert = req.getHeader(CAC_CERT_HEADER); if (cert != null) { cData.isCACPresent = true; // will be reset on parse error parseCert(cert, cData); } } } } return cData; }
From source file:org.opencms.main.CmsUIServlet.java
License:Open Source License
/** * Checks whether the given request was referred from the login page.<p> * * @param request the request/*from w ww. jav a 2 s . co m*/ * * @return <code>true</code> in case of login ui requests */ static boolean isLoginUIRequest(VaadinRequest request) { String referrer = request.getHeader("referer"); return (referrer != null) && referrer.contains(CmsWorkplaceLoginHandler.LOGIN_HANDLER); }