You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ma...@apache.org on 2008/07/08 14:50:49 UTC

svn commit: r674805 - in /webservices/axis2/branches/c/post_1_4_mtom/c: axiom/src/attachments/ src/core/transport/http/common/ src/core/transport/http/sender/ src/core/transport/http/util/

Author: manjula
Date: Tue Jul  8 05:50:49 2008
New Revision: 674805

URL: http://svn.apache.org/viewvc?rev=674805&view=rev
Log:
Fixing some memory leaks. Adding some comments.

Modified:
    webservices/axis2/branches/c/post_1_4_mtom/c/axiom/src/attachments/data_handler.c
    webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/common/http_worker.c
    webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/common/simple_http_svr_conn.c
    webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/sender/http_client.c
    webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/sender/http_transport_sender.c
    webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/util/http_transport_utils.c

Modified: webservices/axis2/branches/c/post_1_4_mtom/c/axiom/src/attachments/data_handler.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/post_1_4_mtom/c/axiom/src/attachments/data_handler.c?rev=674805&r1=674804&r2=674805&view=diff
==============================================================================
--- webservices/axis2/branches/c/post_1_4_mtom/c/axiom/src/attachments/data_handler.c (original)
+++ webservices/axis2/branches/c/post_1_4_mtom/c/axiom/src/attachments/data_handler.c Tue Jul  8 05:50:49 2008
@@ -443,7 +443,7 @@
     
     if (data_handler->data_handler_type == AXIOM_DATA_HANDLER_TYPE_BUFFER)
     {
-        binary_part->part = (axis2_byte_t *)data_handler->buffer;
+        binary_part->part = (axis2_byte_t *)axutil_strdup(env, data_handler->buffer);
         binary_part->part_size = data_handler->buffer_len;
         binary_part->type = AXIOM_MIME_PART_BUFFER;
     }

Modified: webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/common/http_worker.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/common/http_worker.c?rev=674805&r1=674804&r2=674805&view=diff
==============================================================================
--- webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/common/http_worker.c (original)
+++ webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/common/http_worker.c Tue Jul  8 05:50:49 2008
@@ -1918,6 +1918,10 @@
                 {
                     axutil_array_list_t *mime_parts = NULL;
                     mime_parts = axis2_msg_ctx_get_mime_parts(out_msg_ctx, env);
+                    /* If mime_parts is there then that means we send MTOM. So
+                     * in order to send MTOM we are enabling HTTP1.1 and cunk transfer
+                     * encoding */
+
                     if(mime_parts)
                     {
                         axis2_http_header_t *transfer_enc_header = NULL;                        
@@ -1933,6 +1937,8 @@
 
                         axis2_http_simple_response_set_header(response, env,
                                                   transfer_enc_header);
+
+                        /* In the chunking case content-lenght is zero */
                         axis2_http_worker_set_response_headers(http_worker, env, svr_conn,
                                                        simple_request, response,
                                                        0);

Modified: webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/common/simple_http_svr_conn.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/common/simple_http_svr_conn.c?rev=674805&r1=674804&r2=674805&view=diff
==============================================================================
--- webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/common/simple_http_svr_conn.c (original)
+++ webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/common/simple_http_svr_conn.c Tue Jul  8 05:50:49 2008
@@ -381,6 +381,7 @@
         return AXIS2_SUCCESS;
     }
 
+    /* This sending a normal SOAP response without chunk transfer encoding */
     if (AXIS2_FALSE == chuked_encoding && !binary_content)
     {
         axis2_status_t write_stat = AXIS2_FAILURE;
@@ -406,6 +407,9 @@
             return AXIS2_FAILURE;
         }
     }
+    
+    /* In the MTOM case we enable chunking inorder to send the attachment */
+    
     else if(binary_content)
     {
         axutil_http_chunked_stream_t *chunked_stream = NULL;
@@ -433,7 +437,9 @@
         {
             return AXIS2_FAILURE;
         }
-    }    
+    } 
+    
+    /* Sending a normal SOAP response enabling htpp chunking */
     else 
     {    
         axutil_http_chunked_stream_t *chunked_stream = NULL;

Modified: webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/sender/http_client.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/sender/http_client.c?rev=674805&r1=674804&r2=674805&view=diff
==============================================================================
--- webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/sender/http_client.c (original)
+++ webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/sender/http_client.c Tue Jul  8 05:50:49 2008
@@ -33,21 +33,6 @@
 #include "ssl/ssl_stream.h"
 #endif
 
-/*static axis2_status_t
-axis2_http_client_send_mtom_message(
-    axis2_http_client_t * client,
-    const axutil_env_t * env);
-
-static axis2_status_t
-axis2_http_client_send_attachment(
-    const axutil_env_t * env,
-    axutil_http_chunked_stream_t *chunked_stream,
-    FILE *fp,
-    axis2_byte_t *buffer,
-    int buffer_size);
-*/
-
-
 struct axis2_http_client
 {
     int sockfd;
@@ -65,6 +50,8 @@
     axis2_char_t *key_file;
     axis2_char_t *req_body;
     int req_body_size;
+    
+    /* These are for mtom case */
     axutil_array_list_t *mime_parts;
     axis2_bool_t doing_mtom;
 };
@@ -133,6 +120,10 @@
     {
         AXIS2_FREE(env->allocator, http_client->req_body);
     }
+    
+    /* There is no other appropriate place to free the mime_part list when a 
+     * particular client send requests. */
+    
     if (http_client->mime_parts)
     {
         int i = 0;
@@ -165,6 +156,12 @@
     return;
 }
 
+/*This is the main method which writes to the socket in the case of a client 
+ * sends an http_request. Previously this mrthod does not distinguish between a 
+ * mtom request and non mtom request. Because what finally it had was the 
+ * complete buffer with the request. But now MTOM invocations are done 
+ * differently so this method should distinguish those invocations*/
+
 AXIS2_EXTERN axis2_status_t AXIS2_CALL
 axis2_http_client_send(
     axis2_http_client_t * client,
@@ -401,6 +398,8 @@
     {
         axis2_status_t status = AXIS2_SUCCESS;
         axutil_http_chunked_stream_t *chunked_stream = NULL;
+        
+        /* For MTOM we automatically enabled chunking */
         chunked_stream = axutil_http_chunked_stream_create(env, 
                 client->data_stream);
     
@@ -413,7 +412,7 @@
         chunked_stream = NULL;
           
     }
-
+    /* Non MTOM case */
     else if (client->req_body_size > 0 && client->req_body)
     {
         int len = 0;
@@ -444,8 +443,7 @@
         }
         else
         {
-
-            /* Sending HTTP request via chunking */
+            /* Not MTOM but chunking is enabled */
             axutil_http_chunked_stream_t *chunked_stream = NULL;
             chunked_stream = axutil_http_chunked_stream_create(env, client->data_stream);
             status = AXIS2_SUCCESS;
@@ -469,6 +467,7 @@
 
             if (AXIS2_SUCCESS == status)
             {
+                /* Writing the trailing null charactor */
                 axutil_http_chunked_stream_write_last_chunk(chunked_stream, env);
             }
 

Modified: webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/sender/http_transport_sender.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/sender/http_transport_sender.c?rev=674805&r1=674804&r2=674805&view=diff
==============================================================================
--- webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/sender/http_transport_sender.c (original)
+++ webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/sender/http_transport_sender.c Tue Jul  8 05:50:49 2008
@@ -290,6 +290,9 @@
     /* setting SOAP version for OM_OUTPUT.  */
     axiom_output_set_soap11(om_output, env,
                             axis2_msg_ctx_get_is_soap_11(msg_ctx, env));
+    
+    /* This is the case where normal client send the requet using a http_client*/
+    
     if (epr)
     {
         if (axutil_strcmp
@@ -527,13 +530,17 @@
                     axis2_status_t mtom_status = AXIS2_FAILURE;
                     axis2_char_t *content_type = NULL;
                     axutil_array_list_t *mime_parts = NULL;
-                    
+                   
+                    /*Create the attachment related data and put them to an
+                     *arra_list */
                     mtom_status = axiom_output_flush(om_output, env);
                     if(mtom_status == AXIS2_SUCCESS)
                     {
                         mime_parts = axiom_output_get_mime_parts(om_output, env);
                         if(!mime_parts)
                         {
+                            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                            "Unable to create the mime_part list from om_output");
                             return AXIS2_FAILURE;
                         }
                         else
@@ -541,7 +548,7 @@
                             axis2_msg_ctx_set_mime_parts(msg_ctx, env, mime_parts);
                         }
                     }
-
+                    /*om_out put has the details of content_type */
                     content_type =
                         (axis2_char_t *)
                         axiom_output_get_content_type(om_output, env);
@@ -765,7 +772,8 @@
         return AXIS2_FAILURE;
     }
 
-    /* For the MTOM case we should on chunking. */
+    /* For the MTOM case we should on chunking. And for chunking to work the
+     * protocol should be http 1.1*/
 
     if(axis2_msg_ctx_get_doing_mtom(msg_ctx, env))
     {

Modified: webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/util/http_transport_utils.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/util/http_transport_utils.c?rev=674805&r1=674804&r2=674805&view=diff
==============================================================================
--- webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/util/http_transport_utils.c (original)
+++ webservices/axis2/branches/c/post_1_4_mtom/c/src/core/transport/http/util/http_transport_utils.c Tue Jul  8 05:50:49 2008
@@ -394,6 +394,10 @@
         }
     }
 
+    /* when the message contains does not contain pure XML we can't send it 
+     * directly to the parser, First we need to seperate the SOAP part from
+     * the attachment */
+    
     if (strstr(content_type, AXIS2_HTTP_HEADER_ACCEPT_MULTIPART_RELATED))
     {
         /* get mime boundary */
@@ -417,7 +421,8 @@
             int num = 0;
 
             mime_parser = axiom_mime_parser_create(env);
-
+            /* This is the size of the buffer we keep inside mime_parser
+             * when parsing. */
             buffer_size_param = axis2_msg_ctx_get_parameter (msg_ctx,
                                                                env,
                                                                AXIS2_MTOM_BUFFER_SIZE);
@@ -431,7 +436,9 @@
                     axiom_mime_parser_set_buffer_size(mime_parser, env, size);
                 }
             }
-
+            
+            /* We create an array of buffers in order to conatin SOAP data inside
+             * mime_parser. This is the number of sucj buffers */
             max_buffers_param = axis2_msg_ctx_get_parameter (msg_ctx,
                                                                env,
                                                                AXIS2_MTOM_MAX_BUFFERS);
@@ -445,7 +452,8 @@
                     axiom_mime_parser_set_max_buffers(mime_parser, env, num);
                 }
             }
-
+            /* If this paramter is there mime_parser will cached the attachment 
+             * using this callback for large attachments. */    
             callback_name_param = axis2_msg_ctx_get_parameter (msg_ctx,
                                                                    env,
                                                                    AXIS2_MTOM_CACHING_CALLBACK);
@@ -3165,6 +3173,10 @@
         {
             mime_part = (axiom_mime_part_t *)axutil_array_list_get(
                 mime_parts, env, i);
+            
+            /* If it is a buffer just wite it to the wire. This incudes mime_bounadaries,
+             * mime_headers and SOAP */
+            
             if((mime_part->type) == AXIOM_MIME_PART_BUFFER)
             {
                 written = 0;
@@ -3184,6 +3196,10 @@
                     }
                 }
             }
+            
+            /* If it is a file we load a very little portion to memory 
+             * and send it as chunked , we keep on doing this until we find
+             * the end of the file */ 
             else if((mime_part->type) == AXIOM_MIME_PART_FILE)
             {
                 FILE *f = NULL;
@@ -3198,6 +3214,10 @@
                     mime_part->file_name);
                     return AXIS2_FAILURE;
                 }
+                
+                /*If the part_size is less than the defined buffer size then 
+                 *from the first write to the wire we can send the file */
+                
                 if(mime_part->part_size > AXIS2_MTOM_OUTPUT_BUFFER_SIZE)
                 {
                     output_buffer_size = AXIS2_MTOM_OUTPUT_BUFFER_SIZE;
@@ -3210,7 +3230,7 @@
                 output_buffer =  AXIS2_MALLOC(env->allocator, 
                     (output_buffer_size + 1) * sizeof(axis2_char_t));
  
- 
+                /*This is the method responsible for writing to the wire */    
                 status = axis2_http_transport_utils_send_attachment(env, chunked_stream, 
                     f, output_buffer, output_buffer_size);
                 if(status == AXIS2_FAILURE)
@@ -3220,6 +3240,7 @@
             }
             else
             {
+                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Unknown mime_part.");
                 return AXIS2_FAILURE;
             }
             if(status == AXIS2_FAILURE)
@@ -3240,6 +3261,8 @@
     }    
     else
     {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot send the attachment.Mime"
+                "Parts are not set properly.");
         return AXIS2_FAILURE;
     }    
 }
@@ -3259,6 +3282,9 @@
     int written = 0;
     axis2_status_t status = AXIS2_SUCCESS;   
  
+    /*We do not load the whole file to memory. Just load a buffer_size portion
+     *and send it. Keep on doing this until the end of file */
+    
     do
     {
         count = (int)fread(buffer, 1, buffer_size + 1, fp);
@@ -3275,6 +3301,7 @@
             return AXIS2_FAILURE;
         }
 
+        /*Writing the part we loaded to memory to the wire*/
         if(count > 0)
         {
             written = 0;
@@ -3303,7 +3330,10 @@
             }
             fclose(fp);
             return AXIS2_FAILURE;
-        }   
+        }  
+        
+        /*We keep on loading the next part to the same buffer. So need to reset 
+         * te buffer */
         memset(buffer, 0, buffer_size);    
         if(status == AXIS2_FAILURE)
         {