Author: damitha
Date: Thu Feb 28 00:23:50 2008
New Revision: 631888

URL: http://svn.apache.org/viewvc?rev=631888&view=rev
Log:
moving drop if duplicate from global_in_handler to in_handler

Modified:
    webservices/sandesha/trunk/c/include/sandesha2_constants.h
    webservices/sandesha/trunk/c/src/handlers/sandesha2_global_in_handler.c
    webservices/sandesha/trunk/c/src/handlers/sandesha2_in_handler.c

Modified: webservices/sandesha/trunk/c/include/sandesha2_constants.h
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/c/include/sandesha2_constants.h?rev=631888&r1=631887&r2=631888&view=diff
==============================================================================
--- webservices/sandesha/trunk/c/include/sandesha2_constants.h (original)
+++ webservices/sandesha/trunk/c/include/sandesha2_constants.h Thu Feb 28 
00:23:50 2008
@@ -519,6 +519,7 @@
        #define SANDESHA2_INVOKER_SLEEP  "InvokerSleepTime"
        #define SANDESHA2_POLLING_WAIT  "PollingWaitTime"
        #define SANDESHA2_MODULE  "sandesha2"
+       #define SANDESHA2_ISOLATED_LAST_MSG "isolated_last_msg"
 /** @} */
 #ifdef __cplusplus
 }

Modified: 
webservices/sandesha/trunk/c/src/handlers/sandesha2_global_in_handler.c
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/c/src/handlers/sandesha2_global_in_handler.c?rev=631888&r1=631887&r2=631888&view=diff
==============================================================================
--- webservices/sandesha/trunk/c/src/handlers/sandesha2_global_in_handler.c 
(original)
+++ webservices/sandesha/trunk/c/src/handlers/sandesha2_global_in_handler.c Thu 
Feb 28 00:23:50 2008
@@ -21,22 +21,16 @@
 #include <axutil_property.h>
 #include <axis2_const.h>
 #include <axis2_conf_ctx.h>
-#include <axiom_soap_header.h>
-#include <sandesha2_storage_mgr.h>
-#include <sandesha2_permanent_storage_mgr.h>
-#include <sandesha2_permanent_seq_property_mgr.h>
-#include <sandesha2_permanent_sender_mgr.h>
 #include <sandesha2_seq.h>
 #include <sandesha2_msg_ctx.h>
 #include <sandesha2_msg_processor.h>
 #include <sandesha2_msg_init.h>
 #include <sandesha2_constants.h>
 #include <sandesha2_utils.h>
+#include <axis2_relates_to.h>
 #include <axiom_soap_fault.h>
 #include <axiom_soap_body.h>
-#include <axis2_relates_to.h>
-#include <sandesha2_seq_property_mgr.h>
-#include <sandesha2_sender_mgr.h>
+#include <axiom_soap_header.h>
 #include <stdlib.h>
 #include <sandesha2_seq.h>
 #include <sandesha2_msg_number.h>
@@ -49,39 +43,18 @@
     const axutil_env_t *env,
     struct axis2_msg_ctx *msg_ctx);
     
-static axis2_bool_t AXIS2_CALL
-sandesha2_global_in_handler_drop_if_duplicate(
-    struct axis2_handler *handler, 
-    const axutil_env_t *env,
-    sandesha2_msg_ctx_t *rm_msg_ctx,
-    sandesha2_storage_mgr_t *storage_mgr,
-    sandesha2_seq_property_mgr_t *seq_prop_mgr,
-    sandesha2_sender_mgr_t *sender_mgr);
-                                             
-
-static axis2_status_t AXIS2_CALL
-sandesha2_global_in_handler_process_dropped_msg(
-    struct axis2_handler *handler, 
-    const axutil_env_t *env,
-    sandesha2_msg_ctx_t *rm_msg_ctx,
-    sandesha2_storage_mgr_t *storage_mgr,
-    sandesha2_seq_property_mgr_t *seq_prop_mgr,
-    sandesha2_sender_mgr_t *sender_mgr);
-
 AXIS2_EXTERN axis2_handler_t* AXIS2_CALL
 sandesha2_global_in_handler_create(
     const axutil_env_t *env, 
     axutil_qname_t *qname) 
 {
     axis2_handler_t *handler = NULL;
-    AXIS2_ENV_CHECK(env, NULL);
     
     handler = axis2_handler_create(env);
     if (!handler)
     {
         return NULL;
     }
-   
     /* handler init is handled by conf loading, so no need to do it here */
     
     /* set the base struct's invoke op */
@@ -101,7 +74,6 @@
     axis2_conf_ctx_t *conf_ctx = NULL;
     /*axis2_ctx_t *ctx = NULL;*/
     /*axis2_char_t *reinjected_msg = AXIS2_FALSE;*/
-    axis2_bool_t dropped = AXIS2_FALSE;
     /*axutil_property_t *property = NULL;*/
     axiom_soap_envelope_t *soap_envelope = NULL;
     axiom_soap_fault_t *fault_part = NULL;
@@ -110,11 +82,6 @@
     const axis2_char_t *soap_action = NULL;
     axis2_bool_t is_rm_global_msg = AXIS2_FALSE;
     sandesha2_msg_ctx_t *rm_msg_ctx = NULL;
-    sandesha2_storage_mgr_t *storage_mgr = NULL;
-    sandesha2_seq_property_mgr_t *seq_prop_mgr = NULL;
-    sandesha2_sender_mgr_t *sender_mgr = NULL;
-    axis2_bool_t isolated_last_msg = AXIS2_FALSE;
-    axis2_char_t *dbname = NULL;
     AXIS2_PARAM_CHECK(env->error, msg_ctx, AXIS2_FAILURE);
     AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,  
         "[sandesha2]Entry:sandesha2_global_in_handler");
@@ -158,6 +125,7 @@
                 body_node = axiom_soap_body_get_base_node(body, env);
                 if(body && !axiom_node_get_first_element(body_node, env))
                 {
+                    axutil_property_t *property = NULL;
                     axutil_string_t *temp_soap_action = 
axutil_string_create(env, 
                         SANDESHA2_SPEC_2005_02_SOAP_ACTION_LAST_MESSAGE);
                     /* There is an empty body so we know this is the kind of 
message
@@ -167,7 +135,11 @@
                         "Setting SOAP Action for a WSRM 1.0 last message");
                     axis2_msg_ctx_set_soap_action(msg_ctx, env, 
                         temp_soap_action);
-                    isolated_last_msg = AXIS2_TRUE;
+
+                    property = axutil_property_create_with_args(env, 0, 0, 0, 
+                        AXIS2_VALUE_TRUE);
+                    axis2_ctx_set_property(msg_ctx, env, 
+                        SANDESHA2_ISOLATED_LAST_MSG, property);
                 }
             }
         }
@@ -250,237 +222,11 @@
             }
         }
     }
-    if(!sandesha2_permanent_storage_mgr_create_db(env, conf_ctx))
-    {
-        return AXIS2_FAILURE;
-    }
-    dbname = sandesha2_util_get_dbname(env, conf_ctx);
-    storage_mgr = sandesha2_utils_get_storage_mgr(env, dbname);
-    seq_prop_mgr = sandesha2_permanent_seq_property_mgr_create(env, dbname);
-    sender_mgr = sandesha2_permanent_sender_mgr_create(env, dbname);
-    rm_msg_ctx = sandesha2_msg_init_init_msg(env, msg_ctx);
-    if(!isolated_last_msg)
-        dropped = sandesha2_global_in_handler_drop_if_duplicate(handler, env, 
-            rm_msg_ctx, storage_mgr, seq_prop_mgr, sender_mgr);
-    if(dropped)
-    {
-        sandesha2_global_in_handler_process_dropped_msg(handler, env, 
-            rm_msg_ctx, storage_mgr, seq_prop_mgr, sender_mgr);
-        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
-            "[sandesha2]msg_ctx dropped. So return here");
-        if(rm_msg_ctx)
-            sandesha2_msg_ctx_free(rm_msg_ctx, env);
-        if(seq_prop_mgr)
-            sandesha2_seq_property_mgr_free(seq_prop_mgr, env);
-        if(storage_mgr)
-            sandesha2_storage_mgr_free(storage_mgr, env);
-        return AXIS2_SUCCESS;
-    }
     /*Process if global processing possible. - Currently none*/
-    if(rm_msg_ctx)
-        sandesha2_msg_ctx_free(rm_msg_ctx, env);
-    if(seq_prop_mgr)
-        sandesha2_seq_property_mgr_free(seq_prop_mgr, env);
-    if(storage_mgr)
-        sandesha2_storage_mgr_free(storage_mgr, env);
-
     AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, 
         "[sandesha2]Exit:sandesha2_global_in_handler");
        
     return AXIS2_SUCCESS;
 }
 
-static axis2_bool_t AXIS2_CALL
-sandesha2_global_in_handler_drop_if_duplicate(
-    struct axis2_handler *handler, 
-    const axutil_env_t *env,
-    sandesha2_msg_ctx_t *rm_msg_ctx,
-    sandesha2_storage_mgr_t *storage_mgr,
-    sandesha2_seq_property_mgr_t *seq_prop_mgr,
-    sandesha2_sender_mgr_t *sender_mgr)
-{
-    axis2_bool_t drop = AXIS2_FALSE;
-    
-    AXIS2_PARAM_CHECK(env->error, rm_msg_ctx, AXIS2_FALSE);
-    AXIS2_PARAM_CHECK(env->error, storage_mgr, AXIS2_FALSE);
-    
-    if(SANDESHA2_MSG_TYPE_APPLICATION == sandesha2_msg_ctx_get_msg_type(
-        rm_msg_ctx, env))
-    {
-        sandesha2_seq_t *sequence = NULL;
-        long msg_no = -1;
-        axis2_char_t *seq_id = NULL;
-        
-        sequence = sandesha2_msg_ctx_get_sequence(rm_msg_ctx, env);
-        if(sequence)
-        {
-            seq_id = sandesha2_identifier_get_identifier(
-                sandesha2_seq_get_identifier(sequence, env), env);
-            msg_no = 
sandesha2_msg_number_get_msg_num(sandesha2_seq_get_msg_num(
-                sequence, env), env);
-        }
-        if(seq_id && 0 < msg_no)
-        {
-            sandesha2_seq_property_bean_t *rcvd_msgs_bean = NULL;
-            
-            if(seq_prop_mgr)
-                rcvd_msgs_bean = 
sandesha2_seq_property_mgr_retrieve(seq_prop_mgr,
-                    env, seq_id, SANDESHA2_SEQ_PROP_SERVER_COMPLETED_MESSAGES);
-            if(rcvd_msgs_bean)
-            {
-                axis2_char_t *rcvd_msgs_str = NULL;
-                axutil_array_list_t *msg_no_list = NULL;
-                int i = 0, size = 0;
-                
-                rcvd_msgs_str = sandesha2_seq_property_bean_get_value(
-                        rcvd_msgs_bean, env);
-                msg_no_list = sandesha2_utils_get_array_list_from_string(env,
-                        rcvd_msgs_str);
-                if(msg_no_list)
-                    size = axutil_array_list_size(msg_no_list, env);
-                for(i = 0; i < size; i++)
-                {
-                    axis2_char_t *temp = NULL;
-                    
-                    temp = axutil_array_list_get(msg_no_list, env, i);
-                    if(atol(temp) == msg_no)
-                        drop = AXIS2_TRUE;
-                }
-            }
-            if(!drop)
-            {
-                axiom_soap_body_t *soap_body = NULL;
-                axiom_node_t *body_node = NULL;
-                axiom_element_t *body_element = NULL;
-                axiom_children_iterator_t *children_iterator = NULL;
-                axis2_bool_t empty_body = AXIS2_FALSE;
-            
-                soap_body = axiom_soap_envelope_get_body(
-                    sandesha2_msg_ctx_get_soap_envelope(rm_msg_ctx, env), 
-                    env);
-                body_node = axiom_soap_body_get_base_node(soap_body, env);
-                body_element = axiom_node_get_data_element(body_node, env);
-                children_iterator = axiom_element_get_children(body_element, 
env, 
-                    body_node);
-                if(!axiom_children_iterator_has_next(children_iterator, env))
-                    empty_body = AXIS2_TRUE;
-                if(empty_body)
-                {
-                    axis2_char_t *rcvd_msgs_str1 = NULL;
-                    axis2_char_t *bean_value = NULL;
-                    axis2_char_t msg_no_str[32];
-                    sandesha2_msg_processor_t *app_msg_processor = NULL;
-                    
-                    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[sandesha2] Empty 
"
-                        "body last msg recieved");
-                    drop = AXIS2_TRUE;
-                    if(!rcvd_msgs_bean)
-                    {
-                        rcvd_msgs_bean = 
sandesha2_seq_property_bean_create_with_data
-                            (env, seq_id, 
-                            SANDESHA2_SEQ_PROP_SERVER_COMPLETED_MESSAGES, "");
-                        sandesha2_seq_property_mgr_insert(seq_prop_mgr, env,
-                            rcvd_msgs_bean);
-                    }
-                    rcvd_msgs_str1 = sandesha2_seq_property_bean_get_value(
-                            rcvd_msgs_bean, env);
-                    sprintf(msg_no_str, "%ld", msg_no);
-                    if(rcvd_msgs_str1 && 0 < axutil_strlen(rcvd_msgs_str1))
-                        bean_value = axutil_strcat(env, rcvd_msgs_str1, ",",
-                            msg_no_str, NULL);
-                    else
-                        bean_value = axutil_strdup(env, msg_no_str);
-                    
-                    sandesha2_seq_property_bean_set_value(rcvd_msgs_bean, env,
-                        bean_value);
-                    sandesha2_seq_property_mgr_update(seq_prop_mgr, env, 
-                        rcvd_msgs_bean);
-                    app_msg_processor = 
sandesha2_app_msg_processor_create(env);
-                    sandesha2_app_msg_processor_send_ack_if_reqd(env, 
-                        rm_msg_ctx, bean_value, storage_mgr, sender_mgr, 
-                        seq_prop_mgr);
-                    sandesha2_msg_processor_free(app_msg_processor, env);
-                }
-            }
-        }        
-    } 
-    else if(SANDESHA2_MSG_TYPE_UNKNOWN == sandesha2_msg_ctx_get_msg_type(
-        rm_msg_ctx, env))
-    {
-        axis2_relates_to_t *relates_to = NULL;
-        axis2_conf_ctx_t *conf_ctx = NULL;
-        relates_to = sandesha2_msg_ctx_get_relates_to(rm_msg_ctx, env);
-        if(relates_to)
-        {
-            const axis2_char_t *relates_to_val = NULL;
-            axis2_op_ctx_t *op_ctx = NULL;
-            axis2_op_ctx_t *op_ctx1 = NULL;
-            
-            relates_to_val = axis2_relates_to_get_value(relates_to, env);
-            conf_ctx = 
axis2_msg_ctx_get_conf_ctx(sandesha2_msg_ctx_get_msg_ctx(
-                rm_msg_ctx, env), env);
-            op_ctx = axis2_conf_ctx_get_op_ctx(conf_ctx, env, relates_to_val);
-            op_ctx1 = axis2_msg_ctx_get_op_ctx(sandesha2_msg_ctx_get_msg_ctx(
-                        rm_msg_ctx, env), env);
-            if(!op_ctx && !op_ctx1)
-            {
-                AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[sandesha2] Dropping"
-                        " duplicate RM message");
-                drop = AXIS2_TRUE;
-            }
-        }
-    }
-    if(drop)
-    {
-        sandesha2_msg_ctx_set_paused(rm_msg_ctx, env, AXIS2_TRUE);
-        return AXIS2_TRUE;
-    }
-    return AXIS2_FALSE;
-}
-
-
-static axis2_status_t AXIS2_CALL
-sandesha2_global_in_handler_process_dropped_msg(
-    struct axis2_handler *handler, 
-    const axutil_env_t *env,
-    sandesha2_msg_ctx_t *rm_msg_ctx,
-    sandesha2_storage_mgr_t *storage_mgr,
-    sandesha2_seq_property_mgr_t *seq_prop_mgr,
-    sandesha2_sender_mgr_t *sender_mgr)
-{
-    AXIS2_PARAM_CHECK(env->error, rm_msg_ctx, AXIS2_FALSE);
-    AXIS2_PARAM_CHECK(env->error, storage_mgr, AXIS2_FALSE);
-    
-    if(SANDESHA2_MSG_TYPE_APPLICATION == sandesha2_msg_ctx_get_msg_type(
-        rm_msg_ctx, env))
-    {
-        sandesha2_seq_t *sequence = NULL;
-        axis2_char_t *seq_id = NULL;
-        
-        sequence = sandesha2_msg_ctx_get_sequence(rm_msg_ctx, env);
-        if(sequence)
-            seq_id = sandesha2_identifier_get_identifier(
-                sandesha2_seq_get_identifier(sequence, env), env);
-            
-        if(seq_id)
-        {
-            sandesha2_seq_property_bean_t *rcvd_msgs_bean = NULL;
-            axis2_char_t *rcvd_msgs_str = NULL;
-            sandesha2_msg_processor_t *app_msg_processor = NULL;
-            
-            rcvd_msgs_bean = sandesha2_seq_property_mgr_retrieve(seq_prop_mgr,
-                env, seq_id, SANDESHA2_SEQ_PROP_SERVER_COMPLETED_MESSAGES);
-            if(rcvd_msgs_bean)
-            {
-                rcvd_msgs_str = sandesha2_seq_property_bean_get_value(
-                    rcvd_msgs_bean, env);
-                app_msg_processor = sandesha2_app_msg_processor_create(env);
-                sandesha2_app_msg_processor_send_ack_if_reqd(env, rm_msg_ctx, 
-                    rcvd_msgs_str, storage_mgr, sender_mgr, seq_prop_mgr);
-                sandesha2_msg_processor_free(app_msg_processor, env);
-            }
-        }
-    }
-    return AXIS2_SUCCESS;
-}
 

Modified: webservices/sandesha/trunk/c/src/handlers/sandesha2_in_handler.c
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/c/src/handlers/sandesha2_in_handler.c?rev=631888&r1=631887&r2=631888&view=diff
==============================================================================
--- webservices/sandesha/trunk/c/src/handlers/sandesha2_in_handler.c (original)
+++ webservices/sandesha/trunk/c/src/handlers/sandesha2_in_handler.c Thu Feb 28 
00:23:50 2008
@@ -20,8 +20,13 @@
 #include <axis2_msg_ctx.h>
 #include <axutil_property.h>
 #include <axis2_conf_ctx.h>
+#include <axiom_soap_body.h>
 #include <sandesha2_storage_mgr.h>
 #include <sandesha2_permanent_storage_mgr.h>
+#include <sandesha2_permanent_seq_property_mgr.h>
+#include <sandesha2_permanent_sender_mgr.h>
+#include <sandesha2_seq_property_mgr.h>
+#include <sandesha2_sender_mgr.h>
 #include <sandesha2_msg_ctx.h>
 #include <sandesha2_msg_processor.h>
 #include <sandesha2_ack_msg_processor.h>
@@ -38,9 +43,25 @@
     struct axis2_handler *handler, 
     const axutil_env_t *env,
     struct axis2_msg_ctx *msg_ctx);
-                                             
-/******************************************************************************/
                         
+ 
+static axis2_bool_t AXIS2_CALL
+sandesha2_in_handler_drop_if_duplicate(
+    struct axis2_handler *handler, 
+    const axutil_env_t *env,
+    sandesha2_msg_ctx_t *rm_msg_ctx,
+    sandesha2_storage_mgr_t *storage_mgr,
+    sandesha2_seq_property_mgr_t *seq_prop_mgr,
+    sandesha2_sender_mgr_t *sender_mgr);                                       
      
 
+static axis2_status_t AXIS2_CALL
+sandesha2_in_handler_process_dropped_msg(
+    struct axis2_handler *handler, 
+    const axutil_env_t *env,
+    sandesha2_msg_ctx_t *rm_msg_ctx,
+    sandesha2_storage_mgr_t *storage_mgr,
+    sandesha2_seq_property_mgr_t *seq_prop_mgr,
+    sandesha2_sender_mgr_t *sender_mgr);
+                                            
 AXIS2_EXTERN axis2_handler_t* AXIS2_CALL
 sandesha2_in_handler_create(
     const axutil_env_t *env, 
@@ -48,8 +69,6 @@
 {
     axis2_handler_t *handler = NULL;
     
-    AXIS2_ENV_CHECK(env, NULL);
-    
     handler = axis2_handler_create(env);
     if (!handler)
     {
@@ -81,16 +100,24 @@
     sandesha2_msg_processor_t *msg_processor = NULL;
     sandesha2_seq_ack_t *seq_ack = NULL;
     sandesha2_ack_requested_t *ack_requested = NULL;
+    sandesha2_storage_mgr_t *storage_mgr = NULL;
+    sandesha2_seq_property_mgr_t *seq_prop_mgr = NULL;
+    sandesha2_sender_mgr_t *sender_mgr = NULL;
+    axis2_char_t *dbname = NULL;
+    axis2_bool_t isolated_last_msg = AXIS2_FALSE;
+    axis2_bool_t dropped = AXIS2_FALSE;
+    axis2_char_t *value = NULL;
+    axutil_property_t *property = NULL;
     AXIS2_PARAM_CHECK(env->error, msg_ctx, AXIS2_FAILURE);
     
     AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,  
-        "[sandesha2] Start: sandesha2_in_handler_invoke");
+        "[sandesha2] Start:sandesha2_in_handler_invoke");
 
     conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
     if(!conf_ctx)
     {
         AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
-            "[sandesha2] Configuration Context is NULL");
+            "[sandesha2]Configuration Context is NULL");
         AXIS2_ERROR_SET(env->error, SANDESHA2_ERROR_CONF_CTX_NULL, 
                 AXIS2_FAILURE);
         return AXIS2_FAILURE;
@@ -107,7 +134,7 @@
     if(str_done && 0 == axutil_strcmp(AXIS2_VALUE_TRUE, str_done))
     {
         AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
-            "[sandesha2] Application processing done");
+            "[sandesha2]Application processing done");
         return AXIS2_SUCCESS;
     }
     temp_prop = axis2_ctx_get_property(ctx, env, SANDESHA2_REINJECTED_MESSAGE);
@@ -117,7 +144,7 @@
     if(reinjected_msg && 0 == axutil_strcmp(AXIS2_VALUE_TRUE, reinjected_msg))
     {
         AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
-            "[sandesha2] Reinjected_msg. So return here");
+            "[sandesha2]Reinjected_msg. So return here");
         return AXIS2_SUCCESS; /* Reinjected Messages are not processed by 
              sandesha2 inflow handlers */
     }
@@ -126,21 +153,38 @@
     if(!svc)
     {
         AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
-                "[sandesha2] Axis2 Service is NULL");
+                "[sandesha2]Axis2 Service is NULL");
         AXIS2_ERROR_SET(env->error, SANDESHA2_ERROR_SVC_NULL, AXIS2_FAILURE);
         return AXIS2_FAILURE;
     }
     rm_msg_ctx = sandesha2_msg_init_init_msg(env, msg_ctx);
-    /*if(!AXIS2_ERROR_GET_STATUS_CODE(env->error))
+    dbname = sandesha2_util_get_dbname(env, conf_ctx);
+    storage_mgr = sandesha2_utils_get_storage_mgr(env, dbname);
+    seq_prop_mgr = sandesha2_permanent_seq_property_mgr_create(env, dbname);
+    sender_mgr = sandesha2_permanent_sender_mgr_create(env, dbname);
+    property = axis2_msg_ctx_get_property(msg_ctx, env, 
+        SANDESHA2_ISOLATED_LAST_MSG);
+    if(property)
+        value = axutil_property_get_value(property, env);
+    if(value && 0 == axutil_strcmp(AXIS2_VALUE_TRUE, value))
+        isolated_last_msg = AXIS2_TRUE;
+    if(!isolated_last_msg)
+        dropped = sandesha2_in_handler_drop_if_duplicate(handler, env, 
+            rm_msg_ctx, storage_mgr, seq_prop_mgr, sender_mgr);
+    if(dropped)
     {
-        // Message should not be sent in an exception situation
-        axis2_msg_ctx_set_paused(msg_ctx, env, AXIS2_TRUE);
-        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
-            "[sandesha2] Cannot initialize the message");
-        AXIS2_ERROR_SET(env->error, SANDESHA2_ERROR_CANNOT_INIT_MSG, 
-                AXIS2_FAILURE);
-        return AXIS2_FAILURE;
-    }*/
+        sandesha2_in_handler_process_dropped_msg(handler, env, 
+            rm_msg_ctx, storage_mgr, seq_prop_mgr, sender_mgr);
+        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+            "[sandesha2]msg_ctx dropped. So return here");
+        if(rm_msg_ctx)
+            sandesha2_msg_ctx_free(rm_msg_ctx, env);
+        if(seq_prop_mgr)
+            sandesha2_seq_property_mgr_free(seq_prop_mgr, env);
+        if(storage_mgr)
+            sandesha2_storage_mgr_free(storage_mgr, env);
+        return AXIS2_SUCCESS;
+    }
     /* 
      * TODO Validate the message
      * sandesha2_msg_validator_validate(env, rm_msg_ctx);
@@ -169,8 +213,210 @@
     }
     if(rm_msg_ctx)
         sandesha2_msg_ctx_free(rm_msg_ctx, env);
+    if(seq_prop_mgr)
+        sandesha2_seq_property_mgr_free(seq_prop_mgr, env);
+    if(storage_mgr)
+        sandesha2_storage_mgr_free(storage_mgr, env);
     AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,  
         "[sandesha2]Exit:sandesha2_in_handler_invoke");
+    return AXIS2_SUCCESS;
+}
+
+static axis2_bool_t AXIS2_CALL
+sandesha2_in_handler_drop_if_duplicate(
+    struct axis2_handler *handler, 
+    const axutil_env_t *env,
+    sandesha2_msg_ctx_t *rm_msg_ctx,
+    sandesha2_storage_mgr_t *storage_mgr,
+    sandesha2_seq_property_mgr_t *seq_prop_mgr,
+    sandesha2_sender_mgr_t *sender_mgr)
+{
+    axis2_bool_t drop = AXIS2_FALSE;
+    
+    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,  
+        "[sandesha2]Entry:sandesha2_in_handler_drop_if_duplicate");
+    AXIS2_PARAM_CHECK(env->error, rm_msg_ctx, AXIS2_FALSE);
+    AXIS2_PARAM_CHECK(env->error, storage_mgr, AXIS2_FALSE);
+    
+    if(SANDESHA2_MSG_TYPE_APPLICATION == sandesha2_msg_ctx_get_msg_type(
+        rm_msg_ctx, env))
+    {
+        sandesha2_seq_t *sequence = NULL;
+        long msg_no = -1;
+        axis2_char_t *seq_id = NULL;
+        
+        sequence = sandesha2_msg_ctx_get_sequence(rm_msg_ctx, env);
+        if(sequence)
+        {
+            seq_id = sandesha2_identifier_get_identifier(
+                sandesha2_seq_get_identifier(sequence, env), env);
+            msg_no = 
sandesha2_msg_number_get_msg_num(sandesha2_seq_get_msg_num(
+                sequence, env), env);
+        }
+        if(seq_id && 0 < msg_no)
+        {
+            sandesha2_seq_property_bean_t *rcvd_msgs_bean = NULL;
+            
+            if(seq_prop_mgr)
+                rcvd_msgs_bean = 
sandesha2_seq_property_mgr_retrieve(seq_prop_mgr,
+                    env, seq_id, SANDESHA2_SEQ_PROP_SERVER_COMPLETED_MESSAGES);
+            if(rcvd_msgs_bean)
+            {
+                axis2_char_t *rcvd_msgs_str = NULL;
+                axutil_array_list_t *msg_no_list = NULL;
+                int i = 0, size = 0;
+                
+                rcvd_msgs_str = sandesha2_seq_property_bean_get_value(
+                        rcvd_msgs_bean, env);
+                msg_no_list = sandesha2_utils_get_array_list_from_string(env,
+                        rcvd_msgs_str);
+                if(msg_no_list)
+                    size = axutil_array_list_size(msg_no_list, env);
+                for(i = 0; i < size; i++)
+                {
+                    axis2_char_t *temp = NULL;
+                    
+                    temp = axutil_array_list_get(msg_no_list, env, i);
+                    if(atol(temp) == msg_no)
+                        drop = AXIS2_TRUE;
+                }
+            }
+            if(!drop)
+            {
+                axiom_soap_body_t *soap_body = NULL;
+                axiom_node_t *body_node = NULL;
+                axiom_element_t *body_element = NULL;
+                axiom_children_iterator_t *children_iterator = NULL;
+                axis2_bool_t empty_body = AXIS2_FALSE;
+            
+                soap_body = axiom_soap_envelope_get_body(
+                    sandesha2_msg_ctx_get_soap_envelope(rm_msg_ctx, env), 
+                    env);
+                body_node = axiom_soap_body_get_base_node(soap_body, env);
+                body_element = axiom_node_get_data_element(body_node, env);
+                children_iterator = axiom_element_get_children(body_element, 
env, 
+                    body_node);
+                if(!axiom_children_iterator_has_next(children_iterator, env))
+                    empty_body = AXIS2_TRUE;
+                if(empty_body)
+                {
+                    axis2_char_t *rcvd_msgs_str1 = NULL;
+                    axis2_char_t *bean_value = NULL;
+                    axis2_char_t msg_no_str[32];
+                    sandesha2_msg_processor_t *app_msg_processor = NULL;
+                    
+                    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+                        "[sandesha2]Empty body last msg recieved");
+                    drop = AXIS2_TRUE;
+                    if(!rcvd_msgs_bean)
+                    {
+                        rcvd_msgs_bean = 
sandesha2_seq_property_bean_create_with_data
+                            (env, seq_id, 
+                            SANDESHA2_SEQ_PROP_SERVER_COMPLETED_MESSAGES, "");
+                        sandesha2_seq_property_mgr_insert(seq_prop_mgr, env,
+                            rcvd_msgs_bean);
+                    }
+                    rcvd_msgs_str1 = sandesha2_seq_property_bean_get_value(
+                            rcvd_msgs_bean, env);
+                    sprintf(msg_no_str, "%ld", msg_no);
+                    if(rcvd_msgs_str1 && 0 < axutil_strlen(rcvd_msgs_str1))
+                        bean_value = axutil_strcat(env, rcvd_msgs_str1, ",",
+                            msg_no_str, NULL);
+                    else
+                        bean_value = axutil_strdup(env, msg_no_str);
+                    
+                    sandesha2_seq_property_bean_set_value(rcvd_msgs_bean, env,
+                        bean_value);
+                    sandesha2_seq_property_mgr_update(seq_prop_mgr, env, 
+                        rcvd_msgs_bean);
+                    app_msg_processor = 
sandesha2_app_msg_processor_create(env);
+                    sandesha2_app_msg_processor_send_ack_if_reqd(env, 
+                        rm_msg_ctx, bean_value, storage_mgr, sender_mgr, 
+                        seq_prop_mgr);
+                    sandesha2_msg_processor_free(app_msg_processor, env);
+                }
+            }
+        }        
+    } 
+    else if(SANDESHA2_MSG_TYPE_UNKNOWN == sandesha2_msg_ctx_get_msg_type(
+        rm_msg_ctx, env))
+    {
+        axis2_relates_to_t *relates_to = NULL;
+        axis2_conf_ctx_t *conf_ctx = NULL;
+        relates_to = sandesha2_msg_ctx_get_relates_to(rm_msg_ctx, env);
+        if(relates_to)
+        {
+            const axis2_char_t *relates_to_val = NULL;
+            axis2_op_ctx_t *op_ctx = NULL;
+            axis2_op_ctx_t *op_ctx1 = NULL;
+            
+            relates_to_val = axis2_relates_to_get_value(relates_to, env);
+            conf_ctx = 
axis2_msg_ctx_get_conf_ctx(sandesha2_msg_ctx_get_msg_ctx(
+                rm_msg_ctx, env), env);
+            op_ctx = axis2_conf_ctx_get_op_ctx(conf_ctx, env, relates_to_val);
+            op_ctx1 = axis2_msg_ctx_get_op_ctx(sandesha2_msg_ctx_get_msg_ctx(
+                        rm_msg_ctx, env), env);
+            if(!op_ctx && !op_ctx1)
+            {
+                AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[sandesha2] Dropping"
+                        " duplicate RM message");
+                drop = AXIS2_TRUE;
+            }
+        }
+    }
+    if(drop)
+    {
+        sandesha2_msg_ctx_set_paused(rm_msg_ctx, env, AXIS2_TRUE);
+        return AXIS2_TRUE;
+    }
+    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI,  
+        "[sandesha2]Exit:sandesha2_in_handler_drop_if_duplicate");
+    return AXIS2_FALSE;
+}
+
+
+static axis2_status_t AXIS2_CALL
+sandesha2_in_handler_process_dropped_msg(
+    struct axis2_handler *handler, 
+    const axutil_env_t *env,
+    sandesha2_msg_ctx_t *rm_msg_ctx,
+    sandesha2_storage_mgr_t *storage_mgr,
+    sandesha2_seq_property_mgr_t *seq_prop_mgr,
+    sandesha2_sender_mgr_t *sender_mgr)
+{
+    AXIS2_PARAM_CHECK(env->error, rm_msg_ctx, AXIS2_FALSE);
+    AXIS2_PARAM_CHECK(env->error, storage_mgr, AXIS2_FALSE);
+    
+    if(SANDESHA2_MSG_TYPE_APPLICATION == sandesha2_msg_ctx_get_msg_type(
+        rm_msg_ctx, env))
+    {
+        sandesha2_seq_t *sequence = NULL;
+        axis2_char_t *seq_id = NULL;
+        
+        sequence = sandesha2_msg_ctx_get_sequence(rm_msg_ctx, env);
+        if(sequence)
+            seq_id = sandesha2_identifier_get_identifier(
+                sandesha2_seq_get_identifier(sequence, env), env);
+            
+        if(seq_id)
+        {
+            sandesha2_seq_property_bean_t *rcvd_msgs_bean = NULL;
+            axis2_char_t *rcvd_msgs_str = NULL;
+            sandesha2_msg_processor_t *app_msg_processor = NULL;
+            
+            rcvd_msgs_bean = sandesha2_seq_property_mgr_retrieve(seq_prop_mgr,
+                env, seq_id, SANDESHA2_SEQ_PROP_SERVER_COMPLETED_MESSAGES);
+            if(rcvd_msgs_bean)
+            {
+                rcvd_msgs_str = sandesha2_seq_property_bean_get_value(
+                    rcvd_msgs_bean, env);
+                app_msg_processor = sandesha2_app_msg_processor_create(env);
+                sandesha2_app_msg_processor_send_ack_if_reqd(env, rm_msg_ctx, 
+                    rcvd_msgs_str, storage_mgr, sender_mgr, seq_prop_mgr);
+                sandesha2_msg_processor_free(app_msg_processor, env);
+            }
+        }
+    }
     return AXIS2_SUCCESS;
 }
 



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

Reply via email to