You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by ru...@apache.org on 2008/05/27 07:05:17 UTC

svn commit: r660380 - /synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SoapSessionDispatcher.java

Author: ruwan
Date: Mon May 26 22:05:12 2008
New Revision: 660380

URL: http://svn.apache.org/viewvc?rev=660380&view=rev
Log:
Finalized the SYNAPSE-325, added logging to the soapsession load balancing with session affinity

Modified:
    synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SoapSessionDispatcher.java

Modified: synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SoapSessionDispatcher.java
URL: http://svn.apache.org/viewvc/synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SoapSessionDispatcher.java?rev=660380&r1=660379&r2=660380&view=diff
==============================================================================
--- synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SoapSessionDispatcher.java (original)
+++ synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SoapSessionDispatcher.java Mon May 26 22:05:12 2008
@@ -21,6 +21,7 @@
 
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.soap.SOAPHeader;
+import org.apache.axis2.addressing.AddressingConstants;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.MessageContext;
@@ -32,33 +33,38 @@
 
     private static final Log log = LogFactory.getLog(SoapSessionDispatcher.class);
 
+    private static final QName QNAME_SERVICE_GROUP_ID
+            = new QName("http://ws.apache.org/namespaces/axis2", "ServiceGroupId", "axis2");
+
     /**
      * Gives the endpoint based on the service group context ID of the request message.
      *
      * @param synCtx Request MessageContext, possibly containing a service group context ID.
      * @return Endpoint associated with the soap session, if current message is a soap session
-     *         message and if current message is not the first message of the session. Returns null, if
-     *         an Endpoint could not be found for the session.
+     *         message and if current message is not the first message of the session. Returns null,
+     *         if an Endpoint could not be found for the session.
      */
     public Endpoint getEndpoint(MessageContext synCtx, DispatcherContext dispatcherContext) {
-        Endpoint endpoint = null;
 
+        Endpoint endpoint = null;
         SOAPHeader header = synCtx.getEnvelope().getHeader();
-
+        
         if (header != null) {
-            OMElement sgcElm = header.getFirstChildWithName(
-                    new QName("http://ws.apache.org/namespaces/axis2", "ServiceGroupId", "axis2"));
+            OMElement sgcElm = header.getFirstChildWithName(QNAME_SERVICE_GROUP_ID);
 
             if (sgcElm != null) {
                 String sgcID = sgcElm.getText();
 
                 if (sgcID != null) {
-                    Object e = dispatcherContext.getEndpoint(sgcID);
-
-                    if (e != null && e instanceof Endpoint) {
-                        endpoint = (Endpoint) e;
+                    if (log.isDebugEnabled()) {
+                        log.debug("Using the ServiceGroupId SOAP header value "
+                                + sgcID + " to retrieve endpoint on the session");
                     }
+                    endpoint = dispatcherContext.getEndpoint(sgcID);
                 }
+            } else if (log.isDebugEnabled()) {
+                log.debug("Couldn't find the ServiceQroupId SOAP " +
+                        "header to retrieve the endpoint on the session");
             }
         }
 
@@ -73,7 +79,8 @@
      * @param synCtx   MessageContext of the response message.
      * @param endpoint Endpoint to associate with the session.
      */
-    public void updateSession(MessageContext synCtx, DispatcherContext dispatcherContext, Endpoint endpoint) {
+    public void updateSession(MessageContext synCtx, DispatcherContext dispatcherContext,
+        Endpoint endpoint) {
 
         if (endpoint == null || dispatcherContext == null) {
             return;
@@ -86,24 +93,38 @@
         SOAPHeader header = synCtx.getEnvelope().getHeader();
 
         if (header != null) {
-            OMElement replyTo = header.getFirstChildWithName
-                    (new QName("http://www.w3.org/2005/08/addressing", "ReplyTo", "wsa"));
+            OMElement replyTo = header.getFirstChildWithName(
+                    AddressingConstants.Final.QNAME_WSA_REPLY_TO);
 
             if (replyTo != null) {
                 OMElement referenceParameters = replyTo.getFirstChildWithName(new QName(
                         "http://www.w3.org/2005/08/addressing", "ReferenceParameters", "wsa"));
 
                 if (referenceParameters != null) {
-                    OMElement sgcElm = referenceParameters.getFirstChildWithName(new QName(
-                            "http://ws.apache.org/namespaces/axis2", "ServiceGroupId", "axis2"));
-
-                    // synchronized to avoid possible replacement of sessions
-                    String sgcID = sgcElm.getText();
+                    OMElement sgcElm
+                            = referenceParameters.getFirstChildWithName(QNAME_SERVICE_GROUP_ID);
 
-                    if (sgcID != null) {
-                        dispatcherContext.setEndpoint(sgcID, endpoint);
+                    if (sgcElm != null) {
+                        // synchronized to avoid possible replacement of sessions
+                        String sgcID = sgcElm.getText();
+
+                        if (sgcID != null) {
+                            if (log.isDebugEnabled()) {
+                                log.debug("Using the ServiceGroupId value "
+                                        + sgcID + " to update the endpoint session");
+                            }
+                            dispatcherContext.setEndpoint(sgcID, endpoint);
+                        }
+                    } else if (log.isDebugEnabled()) {
+                        log.debug("Couldn't find the WSA ServiceQroupId on the " +
+                                "ReferenceParameters of the Reply-To header to update the session");
                     }
+                } else if (log.isDebugEnabled()) {
+                    log.debug("Couldn't find the WSA ReferenceParameters in the Reply-To " +
+                            "header to retrieve the ServiceQroupId");
                 }
+            } else if (log.isDebugEnabled()) {
+                log.debug("Couldn't find the WSA Reply-To header to retrieve the ServiceQroupId");
             }
         }
     }
@@ -113,15 +134,20 @@
         SOAPHeader header = synCtx.getEnvelope().getHeader();
 
         if (header != null) {
-            OMElement sgcIDElm = header.getFirstChildWithName(
-                    new QName("http://ws.apache.org/namespaces/axis2", "ServiceGroupId", "axis2"));
+            OMElement sgcIDElm = header.getFirstChildWithName(QNAME_SERVICE_GROUP_ID);
 
             if (sgcIDElm != null) {
                 String sgcID = sgcIDElm.getText();
 
                 if (sgcID != null) {
+                    if (log.isDebugEnabled()) {
+                        log.debug("Using the ServiceGroupId value "
+                                + sgcID + " to unbind session");
+                    }
                     dispatcherContext.removeSession(sgcID);
                 }
+            } else if (log.isDebugEnabled()) {
+                log.debug("Couldn't find the ServiceQroupId SOAP header to unbind the session");
             }
         }
     }