Java Code Examples for com.vaadin.server.VaadinRequest#getHeader()
The following examples show how to use
com.vaadin.server.VaadinRequest#getHeader() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Java8LocaleNegotiationStrategy.java From viritin with Apache License 2.0 | 6 votes |
@Override public Locale negotiate(List<Locale> supportedLocales, VaadinRequest vaadinRequest) { String languages = vaadinRequest.getHeader("Accept-Language"); try { // Use reflection here, so the code compiles with jdk 1.7 Class<?> languageRange = Class .forName("java.util.Locale$LanguageRange"); Method parse = languageRange.getMethod("parse", String.class); Object priorityList = parse.invoke(null, languages); Method lookup = Locale.class.getMethod("lookup", List.class, Collection.class); return (Locale) lookup.invoke(null, priorityList, supportedLocales); } catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException e) { throw new RuntimeException( "Java8LocaleNegotiontionStrategy need java 1.8 or newer.", e); } }
Example 2
Source File: RDFUnitDemo.java From RDFUnit with Apache License 2.0 | 6 votes |
private String getClientIpAddr(VaadinRequest request) { String ip = request.getHeader("X-Forwarded-For"); if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("HTTP_CLIENT_IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("HTTP_X_FORWARDED_FOR"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } return ip; }
Example 3
Source File: Java7LocaleNegotiationStrategy.java From viritin with Apache License 2.0 | 5 votes |
@Override public Locale negotiate(final List<Locale> supportedLocales, VaadinRequest vaadinRequest) { String languages = vaadinRequest.getHeader("Accept-Language"); ArrayList<Locale> preferredArray = new ArrayList<>( supportedLocales); if (languages != null) { final String[] priorityList = languages.split(","); Collections.sort(preferredArray, new Comparator<Locale>() { @Override public int compare(Locale o1, Locale o2) { int pos1 = supportedLocales.size(), pos2 = supportedLocales .size(); for (int i = 0; i < priorityList.length; i++) { String lang = priorityList[i].split("[_;-]")[0].trim(); if (lang.equals(o1.getLanguage())) { pos1 = i; } if (lang.equals(o2.getLanguage())) { pos2 = i; } } return pos1 - pos2; } }); } return preferredArray.get(0); }
Example 4
Source File: DesktopApplication.java From mycollab with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void init(VaadinRequest request) { broadcastReceiverService = AppContextUtil.getSpringBean(BroadcastReceiverService.class); ServerConfiguration serverConfiguration = AppContextUtil.getSpringBean(ServerConfiguration.class); if (serverConfiguration.isPush()) { getPushConfiguration().setPushMode(PushMode.MANUAL); } UI.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()); setCurrentContext(new UserUIContext()); postSetupApp(request); EventBusFactory.getInstance().register(new ShellErrorHandler()); mainWindowContainer = new MainWindowContainer(); this.setContent(mainWindowContainer); getPage().addPopStateListener((Page.PopStateListener) event -> enter(event.getPage().getUriFragment())); String userAgent = request.getHeader("user-agent"); if (isInNotSupportedBrowserList(userAgent.toLowerCase())) { NotificationUtil.showWarningNotification(UserUIContext.getMessage(ErrorI18nEnum.BROWSER_OUT_UP_DATE)); } }