update NIO transport to write back custom http headers set on the Axis2 message context and to make the remote party IP address available to the Axis2 MC for incoming requests

git-svn-id: https://svn.apache.org/repos/asf/webservices/synapse/branches/0.92-SNAPSHOT@514554 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/modules/nhttp/src/org/apache/axis2/transport/nhttp/Axis2HttpRequest.java b/modules/nhttp/src/org/apache/axis2/transport/nhttp/Axis2HttpRequest.java
index 239e025..245672f 100644
--- a/modules/nhttp/src/org/apache/axis2/transport/nhttp/Axis2HttpRequest.java
+++ b/modules/nhttp/src/org/apache/axis2/transport/nhttp/Axis2HttpRequest.java
@@ -33,6 +33,8 @@
 import java.io.OutputStream;
 import java.nio.channels.Pipe;
 import java.nio.channels.Channels;
+import java.util.Map;
+import java.util.Iterator;
 
 /**
  * Represents an outgoing Axis2 HTTP/s request. It holds the EPR of the destination, the
@@ -82,6 +84,21 @@
     public HttpRequest getRequest() {
         HttpPost httpRequest = new HttpPost(epr.getAddress());
         httpRequest.setEntity(new BasicHttpEntity());
+
+        // set any transport headers
+        Object o = msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
+        if (o != null && o instanceof Map) {
+            Map headers = (Map) o;
+            Iterator iter = headers.keySet().iterator();
+            while (iter.hasNext()) {
+                Object header = iter.next();
+                Object value = headers.get(header);
+                if (header instanceof String && value != null && value instanceof String) {
+                    httpRequest.setHeader((String) header, (String) value);
+                }
+            }
+        }
+
         return httpRequest;
     }
 
diff --git a/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerHandler.java b/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerHandler.java
index aba1bd1..78926a8 100644
--- a/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerHandler.java
+++ b/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerHandler.java
@@ -162,6 +162,10 @@
         }
     }
 
+    public void responseReady(NHttpServerConnection conn) {
+        // New API method - should not require
+    }
+
     /**
      * Process ready output by writing into the channel
      * @param conn the connection being processed
diff --git a/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerWorker.java b/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerWorker.java
index 0bc78f0..55ce623 100644
--- a/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerWorker.java
+++ b/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerWorker.java
@@ -127,6 +127,11 @@
             headers.put(headerArr[i].getName(), headerArr[i].getValue());
         }
         msgContext.setProperty(MessageContext.TRANSPORT_HEADERS, headers);
+        // find the remote party IP address and set it to the message context
+        if (conn instanceof HttpInetConnection) {
+            HttpInetConnection inetConn = (HttpInetConnection) conn;
+            msgContext.setProperty(MessageContext.REMOTE_ADDR, inetConn.getRemoteAddress());
+        }
 
         try {
             msgContext.setTransportOut(cfgCtx.getAxisConfiguration()