gluu
静的公開メンバ関数 | 静的公開変数類 | 非公開メンバ関数 | 静的非公開メンバ関数 | 静的非公開変数類 | 全メンバ一覧
org.gluu.credmanager.core.navigation.WebUtils クラス
org.gluu.credmanager.core.navigation.WebUtils 連携図
Collaboration graph

静的公開メンバ関数

static HttpServletRequest getServletRequest ()
 
static String getRequestHeader (String headerName)
 
static String getRemoteIP ()
 
static String getUrlContents (String url, int timeout) throws Exception
 
static JsonNode getGeoLocation (String ip, String urlPattern, int timeout)
 
static void execRedirect (String url)
 
static String getQueryParam (String param)
 

静的公開変数類

static final String USER_PAGE_URL ="user.zul"
 
static final String ADMIN_PAGE_URL ="admin.zul"
 

非公開メンバ関数

 WebUtils ()
 

静的非公開メンバ関数

static String getUrlContents (String url, List< NameValuePair > nvPairList, int timeout) throws Exception
 
static void execRedirect (String url, boolean voidUI)
 

静的非公開変数類

static Logger LOG = LogManager.getLogger(WebUtils.class)
 
static ObjectMapper MAPPER = new ObjectMapper()
 

詳解

著者
jgomer

構築子と解体子

◆ WebUtils()

org.gluu.credmanager.core.navigation.WebUtils.WebUtils ( )
inlineprivate
44 { }

関数詳解

◆ execRedirect() [1/2]

static void org.gluu.credmanager.core.navigation.WebUtils.execRedirect ( String  url)
inlinestatic
99  {
100  execRedirect(url, true);
101  }
static void execRedirect(String url)
Definition: WebUtils.java:99

◆ execRedirect() [2/2]

static void org.gluu.credmanager.core.navigation.WebUtils.execRedirect ( String  url,
boolean  voidUI 
)
inlinestaticprivate
136  {
137 
138  try {
139  Execution exec = Executions.getCurrent();
140  HttpServletResponse response = (HttpServletResponse) exec.getNativeResponse();
141 
142  LOG.debug("Redirecting to URL={}", url);
143  response.sendRedirect(response.encodeRedirectURL(url));
144  if (voidUI) {
145  exec.setVoided(voidUI); //no need to create UI since redirect will take place
146  }
147  } catch (IOException e) {
148  LOG.error(e.getMessage(), e);
149  }
150 
151  }
static Logger LOG
Definition: WebUtils.java:38

◆ getGeoLocation()

static JsonNode org.gluu.credmanager.core.navigation.WebUtils.getGeoLocation ( String  ip,
String  urlPattern,
int  timeout 
)
inlinestatic

Executes a geolocation call the to ip-api.com service

引数
ipString representing an IP address
urlPattern
timeout
戻り値
A JsonNode with the respone. Null if there was an error issuing or parsing the contents
78  {
79 
80  JsonNode node = null;
81  try {
82  String ipApiResponse = WebUtils.getUrlContents(MessageFormat.format(urlPattern, ip), timeout);
83  LOG.debug("Response from ip-api.com was: {}", ipApiResponse);
84 
85  if (ipApiResponse != null) {
86  node = MAPPER.readTree(ipApiResponse);
87  if (!node.get("status").asText().equals("success")) {
88  node = null;
89  }
90  }
91  } catch (Exception e) {
92  node = null;
93  LOG.info("An error occurred determining remote location: {}", e.getMessage());
94  LOG.error(e.getMessage(), e);
95  }
96  return node;
97  }
static ObjectMapper MAPPER
Definition: WebUtils.java:39
static Logger LOG
Definition: WebUtils.java:38
WebUtils()
Definition: WebUtils.java:44

◆ getQueryParam()

static String org.gluu.credmanager.core.navigation.WebUtils.getQueryParam ( String  param)
inlinestatic
103  {
104  String[] values = Executions.getCurrent().getParameterValues(param);
105  return Utils.isEmpty(values) ? null : values[0];
106  }

◆ getRemoteIP()

static String org.gluu.credmanager.core.navigation.WebUtils.getRemoteIP ( )
inlinestatic
54  {
55 
56  String ip = getRequestHeader("X-Forwarded-For");
57  if (ip == null) {
58  ip = getServletRequest().getRemoteAddr();
59  } else {
60  String[] ips = ip.split(",\\s*");
61  ip = Utils.isNotEmpty(ips) ? ips[0] : null;
62  }
63  return ip;
64 
65  }
static String getRequestHeader(String headerName)
Definition: WebUtils.java:50
static HttpServletRequest getServletRequest()
Definition: WebUtils.java:46

◆ getRequestHeader()

static String org.gluu.credmanager.core.navigation.WebUtils.getRequestHeader ( String  headerName)
inlinestatic
50  {
51  return getServletRequest().getHeader(headerName);
52  }
static HttpServletRequest getServletRequest()
Definition: WebUtils.java:46

◆ getServletRequest()

static HttpServletRequest org.gluu.credmanager.core.navigation.WebUtils.getServletRequest ( )
inlinestatic
46  {
47  return (HttpServletRequest) Executions.getCurrent().getNativeRequest();
48  }

◆ getUrlContents() [1/2]

static String org.gluu.credmanager.core.navigation.WebUtils.getUrlContents ( String  url,
int  timeout 
) throws Exception
inlinestatic
67  {
68  return getUrlContents(url, Collections.emptyList(), timeout);
69  }
static String getUrlContents(String url, int timeout)
Definition: WebUtils.java:67

◆ getUrlContents() [2/2]

static String org.gluu.credmanager.core.navigation.WebUtils.getUrlContents ( String  url,
List< NameValuePair >  nvPairList,
int  timeout 
) throws Exception
inlinestaticprivate
108  {
109 
110  String contents=null;
111 
112  DefaultHttpClient client = new DefaultHttpClient();
113  HttpParams params = client.getParams();
114  HttpConnectionParams.setConnectionTimeout(params, timeout);
115  HttpConnectionParams.setSoTimeout(params, timeout);
116 
117  HttpGet httpGet = new HttpGet(url);
118  URIBuilder uribe = new URIBuilder(httpGet.getURI());
119  nvPairList.forEach(pair -> uribe.addParameter(pair.getName(), pair.getValue()));
120 
121  httpGet.setURI(uribe.build());
122  httpGet.setHeader("Accept", "application/json");
123  HttpResponse response = client.execute(httpGet);
124  HttpEntity entity = response.getEntity();
125 
126  LOG.debug("GET request is {}", httpGet.getURI());
127  if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
128  contents = EntityUtils.toString(entity);
129  }
130  EntityUtils.consume(entity);
131 
132  return contents;
133 
134  }
static Logger LOG
Definition: WebUtils.java:38

メンバ詳解

◆ ADMIN_PAGE_URL

final String org.gluu.credmanager.core.navigation.WebUtils.ADMIN_PAGE_URL ="admin.zul"
static

◆ LOG

Logger org.gluu.credmanager.core.navigation.WebUtils.LOG = LogManager.getLogger(WebUtils.class)
staticprivate

◆ MAPPER

ObjectMapper org.gluu.credmanager.core.navigation.WebUtils.MAPPER = new ObjectMapper()
staticprivate

◆ USER_PAGE_URL

final String org.gluu.credmanager.core.navigation.WebUtils.USER_PAGE_URL ="user.zul"
static

このクラス詳解は次のファイルから抽出されました: