Author: asankha
Date: Wed Nov 12 02:52:33 2008
New Revision: 23713
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=23713

Log:
add support for MC property POST_TO_PATH


Modified:
   
branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/Axis2HttpRequest.java
   
branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOSender.java
   
branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java
   
branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java

Modified: 
branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/Axis2HttpRequest.java
URL: 
http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/Axis2HttpRequest.java?rev=23713&r1=23712&r2=23713&view=diff
==============================================================================
--- 
branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/Axis2HttpRequest.java
       (original)
+++ 
branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/Axis2HttpRequest.java
       Wed Nov 12 02:52:33 2008
@@ -46,6 +46,7 @@
 import java.nio.channels.ClosedChannelException;
 import java.util.Iterator;
 import java.util.Map;
+import java.net.URL;
 
 /**
  * Represents an outgoing Axis2 HTTP/s request. It holds the EPR of the 
destination, the
@@ -145,9 +146,14 @@
                 
             } else {
                 
-                httpRequest = new BasicHttpEntityEnclosingRequest(
-                    "POST", epr.getAddress(), HttpVersion.HTTP_1_0);
-                
+                if (msgContext.isPropertyTrue(NhttpConstants.POST_TO_PATH)) {
+                    httpRequest = new BasicHttpEntityEnclosingRequest(
+                        "POST", new URL(epr.getAddress()).getPath(), 
HttpVersion.HTTP_1_0);
+                } else {
+                   httpRequest = new BasicHttpEntityEnclosingRequest(
+                        "POST", epr.getAddress(), HttpVersion.HTTP_1_0);
+                }
+
                 ByteArrayOutputStream baos = new ByteArrayOutputStream();
                 messageFormatter.writeTo(msgContext, format, baos, false);
                 BasicHttpEntity entity = new BasicHttpEntity();
@@ -166,7 +172,12 @@
                     "GET", RESTUtil.getURI(msgContext, epr.getAddress()));
 
             } else {
-                httpRequest = new BasicHttpEntityEnclosingRequest("POST", 
epr.getAddress());
+                if (msgContext.isPropertyTrue(NhttpConstants.POST_TO_PATH)) {
+                    httpRequest = new BasicHttpEntityEnclosingRequest(
+                        "POST", new URL(epr.getAddress()).getPath());
+                } else {
+                    httpRequest = new BasicHttpEntityEnclosingRequest("POST", 
epr.getAddress());
+                }
                 ((BasicHttpEntityEnclosingRequest) httpRequest).setEntity(new 
BasicHttpEntity());
             }
         }
@@ -180,7 +191,9 @@
                 Object header = iter.next();
                 Object value = headers.get(header);
                 if (header instanceof String && value != null && value 
instanceof String) {
-                    httpRequest.setHeader((String) header, (String) value);
+                    if (!HTTPConstants.HEADER_HOST.equalsIgnoreCase((String) 
header)) {
+                        httpRequest.setHeader((String) header, (String) value);
+                    }
                 }
             }
         }

Modified: 
branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOSender.java
URL: 
http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOSender.java?rev=23713&r1=23712&r2=23713&view=diff
==============================================================================
--- 
branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOSender.java
      (original)
+++ 
branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/HttpCoreNIOSender.java
      Wed Nov 12 02:52:33 2008
@@ -342,6 +342,9 @@
             } else {
                 try {
                     handler.submitRequest(conn, axis2Req);
+                    if (log.isDebugEnabled()) {
+                        log.debug("An existing connection reused to : " + 
url.getHost() + ":" + port);
+                    }                    
                 } catch (ConnectionClosedException e) {
                     ioReactor.connect(new InetSocketAddress(url.getHost(), 
port),
                         null, axis2Req, sessionRequestCallback);
@@ -349,9 +352,6 @@
                         log.debug("A new connection established to : " + 
url.getHost() + ":" + port);
                     }
                 }
-                if (log.isDebugEnabled()) {
-                    log.debug("An existing connection reused to : " + 
url.getHost() + ":" + port);
-                }
             }
 
             try {
@@ -449,27 +449,30 @@
             if (lstMetrics != null) {
                 lstMetrics.incrementFaultsSending();
             }
-            handleException("Unexpected HTTP protocol error : " + 
e.getMessage(), e);
+            handleException("Unexpected HTTP protocol error sending response 
to : " +
+                worker.getRemoteAddress(), e);
         } catch (ConnectionClosedException e) {
             if (lstMetrics != null) {
                 lstMetrics.incrementFaultsSending();
             }
-            log.warn("Connection closed by client (Connection closed)");
+            log.warn("Connection closed by client : " + 
worker.getRemoteAddress());
         } catch (IllegalStateException e) {
             if (lstMetrics != null) {
                 lstMetrics.incrementFaultsSending();
             }
-            log.warn("Connection closed by client (Buffer closed)");
+            log.warn("Connection closed by client : " + 
worker.getRemoteAddress());
         } catch (IOException e) {
             if (lstMetrics != null) {
                 lstMetrics.incrementFaultsSending();
             }
-            handleException("IO Error sending response message", e);
+            handleException("IO Error sending response message to : " +
+                worker.getRemoteAddress(), e);
         } catch (Exception e) {
             if (lstMetrics != null) {
                 lstMetrics.incrementFaultsSending();
             }
-            handleException("General Error sending response message", e);
+            handleException("General Error sending response message to : " +
+                worker.getRemoteAddress(), e);
         }
 
         try {

Modified: 
branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java
URL: 
http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java?rev=23713&r1=23712&r2=23713&view=diff
==============================================================================
--- 
branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java
 (original)
+++ 
branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/NhttpConstants.java
 Wed Nov 12 02:52:33 2008
@@ -23,6 +23,7 @@
     public static final String SC_ACCEPTED = "SC_ACCEPTED";
     public static final String HTTP_SC = "HTTP_SC";
     public static final String FORCE_HTTP_1_0 = "FORCE_HTTP_1.0";
+    public static final String POST_TO_PATH = "POST_TO_PATH";
     public static final String NO_KEEPALIVE = "NO_KEEPALIVE";
     public static final String DISABLE_KEEPALIVE = 
"http.connection.disable.keepalive";
     public static final String IGNORE_SC_ACCEPTED = "IGNORE_SC_ACCEPTED";

Modified: 
branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
URL: 
http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java?rev=23713&r1=23712&r2=23713&view=diff
==============================================================================
--- 
branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
   (original)
+++ 
branches/synapse/1.2.wso2v1/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
   Wed Nov 12 02:52:33 2008
@@ -87,6 +87,10 @@
     private static final String CONTENT_TYPE = "Content-Type";
     private static final String TEXT_HTML    = "text/html";
     private static final String TEXT_XML     = "text/xml";
+    /** Save requesting user IP address for logging - even during response 
processing when
+     * the connection may be closed
+     */
+    private String remoteAddress = null;
 
     /**
      * Create a new server side worker to process an incoming message and 
optionally begin creating
@@ -171,6 +175,7 @@
                 msgContext.setProperty(MessageContext.REMOTE_ADDR, 
remoteAddr.getHostAddress());
                 msgContext.setProperty(
                         NhttpConstants.REMOTE_HOST, 
NhttpUtils.getHostName(remoteAddr));
+                remoteAddress = remoteAddr.getHostAddress();
             }
         }
 
@@ -599,6 +604,10 @@
         return conn;
     }
 
+    public String getRemoteAddress() {
+        return remoteAddress;
+    }
+
     /**
      * Whatever this method returns as the IP is ignored by the actual http/s 
listener when
      * its getServiceEPR is invoked. This was originally copied from axis2

_______________________________________________
Esb-java-dev mailing list
[email protected]
http://mailman.wso2.org/cgi-bin/mailman/listinfo/esb-java-dev

Reply via email to