You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by da...@apache.org on 2009/12/15 07:20:31 UTC

svn commit: r890660 - in /webservices/axis2/trunk/c: include/ samples/server/ src/core/clientapi/ src/core/context/ src/core/deployment/ src/core/receivers/ src/core/transport/http/common/ src/core/transport/http/sender/ src/core/transport/http/server/...

Author: damitha
Date: Tue Dec 15 06:20:29 2009
New Revision: 890660

URL: http://svn.apache.org/viewvc?rev=890660&view=rev
Log:

Adding support for Keep Alive and http session for Axis2/C.

Modified:
    webservices/axis2/trunk/c/include/axis2_http_out_transport_info.h
    webservices/axis2/trunk/c/include/axis2_http_sender.h
    webservices/axis2/trunk/c/include/axis2_http_transport.h
    webservices/axis2/trunk/c/include/axis2_http_transport_utils.h
    webservices/axis2/trunk/c/include/axis2_msg_recv.h
    webservices/axis2/trunk/c/include/axis2_out_transport_info.h
    webservices/axis2/trunk/c/samples/server/axis2.xml
    webservices/axis2/trunk/c/src/core/clientapi/callback_recv.c
    webservices/axis2/trunk/c/src/core/clientapi/op_client.c
    webservices/axis2/trunk/c/src/core/context/conf_ctx.c
    webservices/axis2/trunk/c/src/core/deployment/conf_init.c
    webservices/axis2/trunk/c/src/core/receivers/msg_recv.c
    webservices/axis2/trunk/c/src/core/receivers/raw_xml_in_out_msg_recv.c
    webservices/axis2/trunk/c/src/core/transport/http/common/http_out_transport_info.c
    webservices/axis2/trunk/c/src/core/transport/http/common/http_worker.c
    webservices/axis2/trunk/c/src/core/transport/http/sender/http_client.c
    webservices/axis2/trunk/c/src/core/transport/http/sender/http_sender.c
    webservices/axis2/trunk/c/src/core/transport/http/sender/http_transport_sender.c
    webservices/axis2/trunk/c/src/core/transport/http/server/apache2/apache2_out_transport_info.c
    webservices/axis2/trunk/c/src/core/transport/http/server/apache2/apache2_worker.c
    webservices/axis2/trunk/c/src/core/transport/http/server/apache2/mod_axis2.c
    webservices/axis2/trunk/c/src/core/transport/http/util/http_transport_utils.c
    webservices/axis2/trunk/c/util/include/axutil_env.h
    webservices/axis2/trunk/c/util/include/axutil_error.h
    webservices/axis2/trunk/c/util/include/platforms/unix/axutil_unix.h
    webservices/axis2/trunk/c/util/include/platforms/windows/axutil_windows.h
    webservices/axis2/trunk/c/util/src/env.c
    webservices/axis2/trunk/c/util/src/error.c

Modified: webservices/axis2/trunk/c/include/axis2_http_out_transport_info.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/include/axis2_http_out_transport_info.h?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_http_out_transport_info.h (original)
+++ webservices/axis2/trunk/c/include/axis2_http_out_transport_info.h Tue Dec 15 06:20:29 2009
@@ -36,6 +36,7 @@
 #include <axutil_env.h>
 #include <axis2_http_simple_response.h>
 #include <axis2_out_transport_info.h>
+#include <axis2_transport_receiver.h>
 
 #ifdef __cplusplus
 extern "C"
@@ -50,6 +51,7 @@
     {
         axis2_out_transport_info_t out_transport;
         axis2_http_simple_response_t *response;
+        axis2_transport_receiver_t *server;
         axis2_char_t *encoding;
 
         axis2_status_t(
@@ -65,6 +67,21 @@
                 axis2_http_out_transport_info_t * info,
                 const axutil_env_t * env,
                 const axis2_char_t * encoding);
+        
+        axis2_status_t(
+            AXIS2_CALL
+            * set_cookie_header)(
+                axis2_http_out_transport_info_t * info,
+                const axutil_env_t * env,
+                const axis2_char_t * cookie_header);
+        
+        axis2_status_t(
+            AXIS2_CALL
+            * set_session)(
+                axis2_http_out_transport_info_t * info,
+                const axutil_env_t * env,
+                const axis2_char_t * session_id,
+                const axis2_char_t * session_value);
 
         void(
             AXIS2_CALL
@@ -99,6 +116,31 @@
         const axis2_char_t * encoding);
 
     /**
+     * @param info pointer to info
+     * @param env pointer to environment struct
+     * @param cookie_header pointer to cookie_header
+     */
+    AXIS2_EXTERN axis2_status_t AXIS2_CALL
+
+    axis2_http_out_transport_info_set_cookie_header(
+        axis2_http_out_transport_info_t * info,
+        const axutil_env_t * env,
+        const axis2_char_t * cookie_header);
+     
+    /** @param info pointer to info
+     * @param env pointer to environment struct
+     * @param session_str pointer to session string
+     */
+    AXIS2_EXTERN axis2_status_t AXIS2_CALL
+
+    axis2_http_out_transport_info_set_session(
+        axis2_http_out_transport_info_t * info,
+        const axutil_env_t * env,
+        const axis2_char_t * session_id,
+        const axis2_char_t * session_value);
+
+
+    /**
      * @param out_transport_info pointer to out transport info
      * @param env pointer to environment struct
      * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE
@@ -151,6 +193,27 @@
                 set_content_type)(axis2_http_out_transport_info_t *,
                         const axutil_env_t *,
                         const axis2_char_t *));
+    
+    AXIS2_EXTERN void AXIS2_CALL
+    axis2_http_out_transport_info_set_cookie_header_func(
+        axis2_http_out_transport_info_t * out_transport_info,
+        const axutil_env_t * env,
+        axis2_status_t(AXIS2_CALL
+                *
+                set_cookie_header)(axis2_http_out_transport_info_t *,
+                        const axutil_env_t *,
+                        const axis2_char_t *));
+    
+    AXIS2_EXTERN void AXIS2_CALL
+    axis2_http_out_transport_info_set_session_func(
+        axis2_http_out_transport_info_t * out_transport_info,
+        const axutil_env_t * env,
+        axis2_status_t(AXIS2_CALL
+                *
+                set_session)(axis2_http_out_transport_info_t *,
+                        const axutil_env_t *,
+                        const axis2_char_t *,
+                        const axis2_char_t *));
 
     AXIS2_EXTERN void AXIS2_CALL
     axis2_http_out_transport_info_set_free_func(
@@ -167,6 +230,14 @@
     /** Set char encoding. */
 #define AXIS2_HTTP_OUT_TRANSPORT_INFO_SET_CHAR_ENCODING(out_transport_info,\
                env, encoding) axis2_http_out_transport_info_set_char_encoding(out_transport_info, env, encoding)
+    
+    /** Set cookie_header. */
+#define AXIS2_HTTP_OUT_TRANSPORT_INFO_SET_COOKIE_HEADER(out_transport_info, \
+               env, cookie_header) axis2_http_out_transport_info_set_cookie_header (out_transport_info, env, cookie_header)
+    
+    /** Set session. */
+#define AXIS2_HTTP_OUT_TRANSPORT_INFO_SET_SESSION(out_transport_info, \
+               env, session_id, session_value) axis2_http_out_transport_info_set_session (out_transport_info, env, session_id, session_value)
 
     /** Free. */
 #define AXIS2_HTTP_OUT_TRANSPORT_INFO_FREE(out_transport_info, env)\

Modified: webservices/axis2/trunk/c/include/axis2_http_sender.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/include/axis2_http_sender.h?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_http_sender.h (original)
+++ webservices/axis2/trunk/c/include/axis2_http_sender.h Tue Dec 15 06:20:29 2009
@@ -181,6 +181,17 @@
         const axutil_env_t * env,
         axis2_msg_ctx_t * msg_ctx);
 
+    AXIS2_EXTERN void AXIS2_CALL
+    axis2_http_sender_set_keep_alive(
+        axis2_http_sender_t * sender,
+        const axutil_env_t * env,
+        axis2_bool_t keep_alive);
+
+    AXIS2_EXTERN axis2_bool_t AXIS2_CALL
+    axis2_http_sender_get_keep_alive(
+        axis2_http_sender_t * sender,
+        const axutil_env_t * env);
+
     /**
      * @param env pointer to environment struct
      */

Modified: webservices/axis2/trunk/c/include/axis2_http_transport.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/include/axis2_http_transport.h?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_http_transport.h (original)
+++ webservices/axis2/trunk/c/include/axis2_http_transport.h Tue Dec 15 06:20:29 2009
@@ -659,6 +659,8 @@
      */
     #define AXIS2_HTTP_HEADER_CONNECTION "Connection"
 
+#define AXIS2_HTTP_CONNECTION_MAP "connection_map"
+
     /**
      * HEADER_CONNECTION_CLOSE
      */
@@ -1002,8 +1004,19 @@
      */
     #define AXIS2_TRANSPORT_HEADER_PROPERTY "HTTP_HEADER_PROPERTY"
 
+    /**
+     * Default session duration
+     */
+#define AXIS2_TRANSPORT_SESSION_EXPIRE_DURATION 60 /* seconds */
+    /**
+     * When a service need session it need to set a hash table into message context.
+     */
+#define AXIS2_TRANSPORT_SESSION_TABLE "session-table"
+
+#define AXIS2_TRANSPORT_SESSION_ID "session_id"
+#define AXIS2_TRANSPORT_SESSION_MAP "session_map"
 
-    #define AXIS2_TRANSPORT_URL_HTTPS "HTTPS"
+#define AXIS2_TRANSPORT_URL_HTTPS "HTTPS"
 
     #define AXIS2_Q_MARK_STR "?"
 

Modified: webservices/axis2/trunk/c/include/axis2_http_transport_utils.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/include/axis2_http_transport_utils.h?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_http_transport_utils.h (original)
+++ webservices/axis2/trunk/c/include/axis2_http_transport_utils.h Tue Dec 15 06:20:29 2009
@@ -128,6 +128,71 @@
 		
 	}axis2_http_transport_out_t;
 
+    /**
+     * size of the key stored in the session file
+     */
+    #define AXIS2_TRANSPORT_SESSION_KEY_SIZE 64 
+    /**
+     * size of the value stored in the session file
+     */
+    #define AXIS2_TRANSPORT_SESSION_VALUE_SIZE 256
+    typedef struct axis2_session_file_record
+    {
+        axis2_char_t key[AXIS2_TRANSPORT_SESSION_KEY_SIZE];
+        axis2_char_t value[AXIS2_TRANSPORT_SESSION_VALUE_SIZE];
+    } axis2_session_file_record_t;
+
+    /**
+     * This will retrieve the session table, set by a service or a module and store it in a session 
+     * file named with the unique session id, generated here in. Then it return the Set-Cookie http 
+     * header with value containing session id and session expire time.
+     * @param env, environments
+     * @param msg_ctx
+     * @return cookie_header
+     */
+    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+    axis2_http_transport_utils_get_session(
+            const axutil_env_t *env, 
+            axis2_msg_ctx_t *msg_ctx);
+
+    /**
+     * When the transport receive a Cookie header it calls this function. This will retrieve the
+     * stored session info from the file related to the id value of the cookie. It also check 
+     * whether the session has timeout by comparing the session expire time contained in the cookie
+     * value with the expire time contained in the file. If session expired then it return nothing. 
+     * If session is still valid it put the values in a hash table and set it into message context.
+     * @param env, environments
+     * @param id
+     * @param msg_ctx
+     */
+    AXIS2_EXTERN void AXIS2_CALL
+    axis2_http_transport_utils_set_session(
+            const axutil_env_t *env, 
+            axis2_msg_ctx_t *msg_ctx,
+            axis2_char_t *session_str);
+
+    /**
+     * After receiving Set-Cookie header in client side store it
+     * @param env, environments
+     * @param msg_ctx  
+     * @param cookie 
+     */
+    AXIS2_EXTERN void AXIS2_CALL
+    axis2_http_transport_utils_store_cookie(
+            const axutil_env_t *env, 
+            axis2_msg_ctx_t *msg_ctx, 
+            axis2_char_t *cookie);
+
+    /** 
+     * Read from cookie store before sending from client side
+     * @param env, environments 
+     * @param msg_ctx
+     * @return cookie string
+     */
+    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+    axis2_http_transport_utils_read_from_cookie_store(
+            const axutil_env_t *env, 
+            axis2_msg_ctx_t *msg_ctx);
 
 	/** 
 	 * Initialize the axis2_http_tranport_in_t. Before using this structure users should 
@@ -407,6 +472,11 @@
         const axutil_env_t *env,
         axutil_array_list_t *mime_parts);
 
+    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+    axis2_http_transport_utils_get_session_id_from_cookie(
+        const axutil_env_t *env,
+        axis2_char_t *cookie);
+
 
 
     /** @} */

Modified: webservices/axis2/trunk/c/include/axis2_msg_recv.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/include/axis2_msg_recv.h?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_msg_recv.h (original)
+++ webservices/axis2/trunk/c/include/axis2_msg_recv.h Tue Dec 15 06:20:29 2009
@@ -146,12 +146,12 @@
      * @param msg_ctx pointer to message context
      * @return service skeleton object
      */
-    AXIS2_EXTERN axis2_svc_skeleton_t *AXIS2_CALL
+    /*AXIS2_EXTERN axis2_svc_skeleton_t *AXIS2_CALL
 
     axis2_msg_recv_get_impl_obj(
         axis2_msg_recv_t * msg_recv,
         const axutil_env_t * env,
-        struct axis2_msg_ctx *msg_ctx);
+        struct axis2_msg_ctx *msg_ctx);*/
 
     /**
      * Set the application scope

Modified: webservices/axis2/trunk/c/include/axis2_out_transport_info.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/include/axis2_out_transport_info.h?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_out_transport_info.h (original)
+++ webservices/axis2/trunk/c/include/axis2_out_transport_info.h Tue Dec 15 06:20:29 2009
@@ -60,6 +60,21 @@
                 axis2_out_transport_info_t * info,
                 const axutil_env_t * env,
                 const axis2_char_t * encoding);
+        
+        axis2_status_t(
+            AXIS2_CALL
+            * set_cookie_header)(
+                axis2_out_transport_info_t * info,
+                const axutil_env_t * env,
+                const axis2_char_t * cookie_header);
+
+        axis2_status_t(
+            AXIS2_CALL
+            * set_session)(
+                axis2_out_transport_info_t * info,
+                const axutil_env_t * env,
+                const axis2_char_t * session_id,
+                const axis2_char_t * session_value);
 
         void(
             AXIS2_CALL
@@ -80,6 +95,14 @@
     /** Set cahr encoding. */
 #define AXIS2_OUT_TRANSPORT_INFO_SET_CHAR_ENCODING(out_transport_info, \
                env, encoding) ((out_transport_info->ops)->set_char_encoding(out_transport_info, env, encoding))
+    
+    /** Set cookie header. */
+#define AXIS2_OUT_TRANSPORT_INFO_SET_COOKIE_HEADER(out_transport_info, \
+               env, cookie_header) ((out_transport_info->ops)->set_cookie_header(out_transport_info, env, cookie_header))
+    
+    /** Set session. */
+#define AXIS2_OUT_TRANSPORT_INFO_SET_SESSION(out_transport_info, \
+               env, session_id, session_value) ((out_transport_info->ops)->set_session(out_transport_info, env, session_id, session_value))
 
     /** Free. */
 #define AXIS2_OUT_TRANSPORT_INFO_FREE(out_transport_info, env)\

Modified: webservices/axis2/trunk/c/samples/server/axis2.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/samples/server/axis2.xml?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/samples/server/axis2.xml (original)
+++ webservices/axis2/trunk/c/samples/server/axis2.xml Tue Dec 15 06:20:29 2009
@@ -58,6 +58,7 @@
     <transportSender name="http" class="axis2_http_sender">
         <parameter name="PROTOCOL" locked="false">HTTP/1.1</parameter>
         <parameter name="xml-declaration" insert="false"/>
+        <!--parameter name="Keep-Alive" locked="false">true</parameter-->
         <!--parameter name="Transfer-Encoding">chunked</parameter-->
         <!--parameter name="HTTP-Authentication" username="" password="" locked="true"/-->
         <!--parameter name="PROXY" proxy_host="127.0.0.1" proxy_port="8080" proxy_username="" proxy_password="" locked="true"/-->

Modified: webservices/axis2/trunk/c/src/core/clientapi/callback_recv.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/clientapi/callback_recv.c?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/clientapi/callback_recv.c (original)
+++ webservices/axis2/trunk/c/src/core/clientapi/callback_recv.c Tue Dec 15 06:20:29 2009
@@ -107,7 +107,14 @@
         {
             axutil_hash_this(hi, &key, NULL, &val);
             if(key)
+            {
                 AXIS2_FREE(env->allocator, (char *)key);
+            }
+            if(val)
+            {
+                axis2_callback_t *callback = (axis2_callback_t *) val;
+                axis2_callback_free(callback, env);
+            }
 
         }
 

Modified: webservices/axis2/trunk/c/src/core/clientapi/op_client.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/clientapi/op_client.c?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/clientapi/op_client.c (original)
+++ webservices/axis2/trunk/c/src/core/clientapi/op_client.c Tue Dec 15 06:20:29 2009
@@ -641,10 +641,10 @@
     if(!op_client)
         return;
 
-    if(op_client->callback)
+    /*if(op_client->callback)
     {
         axis2_callback_free(op_client->callback, env);
-    }
+    }*/
 
     if(op_client->op_ctx)
     {

Modified: webservices/axis2/trunk/c/src/core/context/conf_ctx.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/context/conf_ctx.c?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/context/conf_ctx.c (original)
+++ webservices/axis2/trunk/c/src/core/context/conf_ctx.c Tue Dec 15 06:20:29 2009
@@ -274,6 +274,7 @@
     const axutil_env_t * env)
 {
     axis2_char_t *rv = NULL;
+    /* Do we need to lock here? - damitha */
     axutil_thread_mutex_lock(conf_ctx->mutex);
     rv = conf_ctx->root_dir;
     axutil_thread_mutex_unlock(conf_ctx->mutex);

Modified: webservices/axis2/trunk/c/src/core/deployment/conf_init.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/deployment/conf_init.c?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/deployment/conf_init.c (original)
+++ webservices/axis2/trunk/c/src/core/deployment/conf_init.c Tue Dec 15 06:20:29 2009
@@ -68,6 +68,7 @@
         AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Creating Axis2 configuration context failed.");
         return NULL;
     }
+    axis2_conf_ctx_set_root_dir(conf_ctx, env, axis2_dep_engine_get_repos_path(dep_engine, env));
 
     conf_ctx_base = axis2_conf_ctx_get_base(conf_ctx, env);
     property = axutil_property_create_with_args(env, 2, 0, 0, is_server_side);
@@ -213,6 +214,8 @@
             "Creating Axis2 configuration context failed");
         return NULL;
     }
+    axis2_conf_ctx_set_root_dir(conf_ctx, env, axis2_dep_engine_get_repos_path(dep_engine, env));
+
     conf_ctx_base = axis2_conf_ctx_get_base(conf_ctx, env);
     property = axutil_property_create_with_args(env, 2, 0, 0, AXIS2_VALUE_FALSE);
     axis2_ctx_set_property(conf_ctx_base, env, AXIS2_IS_SVR_SIDE, property);

Modified: webservices/axis2/trunk/c/src/core/receivers/msg_recv.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/receivers/msg_recv.c?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/receivers/msg_recv.c (original)
+++ webservices/axis2/trunk/c/src/core/receivers/msg_recv.c Tue Dec 15 06:20:29 2009
@@ -255,7 +255,7 @@
     }
 }
 
-AXIS2_EXPORT axis2_svc_skeleton_t *AXIS2_CALL
+/*AXIS2_EXPORT axis2_svc_skeleton_t *AXIS2_CALL
 axis2_msg_recv_get_impl_obj(
     axis2_msg_recv_t * msg_recv,
     const axutil_env_t * env,
@@ -276,7 +276,7 @@
     }
 
     return axis2_msg_recv_make_new_svc_obj(msg_recv, env, msg_ctx);
-}
+}*/
 
 AXIS2_EXPORT axis2_status_t AXIS2_CALL
 axis2_msg_recv_set_scope(

Modified: webservices/axis2/trunk/c/src/core/receivers/raw_xml_in_out_msg_recv.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/receivers/raw_xml_in_out_msg_recv.c?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/receivers/raw_xml_in_out_msg_recv.c (original)
+++ webservices/axis2/trunk/c/src/core/receivers/raw_xml_in_out_msg_recv.c Tue Dec 15 06:20:29 2009
@@ -95,7 +95,7 @@
         "[axis2]Entry:axis2_raw_xml_in_out_msg_recv_invoke_business_logic_sync");
 
     /* get the implementation class for the Web Service */
-    svc_obj = axis2_msg_recv_get_impl_obj(msg_recv, env, msg_ctx);
+    svc_obj = axis2_msg_recv_make_new_svc_obj(msg_recv, env, msg_ctx);
 
     if(!svc_obj)
     {

Modified: webservices/axis2/trunk/c/src/core/transport/http/common/http_out_transport_info.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/common/http_out_transport_info.c?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/common/http_out_transport_info.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/common/http_out_transport_info.c Tue Dec 15 06:20:29 2009
@@ -46,6 +46,30 @@
     return axis2_http_out_transport_info_set_char_encoding(http_transport_info, env, encoding);
 }
 
+axis2_status_t AXIS2_CALL
+axis2_out_transport_info_impl_set_cookie_header(
+    axis2_out_transport_info_t * out_transport_info,
+    const axutil_env_t * env,
+    const axis2_char_t * set_cookie)
+{
+    axis2_http_out_transport_info_t *http_transport_info = NULL;
+    http_transport_info = AXIS2_INTF_TO_IMPL(out_transport_info);
+    return axis2_http_out_transport_info_set_cookie_header(http_transport_info, env, set_cookie);
+}
+
+axis2_status_t AXIS2_CALL
+axis2_out_transport_info_impl_set_session(
+    axis2_out_transport_info_t * out_transport_info,
+    const axutil_env_t * env,
+    const axis2_char_t * session_id,
+    const axis2_char_t * session_value)
+{
+    axis2_http_out_transport_info_t *http_transport_info = NULL;
+    http_transport_info = AXIS2_INTF_TO_IMPL(out_transport_info);
+    return axis2_http_out_transport_info_set_session(http_transport_info, env, session_id, 
+            session_value);
+}
+
 void AXIS2_CALL
 axis2_out_transport_info_impl_free(
     axis2_out_transport_info_t * out_transport_info,
@@ -59,7 +83,10 @@
 
 static const axis2_out_transport_info_ops_t ops_var = {
     axis2_out_transport_info_impl_set_content_type,
-    axis2_out_transport_info_impl_set_char_encoding, axis2_out_transport_info_impl_free };
+    axis2_out_transport_info_impl_set_char_encoding, 
+    axis2_out_transport_info_impl_set_cookie_header, 
+    axis2_out_transport_info_impl_set_session, 
+    axis2_out_transport_info_impl_free };
 
 AXIS2_EXTERN axis2_status_t AXIS2_CALL
 axis2_http_out_transport_info_impl_set_content_type(
@@ -118,6 +145,36 @@
     return AXIS2_SUCCESS;
 }
 
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axis2_http_out_transport_info_impl_set_cookie_header(
+    axis2_http_out_transport_info_t * http_out_transport_info,
+    const axutil_env_t * env,
+    const axis2_char_t * set_cookie)
+{
+    AXIS2_PARAM_CHECK(env->error, set_cookie, AXIS2_FAILURE);
+    if(http_out_transport_info->response)
+    {
+        axis2_http_simple_response_set_header(http_out_transport_info-> response, env,
+            axis2_http_header_create(env, AXIS2_HTTP_HEADER_SET_COOKIE, set_cookie));
+    }
+    return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axis2_http_out_transport_info_impl_set_session(
+    axis2_http_out_transport_info_t * http_out_transport_info,
+    const axutil_env_t * env,
+    const axis2_char_t * session_id,
+    const axis2_char_t * session_value)
+{
+    AXIS2_PARAM_CHECK(env->error, session_id, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, session_value, AXIS2_FAILURE);
+    if(http_out_transport_info->server)
+    {
+        env->set_session_fn((void *) http_out_transport_info->server, session_id, session_value);
+    }
+    return AXIS2_SUCCESS;
+}
 AXIS2_EXTERN void AXIS2_CALL
 axis2_http_out_transport_info_impl_free(
     axis2_http_out_transport_info_t * http_out_transport_info,
@@ -162,11 +219,15 @@
     http_out_transport_info->encoding = NULL;
     http_out_transport_info->set_char_encoding = NULL;
     http_out_transport_info->set_content_type = NULL;
+    http_out_transport_info->set_cookie_header = NULL;
+    http_out_transport_info->set_session = NULL;
     http_out_transport_info->free_function = NULL;
 
     http_out_transport_info->set_char_encoding
         = axis2_http_out_transport_info_impl_set_char_encoding;
     http_out_transport_info->set_content_type = axis2_http_out_transport_info_impl_set_content_type;
+    http_out_transport_info->set_cookie_header = axis2_http_out_transport_info_impl_set_cookie_header;
+    http_out_transport_info->set_session = axis2_http_out_transport_info_impl_set_session;
     http_out_transport_info->free_function = axis2_http_out_transport_info_impl_free;
 
     return http_out_transport_info;
@@ -211,6 +272,26 @@
     return http_out_transport_info->set_char_encoding(http_out_transport_info, env, encoding);
 }
 
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axis2_http_out_transport_info_set_cookie_header(
+    axis2_http_out_transport_info_t * http_out_transport_info,
+    const axutil_env_t * env,
+    const axis2_char_t * set_cookie)
+{
+    return http_out_transport_info->set_cookie_header(http_out_transport_info, env, set_cookie);
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axis2_http_out_transport_info_set_session(
+    axis2_http_out_transport_info_t * http_out_transport_info,
+    const axutil_env_t * env,
+    const axis2_char_t * session_id,
+    const axis2_char_t * session_value)
+{
+    return http_out_transport_info->set_session(http_out_transport_info, env, session_id, 
+            session_value);
+}
+
 AXIS2_EXTERN void AXIS2_CALL
 axis2_http_out_transport_info_set_char_encoding_func(
     axis2_http_out_transport_info_t * out_transport_info,
@@ -236,6 +317,31 @@
 }
 
 AXIS2_EXTERN void AXIS2_CALL
+axis2_http_out_transport_info_set_cookie_header_func(
+    axis2_http_out_transport_info_t * out_transport_info,
+    const axutil_env_t * env,
+    axis2_status_t(AXIS2_CALL *
+        set_cookie_header) (axis2_http_out_transport_info_t *,
+        const axutil_env_t *,
+        const axis2_char_t *))
+{
+    out_transport_info->set_cookie_header = set_cookie_header;
+}
+
+AXIS2_EXTERN void AXIS2_CALL
+axis2_http_out_transport_info_set_session_func(
+    axis2_http_out_transport_info_t * out_transport_info,
+    const axutil_env_t * env,
+    axis2_status_t(AXIS2_CALL *
+        set_session) (axis2_http_out_transport_info_t *,
+        const axutil_env_t *,
+        const axis2_char_t *,
+        const axis2_char_t *))
+{
+    out_transport_info->set_session = set_session;
+}
+
+AXIS2_EXTERN void AXIS2_CALL
 axis2_http_out_transport_info_set_free_func(
     axis2_http_out_transport_info_t * out_transport_info,
     const axutil_env_t * env,

Modified: webservices/axis2/trunk/c/src/core/transport/http/common/http_worker.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/common/http_worker.c?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/common/http_worker.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/common/http_worker.c Tue Dec 15 06:20:29 2009
@@ -144,6 +144,11 @@
     axis2_bool_t request_handled = AXIS2_FALSE;
 
     /* HTTP and Proxy authentication */
+    axis2_char_t *cookie_header_value = NULL;
+    /*axis2_char_t *set_cookie_header_value = NULL;
+    axis2_http_header_t *set_cookie_header = NULL;
+    axis2_http_header_t *connection_header = NULL;*/
+    axis2_http_header_t *cookie_header = NULL;
     axis2_char_t *accept_header_value = NULL;
     axis2_http_header_t *accept_header = NULL;
     axis2_char_t *accept_charset_header_value = NULL;
@@ -226,6 +231,33 @@
     msg_ctx = axis2_msg_ctx_create(env, conf_ctx, in_desc, out_desc);
     axis2_msg_ctx_set_server_side(msg_ctx, env, AXIS2_TRUE);
 
+    cookie_header = axis2_http_simple_request_get_first_header(simple_request, env,
+        AXIS2_HTTP_HEADER_COOKIE);
+    if(cookie_header)
+    {
+        char *session_str = NULL;
+        axis2_char_t *session_id = NULL;
+
+        cookie_header_value = axis2_http_header_get_value(cookie_header, env);
+        session_id = axis2_http_transport_utils_get_session_id_from_cookie(env, 
+                cookie_header_value);
+        session_str = env->get_session_fn((void *) conf_ctx, session_id);
+        axis2_http_transport_utils_set_session(env, msg_ctx, session_str);
+    }
+    
+    /*connection_header = axis2_http_simple_request_get_first_header(simple_request, env,
+        AXIS2_HTTP_HEADER_CONNECTION);
+    if(connection_header)
+    {
+        axutil_property_t *connection_header_property = NULL;
+        axis2_char_t *connection_header_value = NULL;
+        connection_header_value = axis2_http_header_get_value(connection_header, env);
+        connection_header_property = axutil_property_create_with_args(env, 
+                AXIS2_SCOPE_REQUEST, 0, 0, connection_header_value);
+        axis2_msg_ctx_set_property(msg_ctx, env, AXIS2_HTTP_HEADER_CONNECTION, 
+                connection_header_property);
+    }*/
+    
     /* Server and Peer IP's */
     svr_ip = axis2_simple_http_svr_conn_get_svr_ip(svr_conn, env);
     peer_ip = axis2_simple_http_svr_conn_get_peer_ip(svr_conn, env);
@@ -1779,11 +1811,12 @@
 
             if(0 == axutil_strcasecmp(value, AXIS2_HTTP_HEADER_CONNECTION_KEEPALIVE))
             {
-                axis2_http_header_t *header = axis2_http_header_create(env,
+                /* Comment these until keep alive support is completed for simple Axis2/C server */
+                /*axis2_http_header_t *header = axis2_http_header_create(env,
                     AXIS2_HTTP_HEADER_CONNECTION, AXIS2_HTTP_HEADER_CONNECTION_KEEPALIVE);
 
                 axis2_http_simple_response_set_header(simple_response, env, header);
-                axis2_simple_http_svr_conn_set_keep_alive(svr_conn, env, AXIS2_TRUE);
+                axis2_simple_http_svr_conn_set_keep_alive(svr_conn, env, AXIS2_TRUE);*/
             }
 
             if(0 == axutil_strcasecmp(value, AXIS2_HTTP_HEADER_CONNECTION_CLOSE))
@@ -1799,9 +1832,18 @@
         { /* Connection Header not available */
             axis2_char_t *http_version = NULL;
             http_version = axis2_http_simple_response_get_http_version(simple_response, env);
-            if(http_version && axutil_strcasecmp(http_version, AXIS2_HTTP_HEADER_PROTOCOL_11))
+            if(http_version && !axutil_strcasecmp(http_version, AXIS2_HTTP_HEADER_PROTOCOL_11))
             {
-                axis2_simple_http_svr_conn_set_keep_alive(svr_conn, env, AXIS2_TRUE);
+                /* Comment these until keep alive support is completed for simple Axis2/C server */
+                /*axis2_simple_http_svr_conn_set_keep_alive(svr_conn, env, AXIS2_TRUE);*/
+                /* Instead add following to always send close connection header to indicate that
+                 * we don't support http keep alive yet in simple Axis2/C server
+                 */
+                axis2_http_header_t *header = axis2_http_header_create(env,
+                    AXIS2_HTTP_HEADER_CONNECTION, AXIS2_HTTP_HEADER_CONNECTION_CLOSE);
+
+                axis2_http_simple_response_set_header(simple_response, env, header);
+                /*axis2_simple_http_svr_conn_set_keep_alive(svr_conn, env, AXIS2_FALSE);*/
             }
             else
             {

Modified: webservices/axis2/trunk/c/src/core/transport/http/sender/http_client.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/sender/http_client.c?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/sender/http_client.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/sender/http_client.c Tue Dec 15 06:20:29 2009
@@ -219,14 +219,20 @@
             return AXIS2_FAILURE;
         }
 
-        client->sockfd = (int)axutil_network_handler_open_socket(env, client->proxy_host,
-            client->proxy_port);
+        if(client->sockfd < 0)
+        {
+            client->sockfd = (int)axutil_network_handler_open_socket(env, client->proxy_host,
+                client->proxy_port);
+        }
     }
     else
     {
         /*Proxy is not enabled*/
 
-        client->sockfd = (int)axutil_network_handler_open_socket(env, host, port);
+        if(client->sockfd < 0)
+        {
+            client->sockfd = (int)axutil_network_handler_open_socket(env, host, port);
+        }
     }
 
     if(client->sockfd < 0)

Modified: webservices/axis2/trunk/c/src/core/transport/http/sender/http_sender.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/sender/http_sender.c?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/sender/http_sender.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/sender/http_sender.c Tue Dec 15 06:20:29 2009
@@ -18,6 +18,7 @@
 #include <axis2_http_sender.h>
 #include <axutil_string.h>
 #include <axis2_http_transport.h>
+#include <axis2_http_transport_utils.h>
 #include <string.h>
 #include <axiom_output.h>
 #include <axis2_op_ctx.h>
@@ -50,6 +51,7 @@
     axiom_output_t *om_output;
     axis2_http_client_t *client;
     axis2_bool_t is_soap;
+    axis2_bool_t keep_alive;
 };
 
 #ifndef AXIS2_LIBCURL_ENABLED
@@ -134,6 +136,12 @@
     axis2_msg_ctx_t * msg_ctx,
     axis2_http_simple_request_t * request,
     axis2_char_t * header_data);
+
+static void
+axis2_http_sender_connection_map_free(
+    void *cm_void,
+    const axutil_env_t *env);
+
 #endif
 
 AXIS2_EXTERN axis2_http_sender_t *AXIS2_CALL
@@ -159,6 +167,7 @@
     sender->om_output = NULL;
     sender->chunked = AXIS2_FALSE;
     sender->client = NULL;
+    sender->keep_alive = AXIS2_TRUE;
 
     return sender;
 }
@@ -242,6 +251,7 @@
     axiom_node_t *body_node = NULL;
     axiom_soap_body_t *soap_body = NULL;
     axis2_bool_t is_soap = AXIS2_TRUE;
+    axis2_bool_t add_keepalive_header = AXIS2_FALSE;
 
     /* http header property to get HTTP headers from msg_ctx and give
      * it to http_sender */
@@ -255,6 +265,9 @@
     axutil_hash_t *transport_attrs = NULL;
     axis2_bool_t write_xml_declaration = AXIS2_FALSE;
     axutil_property_t *property = NULL;/* Property for holding http client */
+    /*axis2_char_t *header_value = NULL;*/
+    axis2_char_t *cookie_str = NULL;
+    axutil_hash_t *connection_map = NULL;
 
     AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_http_sender_send");
     soap_body = axiom_soap_envelope_get_body(out, env);
@@ -317,39 +330,149 @@
         return AXIS2_FAILURE;
     }
 
-    if(sender->client)
+    /*if(sender->client)
     {
         axis2_http_client_free(sender->client, env);
         sender->client = NULL;
+    }*/
+
+    /* This property may be set by the application client. This get the priority over the keep alive 
+     * parameter set in the axix2.xml
+     */
+    property = (axutil_property_t *) axis2_msg_ctx_get_property(msg_ctx, env, 
+            AXIS2_HTTP_HEADER_CONNECTION_KEEPALIVE);
+    if(property)
+    {
+        axis2_char_t *keep_alive_value = NULL;
+
+        keep_alive_value = axutil_property_get_value(property, env);
+        if(!axutil_strcmp(keep_alive_value, AXIS2_VALUE_FALSE))
+        {
+            sender->keep_alive = AXIS2_FALSE;
+        }
     }
 
-    sender->client = axis2_http_client_create(env, url);
+    conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
+    if(conf_ctx)
+    {
+        conf = axis2_conf_ctx_get_conf(conf_ctx, env);
+    }
+
+    /* Because keep alive is not still supported at callback receiver we check
+     * for client side
+     */
+    if(sender->keep_alive && !axis2_msg_ctx_get_server_side(msg_ctx, env))
+    {
+        axutil_property_t *connection_map_property = NULL;
+        axis2_endpoint_ref_t *endpoint = NULL;
+
+        connection_map_property = axis2_conf_ctx_get_property(conf_ctx, env, 
+                AXIS2_HTTP_CONNECTION_MAP);
+        if(!connection_map_property)
+        {
+            connection_map = axutil_hash_make(env);
+            if(!connection_map)
+            {
+                AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+                return AXIS2_FAILURE;
+            }
+            connection_map_property = axutil_property_create_with_args(env, 
+                AXIS2_SCOPE_APPLICATION, 1, axis2_http_sender_connection_map_free, 
+                connection_map);
+            axis2_conf_ctx_set_property(conf_ctx, env, AXIS2_HTTP_CONNECTION_MAP, 
+                connection_map_property);
+
+        }
+        else
+        {
+            connection_map = axutil_property_get_value(connection_map_property, env);
+            if(connection_map)
+            {
+                endpoint = axis2_msg_ctx_get_to(msg_ctx, env);
+                if(endpoint)
+                {
+                    const axis2_char_t *address = NULL;
+
+                    address = axis2_endpoint_ref_get_address(endpoint, env);
+                    if(address)
+                    {
+                        axutil_url_t *url = NULL;
+                        url = axutil_url_parse_string(env, address);
+                        if(url)
+                        {
+                            axis2_char_t *server = axutil_url_get_server(url, env);
+                            if(server)
+                            {
+                                /* We reuse this http client */
+                                sender->client = axutil_hash_get(connection_map, server, 
+                                    AXIS2_HASH_KEY_STRING);
+                            }
+                            axutil_url_free(url, env);
+                        }
+                    }
+                }
+            }
+        }
+        if(!axutil_strcasecmp(sender->http_version, AXIS2_HTTP_HEADER_PROTOCOL_10))
+        {
+            add_keepalive_header = AXIS2_TRUE;
+        }
+    } /* End if sender->keep_alive */
+    if(!sender->client)
+    {
+        sender->client = axis2_http_client_create(env, url);
+        if(sender->client)
+        {
+            axis2_endpoint_ref_t *endpoint = NULL;
+            endpoint = axis2_msg_ctx_get_to(msg_ctx, env);
+            if(endpoint)
+            {
+                const axis2_char_t *address = NULL;
+
+                address = axis2_endpoint_ref_get_address(endpoint, env);
+                if(address)
+                {
+                    axutil_url_t *url = NULL;
+                    url = axutil_url_parse_string(env, address);
+                    if(url)
+                    {
+                        axis2_char_t *server = NULL;
+                        server = axutil_url_get_server(url, env);
+                        if(server)
+                        {
+                            /** 
+                             * We put the client into connection map  so that we can free it once the 
+                             * processing is done at client side. Need to check whether this is neccessary.
+                             */
+                            property = axutil_property_create_with_args(env, AXIS2_SCOPE_REQUEST, 0, 
+                                    axis2_http_client_free_void_arg, sender->client);
+                            axis2_msg_ctx_set_property(msg_ctx, env, AXIS2_HTTP_CLIENT, property);
+                            /**
+                             * If keep alive enabled we store the http client for reuse.
+                             */
+                            if(connection_map)
+                            {
+                                axutil_hash_set(connection_map, axutil_strdup(env, server), 
+                                        AXIS2_HASH_KEY_STRING, sender->client);
+                            }
+                        }
+                        axutil_url_free(url, env);
+                    } /* end if url */
+                } /* end if address */
+            } /* end if endpoint */
+        } /* end if sender->client */
+    } /* end if !sender->client */
     if(!sender->client)
     {
         AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "sender->client creation failed for url %s", url);
         return AXIS2_FAILURE;
     }
 
-    /* We put the client into msg_ctx so that we can free it once the processing
-     * is done at client side
-     */
-    property = axutil_property_create(env);
-    axutil_property_set_scope(property, env, AXIS2_SCOPE_REQUEST);
-    axutil_property_set_free_func(property, env, axis2_http_client_free_void_arg);
-    axutil_property_set_value(property, env, sender->client);
-    axis2_msg_ctx_set_property(msg_ctx, env, AXIS2_HTTP_CLIENT, property);
-
     /* configure proxy settings if we have set so
      */
 
     axis2_http_sender_configure_proxy(sender, env, msg_ctx);
 
-    conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
-    if(conf_ctx)
-    {
-        conf = axis2_conf_ctx_get_conf(conf_ctx, env);
-    }
-
     if(conf)
     {
         trans_desc = axis2_conf_get_transport_out(conf, env, AXIS2_TRANSPORT_ENUM_HTTP);
@@ -584,6 +707,28 @@
     }
 
     request = axis2_http_simple_request_create(env, request_line, NULL, 0, NULL);
+    if(add_keepalive_header)
+    {
+        axis2_http_sender_util_add_header(env, request, AXIS2_HTTP_HEADER_CONNECTION, 
+                AXIS2_HTTP_HEADER_CONNECTION_KEEPALIVE);
+    }
+    /**
+     * If there is a session related stuff handle it
+     */
+    /*header_value = axis2_http_transport_utils_get_session(env, msg_ctx);
+    if(header_value)
+    {
+        axis2_http_sender_util_add_header(env, request, AXIS2_HTTP_HEADER_SET_COOKIE, header_value);
+    }*/
+
+    /**
+     * In the client side sender if a cookie is sent by server add it to the http header
+     */
+    cookie_str = axis2_http_transport_utils_read_from_cookie_store(env, msg_ctx);
+    if(cookie_str)
+    {
+        axis2_http_sender_util_add_header(env, request, AXIS2_HTTP_HEADER_COOKIE, cookie_str);
+    }
 
     /* User-Agent:Axis2/C header */
     axis2_http_sender_util_add_header(env, request, AXIS2_HTTP_HEADER_USER_AGENT, AXIS2_USER_AGENT);
@@ -1292,6 +1437,8 @@
     axutil_property_t *property = NULL;
     axis2_char_t *content_type = NULL;
     int status_code = 0;
+    axis2_bool_t set_cookie_header_present = AXIS2_FALSE;
+    axis2_bool_t connection_header_present = AXIS2_FALSE;
 
     AXIS2_PARAM_CHECK(env->error, msg_ctx, AXIS2_FAILURE);
     AXIS2_PARAM_CHECK(env->error, response, AXIS2_FAILURE);
@@ -1330,8 +1477,139 @@
                     break;
                 }
             }
-        }
+            if(!axutil_strcasecmp(name, AXIS2_HTTP_HEADER_SET_COOKIE))
+            {
+                axis2_char_t *cookie_str = axis2_http_header_get_value(header, env);
+                if(cookie_str)
+                {
+                    axis2_http_transport_utils_store_cookie(env, msg_ctx, cookie_str);
+                }
+                set_cookie_header_present = AXIS2_TRUE;
+            }
+
+            if(!axutil_strcasecmp(name, AXIS2_HTTP_HEADER_CONNECTION))
+            {
+                axis2_char_t *connection_header_value = NULL;
+                axutil_hash_t *connection_map = NULL;
+
+                connection_header_present = AXIS2_TRUE;
+                connection_header_value = axis2_http_header_get_value(header, env);
+
+                /**
+                 * In HTTP1.1 if connection header has value close then drop the connection
+                 */
+                if(connection_header_value && !axutil_strcasecmp(connection_header_value, "close"))
+                {
+                    axis2_endpoint_ref_t *endpoint = NULL;
+                    axutil_property_t *connection_map_property = NULL;
+                    axis2_conf_ctx_t *conf_ctx = NULL;
+
+                    conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
+                    connection_map_property = axis2_conf_ctx_get_property(conf_ctx, env, 
+                            AXIS2_HTTP_CONNECTION_MAP);
+                    if(connection_map_property)
+                    {
+                        connection_map = axutil_property_get_value(connection_map_property, env);
+                        if(connection_map)
+                        {
+                            endpoint = axis2_msg_ctx_get_to(msg_ctx, env);
+                            if(endpoint)
+                            {
+                                const axis2_char_t *address = NULL;
+
+                                address = axis2_endpoint_ref_get_address(endpoint, env);
+                                if(address)
+                                {
+                                    axutil_url_t *url = NULL;
+                                    url = axutil_url_parse_string(env, address);
+                                    if(url)
+                                    {
+                                        axis2_char_t *server = NULL;
+                                        server = axutil_url_get_server(url, env);
+                                        if(server)
+                                        {
+                                            axis2_http_client_t *http_client = NULL;
+                                            /* We remove any connection set for this endpoint */
+                                            http_client = axutil_hash_get(connection_map, server, 
+                                                AXIS2_HASH_KEY_STRING);
+                                            if(http_client)
+                                            {
+                                                /* Dont' free http client here. It is freed by 
+                                                 * op_client 
+                                                 */
+                                                axutil_hash_set(connection_map, server, 
+                                                    AXIS2_HASH_KEY_STRING, NULL);
+                                            }
+                                        }
+                                        axutil_url_free(url, env);
+                                    }
+                                }
+                            } /* End if endpoint */
+                        }
+                    } /* End if connection_map_property */
+                } /* End if connection header has value close */
+            }
+                    } /* End if name of the header present */
     }
+    if(!set_cookie_header_present) /* We need to remove any cookie set previously for this endpoint */
+    {
+        axis2_http_transport_utils_store_cookie(env, msg_ctx, NULL);
+    }
+    if(!connection_header_present) /* No connection header present */ 
+    {
+        /** In HTTP1.0 if there is no keep alive header sent back from server we drop the 
+         * connection 
+         */
+        if(!axutil_strcasecmp(sender->http_version, AXIS2_HTTP_HEADER_PROTOCOL_10))
+        {
+            axis2_endpoint_ref_t *endpoint = NULL;
+            axutil_property_t *connection_map_property = NULL;
+            axutil_hash_t *connection_map = NULL;
+            axis2_conf_ctx_t *conf_ctx = NULL;
+            
+            conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
+            connection_map_property = axis2_conf_ctx_get_property(conf_ctx, env, 
+                    AXIS2_HTTP_CONNECTION_MAP);
+            if(connection_map_property)
+            {
+                connection_map = axutil_property_get_value(connection_map_property, env);
+                if(connection_map)
+                {
+                    endpoint = axis2_msg_ctx_get_to(msg_ctx, env);
+                    if(endpoint)
+                    {
+                        const axis2_char_t *address = NULL;
+
+                        address = axis2_endpoint_ref_get_address(endpoint, env);
+                        if(address)
+                        {
+                            axutil_url_t *url =  NULL;
+                            url = axutil_url_parse_string(env, address);
+                            if(url)
+                            {
+                                axis2_char_t *server = NULL;
+                                server = axutil_url_get_server(url, env);
+                                if(server)
+                                {
+                                    axis2_http_client_t *http_client = NULL;
+                                    /* We remove any connection set for this endpoint */
+                                    http_client = axutil_hash_get(connection_map, server, 
+                                            AXIS2_HASH_KEY_STRING);
+                                    if(http_client)
+                                    {
+                                        /* Dont' free http client here. It is freed by op_client */
+                                        axutil_hash_set(connection_map, server, 
+                                                AXIS2_HASH_KEY_STRING, NULL);
+                                    }
+                                }
+                                axutil_url_free(url, env);
+                            }
+                        } /* end if address */
+                    } /* end if endpoint */
+                }
+            } /* End if connectin_map_property */
+        } /* End if http version 1.0 */
+    } /* End if !connection_header_present */
 
     content_type = (axis2_char_t *)axis2_http_simple_response_get_content_type(response, env);
     if(content_type)
@@ -2960,3 +3238,51 @@
     http_header = axis2_http_header_create(env, header_name, header_value);
     axis2_http_simple_request_add_header(request, env, http_header);
 }
+
+AXIS2_EXTERN void AXIS2_CALL
+axis2_http_sender_set_keep_alive(
+    axis2_http_sender_t * sender,
+    const axutil_env_t * env,
+    axis2_bool_t keep_alive)
+{
+    sender->keep_alive = keep_alive;
+}
+
+AXIS2_EXTERN axis2_bool_t AXIS2_CALL
+axis2_http_sender_get_keep_alive(
+    axis2_http_sender_t * sender,
+    const axutil_env_t * env)
+{
+    return sender->keep_alive;
+}
+
+static void 
+axis2_http_sender_connection_map_free(
+    void *cm_void,
+    const axutil_env_t *env)
+{
+    void *val = NULL;
+    const void *key = NULL;
+    axutil_hash_index_t *hi = NULL;
+    axutil_hash_t *ht = (axutil_hash_t *)cm_void;
+
+    for(hi = axutil_hash_first(ht, env); hi; hi = axutil_hash_next(env, hi))
+    {
+        axis2_char_t *name = NULL;
+        void *value = NULL;
+
+        axutil_hash_this(hi, &key, NULL, &val);
+        name = (axis2_char_t *) key;
+        if(name)
+        {
+            AXIS2_FREE(env->allocator, name);
+        }
+        value = (axis2_http_client_t *) val;
+        if(value)
+        {
+            axis2_http_client_free(value, env);
+        }
+    }
+    axutil_hash_free(ht, env);
+}
+

Modified: webservices/axis2/trunk/c/src/core/transport/http/sender/http_transport_sender.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/sender/http_transport_sender.c?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/sender/http_transport_sender.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/sender/http_transport_sender.c Tue Dec 15 06:20:29 2009
@@ -47,6 +47,7 @@
     axis2_bool_t chunked;
     int connection_timeout;
     int so_timeout;
+    axis2_bool_t keep_alive;
 #ifdef AXIS2_LIBCURL_ENABLED
     axis2_libcurl_t *libcurl;
 #endif
@@ -114,6 +115,7 @@
     transport_sender_impl->chunked = AXIS2_TRUE;
     transport_sender_impl->connection_timeout = AXIS2_HTTP_DEFAULT_CONNECTION_TIMEOUT;
     transport_sender_impl->so_timeout = AXIS2_HTTP_DEFAULT_SO_TIMEOUT;
+    transport_sender_impl->keep_alive = AXIS2_TRUE;
     transport_sender_impl->transport_sender.ops = &http_transport_sender_ops_var;
 
 #ifdef AXIS2_LIBCURL_ENABLED
@@ -309,6 +311,7 @@
             axis2_http_out_transport_info_t *out_info = NULL;
             axis2_bool_t is_soap11 = AXIS2_FALSE;
             axis2_op_ctx_t *op_ctx = NULL;
+            /*axis2_char_t *header_value = NULL;*/
 
             out_info = (axis2_http_out_transport_info_t *)axis2_msg_ctx_get_out_transport_info(
                 msg_ctx, env);
@@ -321,6 +324,11 @@
                 xml_writer = NULL;
                 return AXIS2_FAILURE;
             }
+            /*header_value = axis2_http_transport_utils_get_session(env, msg_ctx);
+            if(header_value)
+            {
+                AXIS2_HTTP_OUT_TRANSPORT_INFO_SET_COOKIE_HEADER(out_info, env, header_value);
+            }*/
 
             is_soap11 = axis2_msg_ctx_get_is_soap_11(msg_ctx, env);
 
@@ -615,6 +623,7 @@
             }
 
             AXIS2_INTF_TO_IMPL(transport_sender)->http_version = axutil_strdup(env, version);
+            AXIS2_INTF_TO_IMPL(transport_sender)->keep_alive = AXIS2_TRUE;
             encoding_param = axutil_param_container_get_param(
                 axis2_transport_out_desc_param_container(out_desc, env), env,
                 AXIS2_HTTP_HEADER_TRANSFER_ENCODING);
@@ -637,6 +646,8 @@
         }
         else if(0 == axutil_strcmp(version, AXIS2_HTTP_HEADER_PROTOCOL_10))
         {
+            axutil_param_t *keepalive_param = NULL;
+
             /* Handling HTTP 1.0 */
             if(AXIS2_INTF_TO_IMPL(transport_sender)->http_version)
             {
@@ -644,6 +655,18 @@
             }
             AXIS2_INTF_TO_IMPL(transport_sender)->http_version = axutil_strdup(env, version);
             AXIS2_INTF_TO_IMPL(transport_sender)->chunked = AXIS2_FALSE;
+            keepalive_param = axutil_param_container_get_param(
+                    axis2_transport_out_desc_param_container(out_desc, env), env, 
+                    AXIS2_HTTP_HEADER_CONNECTION_KEEPALIVE);
+            if(keepalive_param)
+            {
+                axis2_char_t *keepalive_value = NULL;
+                keepalive_value = axutil_param_get_value(keepalive_param, env);
+                if(!axutil_strcmp(keepalive_value, AXIS2_VALUE_FALSE))
+                {
+                    AXIS2_INTF_TO_IMPL(transport_sender)->keep_alive = AXIS2_FALSE;
+                }
+            }
         }
     }
     else
@@ -726,6 +749,7 @@
         AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "http sender creation failed");
         return AXIS2_FAILURE;
     }
+    axis2_http_sender_set_keep_alive(sender, env, AXIS2_INTF_TO_IMPL(transport_sender)->keep_alive);
 
     /* For the MTOM case we should on chunking. And for chunking to work the
      * protocol should be http 1.1*/

Modified: webservices/axis2/trunk/c/src/core/transport/http/server/apache2/apache2_out_transport_info.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/server/apache2/apache2_out_transport_info.c?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/server/apache2/apache2_out_transport_info.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/server/apache2/apache2_out_transport_info.c Tue Dec 15 06:20:29 2009
@@ -114,6 +114,43 @@
     return AXIS2_SUCCESS;
 }
 
+axis2_status_t AXIS2_CALL
+axis2_apache_out_transport_info_set_cookie_header(
+    axis2_http_out_transport_info_t * out_transport_info,
+    const axutil_env_t * env,
+    const axis2_char_t * cookie_header)
+{
+    axis2_apache2_out_transport_info_t *info = NULL;
+
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, cookie_header, AXIS2_FAILURE);
+    info = AXIS2_INTF_TO_IMPL(out_transport_info);
+
+    apr_table_set(info->request->headers_out, AXIS2_HTTP_HEADER_SET_COOKIE, cookie_header);
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_apache_out_transport_info_set_session(
+    axis2_http_out_transport_info_t * out_transport_info,
+    const axutil_env_t * env,
+    const axis2_char_t * session_id,
+    const axis2_char_t * session_value)
+{
+    axis2_apache2_out_transport_info_t *info = NULL;
+    axis2_status_t status = AXIS2_SUCCESS;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, session_id, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, session_value, AXIS2_FAILURE);
+    info = AXIS2_INTF_TO_IMPL(out_transport_info);
+
+    status = env->set_session_fn(info->request, session_id, session_value);
+
+    return status;
+}
+
 axis2_http_out_transport_info_t *AXIS2_CALL
 axis2_apache2_out_transport_info_create(
     const axutil_env_t * env,
@@ -143,6 +180,12 @@
         axis2_apache_out_transport_info_set_char_encoding);
     axis2_http_out_transport_info_set_content_type_func(out_transport_info, env,
         axis2_apache_out_transport_info_set_content_type);
+    axis2_http_out_transport_info_set_cookie_header_func(out_transport_info, env,
+        axis2_apache_out_transport_info_set_cookie_header);
+    axis2_http_out_transport_info_set_session_func(out_transport_info, env,
+        axis2_apache_out_transport_info_set_session);
 
     return out_transport_info;
 }
+
+

Modified: webservices/axis2/trunk/c/src/core/transport/http/server/apache2/apache2_worker.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/server/apache2/apache2_worker.c?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/server/apache2/apache2_worker.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/server/apache2/apache2_worker.c Tue Dec 15 06:20:29 2009
@@ -205,6 +205,8 @@
     axutil_array_list_t *mime_parts = NULL;
     axutil_param_t *callback_name_param = NULL;
     axis2_char_t *mtom_sending_callback_name = NULL;
+    axis2_char_t *cookie = NULL;
+    axis2_char_t *header_value = NULL;
     axis2_status_t status = AXIS2_FAILURE;
 
     AXIS2_ENV_CHECK(env, AXIS2_CRITICAL_FAILURE);
@@ -253,6 +255,18 @@
     msg_ctx = axis2_msg_ctx_create(env, conf_ctx, in_desc, out_desc);
     axis2_msg_ctx_set_server_side(msg_ctx, env, AXIS2_TRUE);
 
+    cookie = (axis2_char_t *)apr_table_get(request->headers_in,
+        AXIS2_HTTP_HEADER_COOKIE);
+    if(cookie)
+    {
+        char *session_str = NULL;
+        axis2_char_t *session_id = NULL;
+
+        session_id = axis2_http_transport_utils_get_session_id_from_cookie(env, cookie);
+        session_str = env->get_session_fn((void *) request, session_id);
+        axis2_http_transport_utils_set_session(env, msg_ctx, session_str);
+    }
+
     if(request->read_chunked == AXIS2_TRUE && 0 == content_length)
     {
         content_length = -1;
@@ -892,6 +906,14 @@
             }
         }
     }
+
+    header_value = axis2_http_transport_utils_get_session(env, msg_ctx);
+    if(header_value)
+    {
+        axis2_http_out_transport_info_t *out_info = NULL;
+        out_info = (axis2_http_out_transport_info_t *)axis2_msg_ctx_get_out_transport_info(msg_ctx, env);
+        AXIS2_HTTP_OUT_TRANSPORT_INFO_SET_COOKIE_HEADER(out_info, env, header_value);
+    }
     if (send_status == DECLINED)
     {
         axis2_bool_t do_rest = AXIS2_FALSE;

Modified: webservices/axis2/trunk/c/src/core/transport/http/server/apache2/mod_axis2.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/server/apache2/mod_axis2.c?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/server/apache2/mod_axis2.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/server/apache2/mod_axis2.c Tue Dec 15 06:20:29 2009
@@ -29,6 +29,8 @@
 #include <axutil_version.h>
 #include <apr_rmm.h>
 #include <apr_shm.h>
+#include <apr_dbd.h>
+#include <mod_dbd.h>
 #include <axis2_http_transport.h>
 
 /* Configuration structure populated by apache2.conf */
@@ -42,7 +44,7 @@
 } axis2_config_rec_t;
 
 axis2_apache2_worker_t *axis2_worker = NULL;
-const axutil_env_t *axutil_env = NULL;
+axutil_env_t *axutil_env = NULL;
 apr_rmm_t* rmm = NULL;
 apr_global_mutex_t *global_mutex = NULL;
 
@@ -119,6 +121,16 @@
 axis2_register_hooks(
     apr_pool_t * p);
 
+char * 
+axis2_get_session(
+        void *req, 
+        const char *id);
+
+axis2_status_t 
+axis2_set_session(
+        void *req, 
+        const char *id,
+        const char *session);
 /***************************End of Function Headers****************************/
 
 static const command_rec axis2_cmds[] = { AP_INIT_TAKE1("Axis2RepoPath", axis2_set_repo_path, NULL,
@@ -128,7 +140,8 @@
     axis2_set_max_log_file_size, NULL, RSRC_CONF, "Axis2/C maximum log file size"),
     AP_INIT_TAKE1("Axis2GlobalPoolSize", axis2_set_global_pool_size, NULL, RSRC_CONF,
         "Axis2/C global pool size"), AP_INIT_TAKE1("Axis2ServiceURLPrefix",
-        axis2_set_svc_url_prefix, NULL, RSRC_CONF, "Axis2/C service URL prifix"), { NULL } };
+        axis2_set_svc_url_prefix, NULL, RSRC_CONF, "Axis2/C service URL prifix"), 
+        { NULL } };
 
 /* Dispatch list for API hooks */
 module AP_MODULE_DECLARE_DATA axis2_module = { STANDARD20_MODULE_STUFF, NULL, /* create per-dir    config structures */
@@ -352,6 +365,8 @@
     thread_env = axutil_env_create_with_error_log_thread_pool(allocator, error, axutil_env->log,
         axutil_env-> thread_pool);
     thread_env->allocator = allocator;
+    thread_env->set_session_fn = axis2_set_session;
+    thread_env->get_session_fn = axis2_get_session;
 
     rv = AXIS2_APACHE2_WORKER_PROCESS_REQUEST(axis2_worker, thread_env, req);
     if(AXIS2_CRITICAL_FAILURE == rv)
@@ -561,6 +576,8 @@
                 "Starting log with log level %d and max log file size %d",
                 conf->log_level, conf->max_log_file_size);
         }
+        axutil_env->set_session_fn = axis2_set_session;
+        axutil_env->get_session_fn = axis2_get_session;
 
         axis2_worker = axis2_apache2_worker_create(axutil_env,
             conf->axis2_repo_path);
@@ -675,6 +692,8 @@
             axis2_version_string());
         AXIS2_LOG_INFO(axutil_env->log, "Starting log with log level %d", conf->log_level);
     }
+    axutil_env->set_session_fn = axis2_set_session;
+    axutil_env->get_session_fn = axis2_get_session;
     axis2_worker = axis2_apache2_worker_create(axutil_env, conf->axis2_repo_path);
     if(!axis2_worker)
     {
@@ -682,6 +701,11 @@
             "[Axis2] Error creating mod_axis2 apache2 worker");
         exit(APEXIT_CHILDFATAL);
     }
+
+    /*ap_dbd_prepare(svr_rec, "SELECT value FROM session WHERE id = %s", "retrieve_session");
+    ap_dbd_prepare(svr_rec, "INSERT INTO session VALUES(?,?)", "insert_session");*/
+
+
     /* If we are initialized we register a clean up as well */
     /* apr_pool_cleanup_register(p, NULL, axis2_shutdown, apr_pool_cleanup_null);*/
 }
@@ -706,3 +730,107 @@
     return APR_SUCCESS;
 }
 
+char * 
+axis2_get_session(
+        void *req, 
+        const char *id)
+{
+    request_rec *request = NULL;
+    apr_status_t rv;
+    const char *dbd_session = NULL;
+    apr_dbd_prepared_t *statement;
+    apr_dbd_results_t *res = NULL;
+    apr_dbd_row_t *row = NULL;
+
+    request = (request_rec *) req;
+    ap_dbd_t *dbd = ap_dbd_acquire(request);
+    if (!dbd) 
+    {
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, request,
+                      "Failed to acquire database connection to look up "
+                      "id '%s'", id);
+        return NULL;
+    }
+
+    statement = apr_hash_get(dbd->prepared, "retrieve_session", APR_HASH_KEY_STRING);
+    if (!statement) 
+    {
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, request,
+                      "A prepared statement could not be found for "
+                      "the key '%s'", "retrieve_session");
+        return NULL;
+    }
+    if (apr_dbd_pvselect(dbd->driver, request->pool, dbd->handle, &res, statement,
+                              0, id, NULL) != 0) 
+    {
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, request,
+                      "Query execution error looking up '%s' "
+                      "in database", id);
+        return NULL;
+    }
+    for (rv = apr_dbd_get_row(dbd->driver, request->pool, res, &row, -1); rv != -1;
+         rv = apr_dbd_get_row(dbd->driver, request->pool, res, &row, -1)) 
+    {
+        if (rv != 0) 
+        {
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, request,
+                          "Error retrieving results while looking up '%s' "
+                          "in database", id);
+            return NULL;
+        }
+        if (!dbd_session) 
+        {
+            dbd_session = apr_dbd_get_entry(dbd->driver, row, 0);
+        }
+        /* we can't break out here or row won't get cleaned up */
+    }
+
+    if (!dbd_session) 
+    {
+        return NULL;
+    }
+
+    return (char *) dbd_session;
+}
+
+axis2_status_t 
+axis2_set_session(
+        void *req, 
+        const char *id,
+        const char *session)
+{
+    request_rec *request = NULL;
+    apr_dbd_prepared_t *statement;
+    int affected_rows = -1;
+
+    request = (request_rec *) req;
+
+    ap_dbd_t *dbd = ap_dbd_acquire(request);
+    if (!dbd) 
+    {
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, request,
+                      "Failed to acquire database connection to insert session for "
+                      "id '%s'", id);
+        return AXIS2_FAILURE;
+    }
+
+    statement = apr_hash_get(dbd->prepared, "insert_session", APR_HASH_KEY_STRING);
+    if (!statement) 
+    {
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, request,
+                      "A prepared statement could not be found for "
+                      "the key '%s'", "insert_session");
+        return AXIS2_FAILURE;
+    }
+    if (apr_dbd_pvquery(dbd->driver, request->pool, dbd->handle, &affected_rows, statement, id, 
+                session, NULL) != 0) 
+    {
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, request,
+                      "Query execution error inserting session for '%s' "
+                      "in database", id);
+        return AXIS2_FAILURE;
+    }
+
+    return AXIS2_SUCCESS;
+}
+

Modified: webservices/axis2/trunk/c/src/core/transport/http/util/http_transport_utils.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/util/http_transport_utils.c?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/util/http_transport_utils.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/util/http_transport_utils.c Tue Dec 15 06:20:29 2009
@@ -193,6 +193,11 @@
     axutil_hash_t * param_map,
     axis2_char_t * method);
 
+AXIS2_EXTERN void AXIS2_CALL
+axis2_http_transport_utils_session_map_free_void_arg(
+    void *sm_void,
+    const axutil_env_t *env);
+
 static axis2_status_t
 axis2_http_transport_utils_send_attachment_using_file(
     const axutil_env_t * env,
@@ -209,6 +214,21 @@
     void *handler,
     void *user_param);
 
+static axis2_char_t *
+axis2_http_transport_utils_copy_key(
+        const axutil_env_t *env, 
+        axis2_char_t *);
+    
+static axis2_char_t *
+axis2_http_transport_utils_copy_value(
+        const axutil_env_t *env, 
+        axis2_char_t *pair);
+
+static void 
+axis2_http_transport_utils_parse_session_str(
+        const axutil_env_t *env, 
+        axis2_char_t *str, 
+        axutil_hash_t *ht);
 /***************************** End of function headers ************************/
 
 AXIS2_EXTERN axis2_status_t AXIS2_CALL
@@ -3398,3 +3418,409 @@
 
     return is_required;
 }
+
+static void 
+axis2_http_transport_utils_parse_session_str(const axutil_env_t *env, axis2_char_t *str, 
+        axutil_hash_t *ht)
+{
+    while (*str)
+    {
+        axis2_char_t *next = axutil_strstr(str, ";");
+        if (next)
+        {
+            axis2_char_t *key = NULL;
+            axis2_char_t *val = NULL;
+            
+
+            /* Get key and value pairs */
+            key = axis2_http_transport_utils_copy_key(env, str);
+            val = axis2_http_transport_utils_copy_value(env, str);
+            axutil_hash_set(ht, key, AXIS2_HASH_KEY_STRING, val);
+
+            /* find next token */
+            str = next + 1;
+        }
+           
+    }
+}
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+axis2_http_transport_utils_get_session(
+        const axutil_env_t *env, 
+        axis2_msg_ctx_t *msg_ctx)
+{
+    axutil_hash_index_t *hi = NULL;
+    void *val = NULL;
+    const void *key = NULL;
+    axutil_hash_t *ht = NULL;
+    axis2_char_t *session_id = NULL;
+    axis2_char_t *time_str = NULL;
+    axis2_char_t *header_value = NULL;
+    axutil_date_time_t *expire_time = NULL;
+    axis2_char_t session_value[256];
+    axis2_http_out_transport_info_t *out_info = NULL;
+    axis2_status_t status = AXIS2_SUCCESS;
+
+    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_http_transport_utils_get_session");
+    ht = axis2_msg_ctx_get_property_value(msg_ctx, env, AXIS2_TRANSPORT_SESSION_TABLE);
+    if(!ht)
+    {
+        axis2_op_ctx_t *op_ctx = NULL;
+        axis2_msg_ctx_t *in_msg_ctx = NULL;
+        op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env);
+        in_msg_ctx = axis2_op_ctx_get_msg_ctx(op_ctx, env, AXIS2_WSDL_MESSAGE_LABEL_IN);
+        ht = axis2_msg_ctx_get_property_value(msg_ctx, env, AXIS2_TRANSPORT_SESSION_TABLE);
+        if(!ht)
+        {
+            return NULL;
+        }
+    }
+    session_id = axutil_hash_get(ht, "id", AXIS2_HASH_KEY_STRING);
+    if(!session_id)
+    {
+        /* Generate session and set it in session table */
+        session_id = axutil_uuid_gen(env);
+        axutil_hash_set(ht, axutil_strdup(env, "id"), AXIS2_HASH_KEY_STRING, axutil_strdup(env, 
+                    session_id));
+
+        /* Generate expire time and set it in session table */
+        expire_time = axutil_date_time_create_with_offset(env, AXIS2_TRANSPORT_SESSION_EXPIRE_DURATION);
+        time_str = axutil_strdup(env, axutil_date_time_serialize_date_time(expire_time, env));
+        axutil_date_time_free(expire_time, env);
+        axutil_hash_set(ht, axutil_strdup(env, "expires"), AXIS2_HASH_KEY_STRING, time_str);
+    
+        sprintf(session_value, "%s", "");
+
+        for(hi = axutil_hash_first(ht, env); hi; hi = axutil_hash_next(env, hi))
+        {
+            axis2_char_t *name = NULL;
+            axis2_char_t *value = NULL;
+            int len = -1;
+
+            axutil_hash_this(hi, &key, NULL, &val);
+            name = (axis2_char_t *) key;
+            value = (axis2_char_t *) val;
+            if(name)
+            {
+                len = axutil_strlen(session_value);
+                sprintf(session_value + len, "%s=", name); 
+                AXIS2_FREE(env->allocator, name);
+            }
+            if(value)
+            {
+                len = axutil_strlen(session_value);
+                sprintf(session_value + len, "%s;", value); 
+                AXIS2_FREE(env->allocator, value);
+            }
+        }
+
+        out_info = (axis2_http_out_transport_info_t *)axis2_msg_ctx_get_out_transport_info(
+            msg_ctx, env);
+        if(!out_info)
+        {
+            AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_OUT_TRNSPORT_INFO_NULL, AXIS2_FAILURE);
+            AXIS2_FREE(env->allocator, header_value);
+            return NULL;
+        }
+        status = AXIS2_HTTP_OUT_TRANSPORT_INFO_SET_SESSION(out_info, env, session_id, session_value);
+        if(status != AXIS2_SUCCESS)
+        {
+            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                    "Inserting session value failed for session id %s", session_id);
+            return NULL;
+        }
+    }
+    else
+    {
+        time_str = axutil_hash_get(ht, "expires", AXIS2_HASH_KEY_STRING);
+    }
+    header_value = AXIS2_MALLOC(env->allocator, 256 * sizeof(axis2_char_t));
+    sprintf(header_value, "ID=%s; expires=%s;", session_id, time_str);
+
+    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_http_transport_utils_get_session");
+    return header_value;
+}
+
+AXIS2_EXTERN void AXIS2_CALL
+axis2_http_transport_utils_set_session(
+        const axutil_env_t *env, 
+        axis2_msg_ctx_t *msg_ctx,
+        axis2_char_t *session_str)
+{
+    axutil_date_time_t *expire_time = NULL;
+    axutil_date_time_t *current_time = NULL;
+    axutil_date_time_comp_result_t result;
+    axis2_char_t *time_str = NULL;
+    axutil_hash_t *ht = NULL;
+    axutil_property_t *property = NULL;
+
+    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_http_tranpsport_utils_set_session");
+
+    /* Check whether session has expired. If so set error and return */
+    ht = axutil_hash_make(env);
+    axis2_http_transport_utils_parse_session_str(env, session_str, ht);
+    time_str = (axis2_char_t *) axutil_hash_get(ht, "time", AXIS2_HASH_KEY_STRING);
+    expire_time = axutil_date_time_create(env);
+    axutil_date_time_deserialize_date_time(expire_time, env, time_str);
+    current_time = axutil_date_time_create(env);
+    result = axutil_date_time_compare(current_time, env, expire_time);
+    axutil_date_time_free(current_time, env);
+    axutil_date_time_free(expire_time, env);
+    if(result == AXIS2_DATE_TIME_COMP_RES_EXPIRED)
+    {
+        axutil_hash_index_t *hi = NULL;
+        void *val = NULL;
+        const void *key = NULL;
+
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Session time out");
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SESSION_TIMEOUT, AXIS2_FAILURE);
+        for(hi = axutil_hash_first(ht, env); hi; hi = axutil_hash_next(env, hi))
+        {
+            axis2_char_t *name = NULL;
+            axis2_char_t *value = NULL;
+
+            axutil_hash_this(hi, &key, NULL, &val);
+            name = (axis2_char_t *) key;
+            if(name)
+            {
+                AXIS2_FREE(env->allocator, name);
+            }
+            value = (axis2_char_t *) val;
+            if(value)
+            {
+                AXIS2_FREE(env->allocator, value);
+            }
+        }
+        axutil_hash_free(ht, env);
+    }
+
+    property = axutil_property_create_with_args(env, 0, AXIS2_TRUE, 0, ht);
+    axis2_msg_ctx_set_property(msg_ctx, env, AXIS2_TRANSPORT_SESSION_TABLE, property);
+    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_http_tranpsport_utils_set_session");
+}
+
+/**
+ * After receiving Set-Cookie header store it
+ */
+AXIS2_EXTERN void AXIS2_CALL
+axis2_http_transport_utils_store_cookie(
+        const axutil_env_t *env, 
+        axis2_msg_ctx_t *msg_ctx, 
+        axis2_char_t *cookie)
+{
+    axis2_conf_ctx_t *conf_ctx = NULL;
+    axutil_property_t *property = NULL;
+    axutil_hash_t *session_map = NULL;
+    axis2_endpoint_ref_t *endpoint = NULL;
+    const axis2_char_t *address = NULL;
+
+    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_http_transport_utils_store_cookie");
+    conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
+    property = axis2_conf_ctx_get_property(conf_ctx, env, AXIS2_TRANSPORT_SESSION_MAP);
+    if(property)
+    {
+        session_map = axutil_property_get_value(property, env);
+    }
+    if(!session_map)
+    {
+        if(!cookie)
+        {
+            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+                    "No session map found and no cookie set. So return");
+            return;
+        }
+        session_map = axutil_hash_make(env);
+        if(session_map)
+        {
+            property = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION, 1, 
+                axis2_http_transport_utils_session_map_free_void_arg, session_map); 
+            axis2_conf_ctx_set_property(conf_ctx, env, AXIS2_TRANSPORT_SESSION_MAP, property);
+        }
+        else
+        {
+            AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+            return;
+        }
+    }
+    endpoint = axis2_msg_ctx_get_to(msg_ctx, env);
+    if(endpoint)
+    {
+        address = axis2_endpoint_ref_get_address(endpoint, env);
+        if(address)
+        {
+            axutil_url_t *url = NULL;
+
+            url = axutil_url_parse_string(env, address);
+            if(url)
+            {
+                axis2_char_t *server = NULL;
+                server = axutil_url_get_server(url, env);
+                if(server)
+                {
+                    if(cookie)
+                    {
+                        axutil_hash_set(session_map, axutil_strdup(env, server), AXIS2_HASH_KEY_STRING, 
+                                axutil_strdup(env, cookie));
+                    }
+                    else /* We remove any cookie set for this endpoint */
+                    {
+                        cookie = axutil_hash_get(session_map, server, AXIS2_HASH_KEY_STRING);
+                        if(cookie)
+                        {
+                            AXIS2_FREE(env->allocator, cookie);
+                        }
+                        axutil_hash_set(session_map, server, AXIS2_HASH_KEY_STRING, NULL);
+                    }
+                }
+                axutil_url_free(url, env);
+            }
+        }
+    }
+
+    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_http_transport_utils_store_cookie");
+}
+
+/* Read from cookie store before sending */
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+axis2_http_transport_utils_read_from_cookie_store(
+        const axutil_env_t *env, 
+        axis2_msg_ctx_t *msg_ctx)
+{
+    axutil_property_t *property = NULL;
+    axutil_hash_t *session_map = NULL;
+    axis2_endpoint_ref_t *endpoint = NULL;
+    const axis2_char_t *address = NULL;
+    axis2_char_t *cookie = NULL;
+    axis2_conf_ctx_t *conf_ctx = NULL;
+
+    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_http_transport_utils_read_from_cookie_store");
+    conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
+    property = axis2_conf_ctx_get_property(conf_ctx, env, AXIS2_TRANSPORT_SESSION_MAP);
+    if(property)
+    {
+        session_map = axutil_property_get_value(property, env);
+    }
+    if(!session_map)
+    {
+        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No session map stored");
+        return NULL;
+    }
+    endpoint = axis2_msg_ctx_get_to(msg_ctx, env);
+    if(endpoint)
+    {
+        address = axis2_endpoint_ref_get_address(endpoint, env);
+        if(address)
+        {
+            axutil_url_t *url = NULL; 
+            url = axutil_url_parse_string(env, address);
+            if(url)
+            {
+                axis2_char_t *server = NULL;
+                server = axutil_url_get_server(url, env);
+                if(server)
+                {
+                    cookie = axutil_hash_get(session_map, server, AXIS2_HASH_KEY_STRING);
+                }
+                axutil_url_free(url, env);
+            }
+            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "cookie:%s", cookie);
+        }
+    }
+    
+    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_http_transport_utils_read_from_cookie_store");
+    return cookie;
+}
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+axis2_http_transport_utils_get_session_id_from_cookie(
+        const axutil_env_t *env,
+        axis2_char_t *cookie)
+{
+    axis2_char_t *next = NULL;
+    axis2_char_t *session_id = NULL;
+
+    next = axutil_strstr(cookie, ";");
+    if (next)
+    {
+        session_id = axis2_http_transport_utils_copy_value(env, cookie);
+    }
+
+    return session_id;
+}
+
+static axis2_char_t *
+axis2_http_transport_utils_copy_key(
+        const axutil_env_t *env, 
+        axis2_char_t *pair)
+{
+    axis2_char_t *p = axutil_strchr(pair, '=');
+    axis2_char_t *ret = NULL;
+
+    if (p)
+    {
+        axis2_char_t c;
+        int len = p - pair;
+        c = pair[len];
+        pair[len] = '\0';
+        ret = axutil_strdup(env, pair);
+        pair[len] = c;
+    }
+
+    return ret;
+}
+
+static axis2_char_t *
+axis2_http_transport_utils_copy_value(
+        const axutil_env_t *env, 
+        axis2_char_t *pair)
+{
+    axis2_char_t *ret = NULL;
+    int len;
+    axis2_char_t c;
+
+    pair = axutil_strchr(pair, '=');
+    if (pair)
+    {
+        pair++;
+        len = axutil_strchr(pair, ';') - pair;
+        c = pair[len];
+        pair[len] = '\0';
+        ret = axutil_strdup(env, pair);
+        pair[len] = c;
+    }
+
+    return ret;
+}
+
+
+AXIS2_EXTERN void AXIS2_CALL
+axis2_http_transport_utils_session_map_free_void_arg(
+    void *sm_void,
+    const axutil_env_t *env)
+{
+    void *val = NULL;
+    const void *key = NULL;
+    axutil_hash_index_t *hi = NULL;
+    axutil_hash_t *ht = (axutil_hash_t *)sm_void;
+
+    for(hi = axutil_hash_first(ht, env); hi; hi = axutil_hash_next(env, hi))
+    {
+        axis2_char_t *name = NULL;
+        axis2_char_t *value = NULL;
+
+        axutil_hash_this(hi, &key, NULL, &val);
+        name = (axis2_char_t *) key;
+        if(name)
+        {
+            AXIS2_FREE(env->allocator, name);
+        }
+        value = (axis2_char_t *) val;
+        if(value)
+        {
+            AXIS2_FREE(env->allocator, value);
+        }
+    }
+    axutil_hash_free(ht, env);
+}
+
+

Modified: webservices/axis2/trunk/c/util/include/axutil_env.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/include/axutil_env.h?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/include/axutil_env.h (original)
+++ webservices/axis2/trunk/c/util/include/axutil_env.h Tue Dec 15 06:20:29 2009
@@ -75,6 +75,9 @@
         axutil_thread_pool_t *thread_pool;
 
         int ref;
+
+        axis2_status_t (*set_session_fn)(void*, const char*, const char*);
+        char * (*get_session_fn)(void*, const char*);
     }
     axutil_env_t;
 

Modified: webservices/axis2/trunk/c/util/include/axutil_error.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/include/axutil_error.h?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/include/axutil_error.h (original)
+++ webservices/axis2/trunk/c/util/include/axutil_error.h Tue Dec 15 06:20:29 2009
@@ -116,6 +116,9 @@
         AXIS2_ERROR_UNSUPPORTED_TYPE,
         /* Options object is not set */
         AXIS2_ERROR_OPTIONS_OBJECT_IS_NOT_SET,
+
+        /* Session Timeout */
+        AXIS2_ERROR_SESSION_TIMEOUT,
         /*
          * Group - core:clientapi:diclient
          */

Modified: webservices/axis2/trunk/c/util/include/platforms/unix/axutil_unix.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/include/platforms/unix/axutil_unix.h?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/include/platforms/unix/axutil_unix.h (original)
+++ webservices/axis2/trunk/c/util/include/platforms/unix/axutil_unix.h Tue Dec 15 06:20:29 2009
@@ -216,6 +216,7 @@
 #define AXIS2_FREAD fread
 #define AXIS2_FWRITE fwrite
 #define AXIS2_FCLOSE fclose
+#define AXIS2_FTELL ftell
 #define AXIS2_ACCESS(zpath,imode) access(zpath,imode)
 #define AXIS2_R_OK R_OK         /* test for read permission */
 #define AXIS2_W_OK W_OK         /* test for write permission */

Modified: webservices/axis2/trunk/c/util/include/platforms/windows/axutil_windows.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/include/platforms/windows/axutil_windows.h?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/include/platforms/windows/axutil_windows.h (original)
+++ webservices/axis2/trunk/c/util/include/platforms/windows/axutil_windows.h Tue Dec 15 06:20:29 2009
@@ -211,6 +211,7 @@
 #define AXIS2_FREAD fread
 #define AXIS2_FWRITE fwrite
 #define AXIS2_FCLOSE fclose
+#define AXIS2_FTELL ftell
 #define AXIS2_ACCESS(zpath,imode) _access(zpath,imode)
 #define AXIS2_R_OK 04           /* test for read permission */
 #define AXIS2_W_OK 02           /* test for write permission */

Modified: webservices/axis2/trunk/c/util/src/env.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/src/env.c?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/src/env.c (original)
+++ webservices/axis2/trunk/c/util/src/env.c Tue Dec 15 06:20:29 2009
@@ -57,6 +57,8 @@
     axutil_error_init();
 
     env->ref = 1;
+    env->get_session_fn = NULL;
+    env->set_session_fn = NULL;
 
     return env;
 }
@@ -90,6 +92,8 @@
     axutil_error_init();
 
     env->ref = 1;
+    env->get_session_fn = NULL;
+    env->set_session_fn = NULL;
 
     return env;
 }
@@ -134,6 +138,8 @@
     axutil_error_init();
 
     env->ref = 1;
+    env->get_session_fn = NULL;
+    env->set_session_fn = NULL;
 
     return env;
 }
@@ -180,6 +186,8 @@
     }
 
     env->ref = 1;
+    env->get_session_fn = NULL;
+    env->set_session_fn = NULL;
 
     return env;
 }

Modified: webservices/axis2/trunk/c/util/src/error.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/src/error.c?rev=890660&r1=890659&r2=890660&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/src/error.c (original)
+++ webservices/axis2/trunk/c/util/src/error.c Tue Dec 15 06:20:29 2009
@@ -71,6 +71,7 @@
     axutil_error_messages[AXIS2_ERROR_UNKNOWN_TRANSPORT] = "Unknown transport";
     axutil_error_messages[AXIS2_ERROR_UNSUPPORTED_TYPE] = "Type is not supported";
     axutil_error_messages[AXIS2_ERROR_OPTIONS_OBJECT_IS_NOT_SET] = "Options object is not set";
+    axutil_error_messages[AXIS2_ERROR_SESSION_TIMEOUT] = "Session Timeout";
     /* core:clientapi:diclient */
 
     /* core:context */