<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page import="java.util.Enumeration" %>
<h1>This is a page for testing proxy webapp.</h1>
<h3>Webapp context path: <%=request.getContextPath()%></h3>
<b>sessionId:</b> <%=request.getSession().getId()%><br />
<b>serverName:</b> <%=request.getServerName()%><br />
<b>remoteAddr:</b> <%=request.getRemoteAddr()%><br />
<b>realRemoteAddr:</b> <%=getRealRemoteAddr(request)%><br />
<h3>Request Headers</h3>
<%
Enumeration<String> em = request.getHeaderNames();
while (em.hasMoreElements()) {
String name = em.nextElement();
StringBuilder sb = new StringBuilder();
Enumeration<String> e = request.getHeaders(name);
while (e.hasMoreElements()) {
sb.append(e.nextElement() + " | ");
}
out.println("<b>" + name + ":</b> " + sb + "<br />");
}
%>
<%!
String getRealRemoteAddr(HttpServletRequest request) {
String remoteAddr = request.getHeader("x-forwarded-for");
if (remoteAddr == null || remoteAddr.trim().length() == 0 || "unknown".equalsIgnoreCase(remoteAddr)) {
remoteAddr = request.getHeader("x-real-ip");
}
if (remoteAddr == null || remoteAddr.trim().length() == 0 || "unknown".equalsIgnoreCase(remoteAddr)) {
remoteAddr = request.getHeader("Proxy-Client-IP");
}
if (remoteAddr == null || remoteAddr.trim().length() == 0 || "unknown".equalsIgnoreCase(remoteAddr)) {
remoteAddr = request.getHeader("WL-Proxy-Client-IP");
}
if (remoteAddr == null || remoteAddr.trim().length() == 0 || "unknown".equalsIgnoreCase(remoteAddr)) {
remoteAddr = request.getRemoteAddr();
}
if (remoteAddr != null && remoteAddr.trim().length() != 0) {
String[] remoteAddrs = remoteAddr.split(",");
remoteAddr = remoteAddrs[0].trim();
}
return remoteAddr;
}
%>