[Miles' Blog]

Welcome 2 My Planet

Available categories: [/] [working on downwap.] [trouble shooting] [working on Yup Mailman]

Get Ip Addr. From The HttpServletRequest Wrapped By The "iisforward" ISAPI Extension In Weblogic | 通过iisforward isapi ext访问weblogic的取ip问题 [Permalink]

Sun Oct 02 12:46:42 CST 2005
Category [development. ~]

在IIS+Weblogic整合系统中,像移动网关一样,iisforward这个ISAPI过滤器也会对request对象进行再包装,附加一些WLS要用的头信息。这种情况下,直接用request.getRemoteAddr()是无法取到真正的客户IP的。

实际的iisforward附加头如下:

WL-Proxy-Client-IP=211.161.1.239
Proxy-Client-IP=211.161.1.239
X-Forwarded-For=211.161.1.239
WL-Proxy-Client-Keysize=
WL-Proxy-Client-Secretkeysize=
X-WebLogic-Request-ClusterInfo=true
X-WebLogic-KeepAliveSecs=30
X-WebLogic-Force-JVMID=-327089098
WL-Proxy-SSL=false
综上,正确作法如下:
public String getIpAddr(HttpServletRequest request) {
    String ip=request.getHeader("X-Forwarded-For");
    if(ip == null || ip.length() == 0) {
        ip=request.getHeader("Proxy-Client-IP");
    }
    if(ip == null || ip.length() == 0) {
        ip=request.getHeader("WL-Proxy-Client-IP");
    }
    if(ip == null || ip.length() == 0) {
        ip=request.getRemoteAddr();
    }
    return ip;
}
如此一来,就可适应各种情况,包括通过移动网关访问(会附加X-Forwarded-For)。通过这个简单例子可以看出封装和抽象的重要性。

Posted by: miles
Comments [0] |

?
十二月 2018
Sun? Mon? Tue? Wed? Thu? Fri? Sat?
      1
2345678
9101112131415
16171819202122
23242526272829
3031     
<  Nov???Today??? Jan  >
<< <   1   > >>

Available categories: [/] [working on downwap.] [trouble shooting] [working on Yup Mailman]

Powered By blojsom?? RSS Feed? RSS2 Feed? RDF Feed

html hits:?39872