Author: asankha
Date: Sun Mar  4 22:02:08 2007
New Revision: 514559

URL: http://svn.apache.org/viewvc?view=rev&rev=514559
Log:
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

Modified:
    
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/Axis2HttpRequest.java
    
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerHandler.java
    
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerWorker.java

Modified: 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/Axis2HttpRequest.java
URL: 
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/Axis2HttpRequest.java?view=diff&rev=514559&r1=514558&r2=514559
==============================================================================
--- 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/Axis2HttpRequest.java
 (original)
+++ 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/Axis2HttpRequest.java
 Sun Mar  4 22:02:08 2007
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  *  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -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;
     }
 
@@ -102,7 +119,7 @@
     public void streamMessageContents() throws AxisFault {
 
         log.debug("start streaming outgoing http request");
-        OutputStream out = Channels.newOutputStream(pipe.sink());        
+        OutputStream out = Channels.newOutputStream(pipe.sink());
         OMOutputFormat format = Util.getOMOutputFormat(msgContext);
 
         try {

Modified: 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerHandler.java
URL: 
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerHandler.java?view=diff&rev=514559&r1=514558&r2=514559
==============================================================================
--- 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerHandler.java
 (original)
+++ 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerHandler.java
 Sun Mar  4 22:02:08 2007
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  *  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -160,6 +160,10 @@
         } catch (IOException e) {
             handleException("I/O Error : " + e.getMessage(), e, conn);
         }
+    }
+
+    public void responseReady(NHttpServerConnection conn) {
+        // New API method - should not require
     }
 
     /**

Modified: 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerWorker.java
URL: 
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerWorker.java?view=diff&rev=514559&r1=514558&r2=514559
==============================================================================
--- 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerWorker.java
 (original)
+++ 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerWorker.java
 Sun Mar  4 22:02:08 2007
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  *  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -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()
@@ -137,7 +142,7 @@
             handleException("Unable to get out/in http transport 
configurations from Axis2", af);
             return null;
         }
-        
+
         return msgContext;
     }
 
@@ -233,7 +238,7 @@
                     parameters.put(param.substring(0, pos), 
param.substring(pos+1));
                 } else {
                     parameters.put(param, null);
-                }                
+                }
             }
         }
 
@@ -394,7 +399,7 @@
         if (e == null) {
             e = new Exception(msg);
         }
-        
+
         try {
             AxisEngine engine = new AxisEngine(cfgCtx);
             MessageContext faultContext = 
engine.createFaultMessageContext(msgContext, e);
@@ -404,7 +409,7 @@
             response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
             response.addHeader(CONTENT_TYPE, TEXT_XML);
             serverHandler.commitResponse(conn, response);
-            
+
             try {
                 os.write(msg.getBytes());
                 if (ex != null) {



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to