webservice获取客户端IP地址
目录:
[一]、基于JDK6 jax-ws开发的webservice获取客户端IP地址 以:http://www.micmiu.com/soa/webservice/jax-ws-demo/?中的?[三] 2?具体示例为基础: 1.?情况一:如果以?Endpoint.publish()?的方式发布: 服务端接口实现类:HelloServiceImpl.java?修改如下: 客户端调用后,服务端运行日志: 从上面的日志信息中可看出:服务端完全可以获取到客户端的IP地址。 2.?情况二:如果以web容器的方式发布(jetty 或 tomcat为例): 服务端接口实现?HelloServiceImpl.java?修改成如下: |
demo2
;
?
;
;
servlet
http
HttpServletRequest
;
;
;
?
;
?
/**
* blog http://www.micmiu.com
*
* @author Michael
*/
endpointInterface
"com.micmiu.jaxws.demo2.HelloService"
)
{
?
Resource
;
?
(
{
;
clientIP
;
;
"Hi,47) !important;">
" welcome to JAX-WS with IP: "
clientIP
" . see more http://www.micmiu.com "
;
}
?
{
null
;
{
;
HttpServletRequest
request
mc
SERVLET_REQUEST
;
request
getRemoteAddr
;
(
"client IP : "
clientIP
;
{
;
}
?
;
?
}
客户端代码不用修改,运行如下:
|
start
webservice
client
.
.
send
Michael
to
server
Hi
,
Michael
welcome
JAX
-
WS
with
IP
.
see
more
http
:
//www.micmiu.com
test
client
end
.
|
服务端运行日志如下: