本文整理汇总了Java中com.vaadin.server.VaadinRequest.getHeader方法的典型用法代码示例。如果您正苦于以下问题:Java VaadinRequest.getHeader方法的具体用法?Java VaadinRequest.getHeader怎么用?Java VaadinRequest.getHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vaadin.server.VaadinRequest
的用法示例。
在下文中一共展示了VaadinRequest.getHeader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUserRemoteAddress
import com.vaadin.server.VaadinRequest; //导入方法依赖的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;
}
示例2: negotiate
import com.vaadin.server.VaadinRequest; //导入方法依赖的package包/类
@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);
}
}
示例3: getClientIpAddr
import com.vaadin.server.VaadinRequest; //导入方法依赖的package包/类
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;
}
示例4: UiAccessControl
import com.vaadin.server.VaadinRequest; //导入方法依赖的package包/类
public UiAccessControl(VaadinRequest request) {
sessionId = request.getWrappedSession().getId();
if (!isUserSignedIn()) {
// try auto login
String host = request.getHeader("Host");
VirtualHost vHost = MApi.lookup(CherryApi.class).findVirtualHost(host);
AaaContext context = vHost.doLogin(new VaadinRequestWrapper(request), null);
if (context != null) {
IProperties session = MApi.lookup(InternalCherryApi.class).getCherrySession(sessionId);
session.put(InternalCherryApi.SESSION_ACCESS_NAME, context);
}
}
}
示例5: negotiate
import com.vaadin.server.VaadinRequest; //导入方法依赖的package包/类
@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);
}
示例6: DefaultUserAgentInspector
import com.vaadin.server.VaadinRequest; //导入方法依赖的package包/类
/**
* Constructor using {@link VaadinRequest}
* @param request Vaadin Request
*/
public DefaultUserAgentInspector(VaadinRequest request) {
this(request.getHeader("user-agent"), request.getHeader("accept"));
}