2012-04-10 2 views
2

저는 Apache 기본 사용자 (http://ws.apache.org/xmlrpc/server.html)가 제안한 기본값을 그대로 따르는 매우 기본적인 XMLRPC Servlet Server를 운영합니다.Apache XMLRPC 환경에서 사용자의 IP 주소를 요청 하시겠습니까?

내 XMLRPC 기능 내에서 요청자의 IP 주소에 액세스 할 수있는 방법이 있습니까? IP 주소별로 다른 사용자로부터받은 요청을 기록하는 서비스를 설계하고 있습니다. 내가 그들의 예에서 계산기 클래스를 복용 한 경우 예를 들어, 내가 좋아하는 뭔가를 할 수

,

public int add(int a, int b){ 
    IPAddress user = {magic incantation}; 
    Log.info("Summed " + a + " and " + b + " for " + user); 
    return a + b; 
} 

(분명이 장난감 예,하지만 내가하는 방법을 알고 있다면 그건, 내가 할 수있는

내 프로그램에서하고 싶은 것을하십시오)

대단히 감사합니다 !!

답변

1

요청을 처리 할 때 HttpServletRequest의 인스턴스에 액세스 할 수 있습니다. 이 개체는 getRemoteAddr() 메서드를 제공합니다.

또한 : FAQ에서는 this snippet을 찾아 IP를 ThreadLocal으로 저장하고 이후에 액세스 할 수 있습니다 (어쩌면 원하는 것 이상).

스 니펫의 재생은 다음과 같습니다

public static class ClientInfoServlet extends XmlRpcServlet { 
    private static ThreadLocal clientIpAddress = new ThreadLocal(); 

    public static String getClientIpAddress() { 
     return (String) clientIpAddress.get(); 
    } 

    public void doPost(HttpServletRequest pRequest, HttpServletResponse pResponse) 
      throws IOException, ServletException { 
     clientIpAddress.set(pRequest.getRemoteAddr()); 
     super.doPost(pRequest, pResponse); 
    } 
} 
+0

큰 일했다! 고마워요! – justinemarie

관련 문제