axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r480918 - in /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server: DefaultHttpConnectionFactory.java DefaultHttpServiceProcessor.java
Date Thu, 30 Nov 2006 13:34:36 GMT
Author: dims
Date: Thu Nov 30 05:34:35 2006
New Revision: 480918

URL: http://svn.apache.org/viewvc?view=rev&rev=480918
Log:
Fix for AXIS2-1751 - Allow Axis2 to know the IP address and host name of the remote client
when using the SimpleHTTPServer

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/DefaultHttpConnectionFactory.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/DefaultHttpServiceProcessor.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/DefaultHttpConnectionFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/DefaultHttpConnectionFactory.java?view=diff&rev=480918&r1=480917&r2=480918
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/DefaultHttpConnectionFactory.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/DefaultHttpConnectionFactory.java
Thu Nov 30 05:34:35 2006
@@ -50,9 +50,33 @@
     
     public HttpServerConnection newConnection(final Socket socket)
             throws IOException {
-        DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
+        DefaultHttpServerConnection conn = new Axis2HttpServerConnection();
         conn.bind(socket, this.params);
         return conn;
     }
     
+    public class Axis2HttpServerConnection extends DefaultHttpServerConnection {
+        public Axis2HttpServerConnection() {
+            super();
+        }
+
+        public String getRemoteIPAddress() {
+            java.net.SocketAddress sa = socket.getRemoteSocketAddress();
+            if (sa instanceof java.net.InetSocketAddress) {
+            	return ((java.net.InetSocketAddress) sa).getAddress().getHostAddress();
+            } else {
+            	return sa.toString();
+            }
+        }
+
+        public String getRemoteHostName() {
+        	java.net.SocketAddress sa = socket.getRemoteSocketAddress();
+        	if (sa instanceof java.net.InetSocketAddress) {
+          	return ((java.net.InetSocketAddress) sa).getHostName();
+          } else {
+          	return sa.toString(); // fail-safe and fall back to something which one can use
in place of the host name
+          }
+        }
+    }
+
 }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/DefaultHttpServiceProcessor.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/DefaultHttpServiceProcessor.java?view=diff&rev=480918&r1=480917&r2=480918
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/DefaultHttpServiceProcessor.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/DefaultHttpServiceProcessor.java
Thu Nov 30 05:34:35 2006
@@ -57,6 +57,7 @@
 import org.apache.http.RequestLine;
 import org.apache.http.StatusLine;
 import org.apache.http.UnsupportedHttpVersionException;
+import org.apache.http.impl.DefaultHttpServerConnection;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.ResponseConnControl;
@@ -73,6 +74,7 @@
     private final SessionManager sessionManager;
     private final Worker worker;
     private final IOProcessorCallback callback;
+    private HttpServerConnection conn;
 
     private HttpContext httpcontext = null;
 
@@ -83,6 +85,7 @@
             final Worker worker,
             final IOProcessorCallback callback) {
         super(conn);
+        this.conn = conn;
         if (worker == null) {
             throw new IllegalArgumentException("Worker may not be null");
         }
@@ -148,6 +151,14 @@
 
         MessageContext msgContext = new MessageContext();
         msgContext.setIncomingTransportName(Constants.TRANSPORT_HTTP);
+
+        if (conn instanceof DefaultHttpConnectionFactory.Axis2HttpServerConnection) {
+            DefaultHttpConnectionFactory.Axis2HttpServerConnection axis2Con =
+                (DefaultHttpConnectionFactory.Axis2HttpServerConnection) conn;
+            msgContext.setProperty(MessageContext.REMOTE_ADDR, axis2Con.getRemoteIPAddress());
+            LOG.debug("Remote address of the connection : " + axis2Con.getRemoteIPAddress());
+        }
+
         try {
             TransportOutDescription transportOut = this.configurationContext.getAxisConfiguration()
                     .getTransportOut(new QName(Constants.TRANSPORT_HTTP));



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message