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 sh...@apache.org on 2009/09/02 16:45:11 UTC

svn commit: r810531 [3/3] - in /webservices/axis2/trunk/c/src/core/transport/http: common/ receiver/ server/apache2/ util/

Modified: webservices/axis2/trunk/c/src/core/transport/http/common/simple_http_svr_conn.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/common/simple_http_svr_conn.c?rev=810531&r1=810530&r2=810531&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/common/simple_http_svr_conn.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/common/simple_http_svr_conn.c Wed Sep  2 14:45:10 2009
@@ -32,34 +32,36 @@
     axis2_bool_t keep_alive;
 };
 
+static axis2_char_t *
+axis2_simple_http_svr_conn_read_line(
+    axis2_simple_http_svr_conn_t * svr_conn,
+    const axutil_env_t * env);
+
 AXIS2_EXTERN axis2_simple_http_svr_conn_t *AXIS2_CALL
 axis2_simple_http_svr_conn_create(
     const axutil_env_t * env,
     int sockfd)
 {
     axis2_simple_http_svr_conn_t *svr_conn = NULL;
-
     svr_conn = (axis2_simple_http_svr_conn_t *)AXIS2_MALLOC(env->allocator,
         sizeof(axis2_simple_http_svr_conn_t));
-
     if(!svr_conn)
     {
         AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "server connection failed. Insufficient memory");
         return NULL;
     }
+
     memset((void *)svr_conn, 0, sizeof(axis2_simple_http_svr_conn_t));
     svr_conn->socket = sockfd;
-    svr_conn->stream = NULL;
-    svr_conn->keep_alive = AXIS2_FALSE;
 
     if(-1 != svr_conn->socket)
     {
         svr_conn->stream = axutil_stream_create_socket(env, svr_conn->socket);
         if(!svr_conn->stream)
         {
-            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "socket creation failed, socket %d",
-                (int)sockfd);
-            axis2_simple_http_svr_conn_free((axis2_simple_http_svr_conn_t *)svr_conn, env);
+            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "socket creation failed, socket %d", sockfd);
+            axis2_simple_http_svr_conn_free(svr_conn, env);
             return NULL;
         }
     }
@@ -68,18 +70,11 @@
 
 AXIS2_EXTERN void AXIS2_CALL
 axis2_simple_http_svr_conn_free(
-    axis2_simple_http_svr_conn_t * svr_conn,
+    axis2_simple_http_svr_conn_t *svr_conn,
     const axutil_env_t * env)
 {
-    if(!svr_conn)
-    {
-        return;
-    }
-
     axis2_simple_http_svr_conn_close(svr_conn, env);
     AXIS2_FREE(env->allocator, svr_conn);
-
-    return;
 }
 
 AXIS2_EXTERN axis2_status_t AXIS2_CALL
@@ -148,142 +143,53 @@
     const axutil_env_t * env)
 {
     axis2_char_t* str_line = NULL;
-    axis2_char_t tmp_buf[2048];
-    int read = -1;
-    axis2_bool_t end_of_line = AXIS2_FALSE;
     axis2_bool_t end_of_headers = AXIS2_FALSE;
     axis2_http_request_line_t *request_line = NULL;
     axis2_http_simple_request_t *request = NULL;
 
-    while((read = axutil_stream_peek_socket(svr_conn->stream, env, tmp_buf, 2048 - 1)) > 0)
-    {
-        axis2_char_t *start = tmp_buf;
-        axis2_char_t *end = NULL;
-        tmp_buf[read] = AXIS2_ESC_NULL;
-        end = strstr(tmp_buf, AXIS2_HTTP_CRLF);
-        if(end)
-        {
-            read = axutil_stream_read(svr_conn->stream, env, tmp_buf, end - start + 2);
-            if(read > 0)
-            {
-                axis2_char_t* tmp_str_line = NULL;
-                tmp_buf[read] = AXIS2_ESC_NULL;
-                tmp_str_line = axutil_stracat(env, str_line, tmp_buf);
-                if(tmp_str_line)
-                {
-                    AXIS2_FREE(env->allocator, str_line);
-                    str_line = tmp_str_line;
-                }
-                break;
-            }
-            else
-            {
-                /* read returns 0 or negative value, this could be an error */
-                break;
-            }
-        }
-        else
-        {
-            /* not reached end yet */
-            read = axutil_stream_read(svr_conn->stream, env, tmp_buf, 2048 - 1);
-            if(read > 0)
-            {
-                axis2_char_t* tmp_str_line = NULL;
-                tmp_buf[read] = AXIS2_ESC_NULL;
-                tmp_str_line = axutil_stracat(env, str_line, tmp_buf);
-                if(tmp_str_line)
-                {
-                    AXIS2_FREE(env->allocator, str_line);
-                    str_line = tmp_str_line;
-                }
-            }
-        }
+    /* read first line of the request (which is <HTTP METHOD> <URI> <HTTP VERSION> CRLF */
+    str_line = axis2_simple_http_svr_conn_read_line(svr_conn, env);
+    if(str_line)
+    {
+        request_line = axis2_http_request_line_parse_line(env, str_line);
+        AXIS2_FREE(env->allocator, str_line);
+        str_line = NULL;
     }
 
-    request_line = axis2_http_request_line_parse_line(env, str_line);
-    AXIS2_FREE(env->allocator, str_line);
-    str_line = NULL;
-
     if(!request_line)
     {
         AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_HTTP_HEADER_START_LINE, AXIS2_FAILURE);
         return NULL;
     }
     request = axis2_http_simple_request_create(env, request_line, NULL, 0, svr_conn->stream);
-    /* now read the headers */
-    end_of_line = AXIS2_FALSE;
+
+    /* now read the headers until we find a line only having CRLF */
     while(AXIS2_FALSE == end_of_headers)
     {
-        axis2_bool_t is_read = AXIS2_FALSE;
-        while((read = axutil_stream_peek_socket(svr_conn->stream, env, tmp_buf, 2048 - 1)) > 0)
+        str_line = axis2_simple_http_svr_conn_read_line(svr_conn, env);
+        if(!str_line)
         {
-            axis2_char_t *start = tmp_buf;
-            axis2_char_t *end = NULL;
-            is_read = AXIS2_TRUE;
-            tmp_buf[read] = AXIS2_ESC_NULL;
-            end = strstr(tmp_buf, AXIS2_HTTP_CRLF);
-            if(end)
-            {
-                read = axutil_stream_read(svr_conn->stream, env, tmp_buf, end - start + 2);
-                if(read > 0)
-                {
-                    axis2_char_t* tmp_str_line = NULL;
-                    tmp_buf[read] = AXIS2_ESC_NULL;
-                    tmp_str_line = axutil_stracat(env, str_line, tmp_buf);
-                    if(tmp_str_line)
-                    {
-                        AXIS2_FREE(env->allocator, str_line);
-                        str_line = tmp_str_line;
-                    }
-                    end_of_line = AXIS2_TRUE;
-                    break;
-                }
-                else
-                {
-                    break;
-                }
-            }
-            else
-            {
-                read = axutil_stream_read(svr_conn->stream, env, tmp_buf, 2048 - 1);
-                if(read > 0)
-                {
-                    axis2_char_t* tmp_str_line = NULL;
-                    tmp_buf[read] = AXIS2_ESC_NULL;
-                    tmp_str_line = axutil_stracat(env, str_line, tmp_buf);
-                    if(tmp_str_line)
-                    {
-                        AXIS2_FREE(env->allocator, str_line);
-                        str_line = tmp_str_line;
-                    }
-                }
-            }
-
+            /*if nothing is read, this loop should be broken. Otherwise, going to be endless loop */
+            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "reading http header failed");
+            break;
         }
 
-        if(AXIS2_TRUE == end_of_line)
+        if(0 == axutil_strcmp(str_line, AXIS2_HTTP_CRLF))
         {
-            if(0 == axutil_strcmp(str_line, AXIS2_HTTP_CRLF))
-            {
-                end_of_headers = AXIS2_TRUE;
-            }
-            else
-            {
-                axis2_http_header_t *tmp_header = axis2_http_header_create_by_str(env, str_line);
-                AXIS2_FREE(env->allocator, str_line);
-                str_line = NULL;
-                if(tmp_header)
-                {
-                    axis2_http_simple_request_add_header(request, env, tmp_header);
-                }
-            }
+            /* line contains only CRLF, so should be end of headers */
+            end_of_headers = AXIS2_TRUE;
         }
-        end_of_line = AXIS2_FALSE;
-        if(!is_read)
+        else
         {
-            /*if nothing is read, this loop should be broken. Otherwise, going to be endless loop */
-            break;
+            axis2_http_header_t *tmp_header = axis2_http_header_create_by_str(env, str_line);
+            if(tmp_header)
+            {
+                axis2_http_simple_request_add_header(request, env, tmp_header);
+            }
         }
+
+        AXIS2_FREE(env->allocator, str_line);
+        str_line = NULL;
     }
     return request;
 }
@@ -299,7 +205,7 @@
     axutil_stream_t *response_stream = NULL;
     axis2_char_t *response_body = NULL;
     int body_size = 0;
-    int i = 0;
+
     axis2_http_header_t *enc_header = NULL;
     axis2_bool_t chuked_encoding = AXIS2_FALSE;
     axis2_char_t *status_line = NULL;
@@ -309,65 +215,69 @@
     AXIS2_PARAM_CHECK(env->error, response, AXIS2_FAILURE);
 
     response_writer = axis2_http_response_writer_create(env, svr_conn->stream);
+    if(!response_writer)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot create http response writer");
+        return AXIS2_FAILURE;
+    }
+
     content_type = (axis2_char_t *)axis2_http_simple_response_get_content_type(response, env);
     if(content_type)
     {
-        if(strstr(content_type, AXIS2_HTTP_HEADER_ACCEPT_MULTIPART_RELATED) && strstr(content_type,
-            AXIS2_HTTP_HEADER_ACCEPT_XOP_XML))
+        if(strstr(content_type, AXIS2_HTTP_HEADER_ACCEPT_MULTIPART_RELATED)
+            && strstr(content_type,AXIS2_HTTP_HEADER_ACCEPT_XOP_XML))
+        {
             binary_content = AXIS2_TRUE;
+        }
     }
-    if(!response_writer)
-    {
-        return AXIS2_FAILURE;
-    }
+
     enc_header = axis2_http_simple_response_get_first_header(response, env,
         AXIS2_HTTP_HEADER_TRANSFER_ENCODING);
     if(enc_header)
     {
         axis2_char_t *enc_value = axis2_http_header_get_value(enc_header, env);
-        if(enc_value)
+        if(enc_value && (0 == axutil_strcmp(enc_value, AXIS2_HTTP_HEADER_TRANSFER_ENCODING_CHUNKED)))
         {
-            if(0 == axutil_strcmp(enc_value, AXIS2_HTTP_HEADER_TRANSFER_ENCODING_CHUNKED))
-            {
-                chuked_encoding = AXIS2_TRUE;
-                /* remove the content length header */
-                if(AXIS2_TRUE == axis2_http_simple_response_contains_header(response, env,
-                    AXIS2_HTTP_HEADER_CONTENT_LENGTH))
-                {
-                    axis2_http_simple_response_remove_headers(response, env,
-                        AXIS2_HTTP_HEADER_CONTENT_LENGTH);
-                }
-            }
+            chuked_encoding = AXIS2_TRUE;
+
+            /* remove the content length header */
+            axis2_http_simple_response_remove_headers(response, env,
+                AXIS2_HTTP_HEADER_CONTENT_LENGTH);
         }
     }
+
+    /* print status line */
     status_line = axis2_http_simple_response_get_status_line(response, env);
     if(!status_line)
     {
         AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_INVALID_HTTP_HEADER_START_LINE, AXIS2_FAILURE);
         axis2_http_response_writer_free(response_writer, env);
-        response_writer = NULL;
         return AXIS2_FAILURE;
     }
     axis2_http_response_writer_print_str(response_writer, env, status_line);
-    headers = axis2_http_simple_response_get_headers(response, env);
 
+    headers = axis2_http_simple_response_get_headers(response, env);
     if(headers)
     {
-        for(i = 0; i < axutil_array_list_size(headers, env); i++)
+        int i = 0;
+        int count = axutil_array_list_size(headers, env);
+        for(; i < count; i++)
         {
-            axis2_http_header_t *header = NULL;
-            header = (axis2_http_header_t *)axutil_array_list_get(headers, env, i);
+            axis2_http_header_t *header =
+                (axis2_http_header_t *)axutil_array_list_get(headers, env, i);
             if(header)
             {
-                axis2_char_t *header_ext_form = axis2_http_header_to_external_form(
-                    (axis2_http_header_t *)header, env);
+                axis2_char_t *header_ext_form = axis2_http_header_to_external_form(header, env);
                 axis2_http_response_writer_print_str(response_writer, env, header_ext_form);
                 AXIS2_FREE(env->allocator, header_ext_form);
             }
         }
     }
-    axis2_http_response_writer_println(response_writer, env);
 
+    /* write empty line after http headers */
+    axis2_http_response_writer_print_str(response_writer, env, AXIS2_HTTP_CRLF);
+
+    /* write the body */
     response_stream = axis2_http_simple_response_get_body(response, env);
     if(response_stream)
     {
@@ -379,94 +289,81 @@
 
     if(body_size <= 0 && !binary_content)
     {
+        /* no body available to write. Note that this is not an error. We might want to write only
+         * status information and hence, this is a valid case */
         axis2_http_response_writer_free(response_writer, env);
         return AXIS2_SUCCESS;
     }
 
-    /* This sending a normal SOAP response without chunk transfer encoding */
-    if(AXIS2_FALSE == chuked_encoding && !binary_content)
+    if(!chuked_encoding && !binary_content)
     {
+        /* This sending a normal SOAP response without chunk transfer encoding */
         axis2_status_t write_stat = AXIS2_FAILURE;
-        if(AXIS2_FALSE == binary_content)
-        {
-            write_stat
-                = axis2_http_response_writer_println_str(response_writer, env, response_body);
-        }
-        else
-        {
-            write_stat = axis2_http_response_writer_write_buf(response_writer, env, response_body,
-                0, body_size);
-        }
-
-        if(AXIS2_SUCCESS != write_stat)
+        write_stat = axis2_http_response_writer_println_str(response_writer, env, response_body);
+        if(write_stat != AXIS2_SUCCESS)
         {
             AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_RESPONSE, AXIS2_FAILURE);
             axis2_http_response_writer_free(response_writer, env);
             return AXIS2_FAILURE;
         }
     }
-
-    /* In the MTOM case we enable chunking inorder to send the attachment */
-
-    else if(binary_content)
+    else if(!binary_content)
+    {
+        /* Sending a normal SOAP response enabling http chunking */
+        axutil_http_chunked_stream_t *chunked_stream = NULL;
+        int left = body_size;
+        chunked_stream = axutil_http_chunked_stream_create(env, svr_conn->stream);
+        while(left > 0)
+        {
+            left -= axutil_http_chunked_stream_write(chunked_stream, env, response_body, body_size);
+        }
+        axutil_http_chunked_stream_write_last_chunk(chunked_stream, env);
+        axutil_http_chunked_stream_free(chunked_stream, env);
+    }
+    else
     {
+        /* In the MTOM case we enable chunking in order to send the attachment */
         axutil_http_chunked_stream_t *chunked_stream = NULL;
         axis2_status_t write_stat = AXIS2_FAILURE;
         axutil_array_list_t *mime_parts = NULL;
         axis2_char_t *mtom_sending_callback_name = NULL;
 
         mime_parts = axis2_http_simple_response_get_mime_parts(response, env);
-
-        mtom_sending_callback_name = axis2_http_simple_response_get_mtom_sending_callback_name(
-            response, env);
+        if(!mime_parts)
+        {
+            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No mime parts are given");
+            axis2_http_response_writer_free(response_writer, env);
+            return AXIS2_FAILURE;
+        }
 
         /* If the callback name is not there, then we will check whether there 
          * is any mime_parts which has type callback. If we found then no point 
          * of continuing we should return a failure */
-
+        mtom_sending_callback_name = axis2_http_simple_response_get_mtom_sending_callback_name(
+            response, env);
         if(!mtom_sending_callback_name)
         {
             if(axis2_http_transport_utils_is_callback_required(env, mime_parts))
             {
                 AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Sender callback not specified");
+                axis2_http_response_writer_free(response_writer, env);
                 return AXIS2_FAILURE;
             }
         }
 
         chunked_stream = axutil_http_chunked_stream_create(env, svr_conn->stream);
+        write_stat = axis2_http_transport_utils_send_mtom_message(chunked_stream, env, mime_parts,
+            mtom_sending_callback_name);
+        axutil_http_chunked_stream_free(chunked_stream, env);
 
-        if(mime_parts)
-        {
-            write_stat = axis2_http_transport_utils_send_mtom_message(chunked_stream, env,
-                mime_parts, mtom_sending_callback_name);
-            axutil_http_chunked_stream_free(chunked_stream, env);
-            chunked_stream = NULL;
-
-            if(write_stat == AXIS2_FAILURE)
-            {
-                return write_stat;
-            }
-        }
-        else
+        if(write_stat != AXIS2_SUCCESS)
         {
+            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "writing mime parts failed");
+            axis2_http_response_writer_free(response_writer, env);
             return AXIS2_FAILURE;
         }
     }
 
-    /* Sending a normal SOAP response enabling htpp chunking */
-    else
-    {
-        axutil_http_chunked_stream_t *chunked_stream = NULL;
-        int left = body_size;
-        chunked_stream = axutil_http_chunked_stream_create(env, svr_conn->stream);
-        while(left > 0)
-        {
-            left -= axutil_http_chunked_stream_write(chunked_stream, env, response_body, body_size);
-        }
-        axutil_http_chunked_stream_write_last_chunk(chunked_stream, env);
-        axutil_http_chunked_stream_free(chunked_stream, env);
-    }
-
     axis2_http_response_writer_free(response_writer, env);
     return AXIS2_SUCCESS;
 }
@@ -505,3 +402,94 @@
     return axutil_network_handler_get_peer_ip(env, svr_conn->socket);
 }
 
+static axis2_char_t *
+axis2_simple_http_svr_conn_read_line(
+    axis2_simple_http_svr_conn_t * svr_conn,
+    const axutil_env_t * env)
+{
+    axis2_char_t* str_line = NULL;
+    axis2_char_t tmp_buf[2048];
+    int read = -1;
+
+    /* peek for 2047 characters to verify whether it contains CRLF character */
+    while((read = axutil_stream_peek_socket(svr_conn->stream, env, tmp_buf, 2048 - 1)) > 0)
+    {
+        axis2_char_t *start = tmp_buf;
+        axis2_char_t *end = NULL;
+        tmp_buf[read] = AXIS2_ESC_NULL;
+        end = strstr(tmp_buf, AXIS2_HTTP_CRLF);
+        if(end)
+        {
+            axis2_char_t *buffer = NULL;
+            if(str_line)
+            {
+                /* header is more than 2048 character. this is not a common case, and not optimized
+                 * for performance (reading in a temp buffer and then strcat to get final buffer */
+                buffer = tmp_buf;
+            }
+            else
+            {
+                /* header is less than 2048 characters, this is the common case. So to improve
+                 * the performance, the buffer is malloc and then used to read the stream. */
+                buffer = (axis2_char_t *)AXIS2_MALLOC(env->allocator, end - start + 3);
+            }
+
+            /* read the data including CRLF (hence the size = end - start + 2) */
+            read = axutil_stream_read(svr_conn->stream, env, buffer, end - start + 2);
+            if(read > 0)
+            {
+                buffer[read] = AXIS2_ESC_NULL;
+
+                if(str_line)
+                {
+                    axis2_char_t* tmp_str_line = NULL;
+                    tmp_str_line = axutil_stracat(env, str_line, buffer);
+                    if(tmp_str_line)
+                    {
+                        AXIS2_FREE(env->allocator, str_line);
+                        str_line = tmp_str_line;
+                    }
+                }
+                else
+                {
+                    str_line = buffer;
+                }
+            }
+            else
+            {
+                /* read returns 0 or negative value, this could be an error */
+                if(str_line)
+                {
+                    AXIS2_FREE(env->allocator, str_line);
+                    str_line = NULL;
+                }
+                else
+                {
+                    AXIS2_FREE(env->allocator, buffer);
+                }
+            }
+            break;
+        }
+        else
+        {
+            /* not reached end yet */
+            read = axutil_stream_read(svr_conn->stream, env, tmp_buf, 2048 - 1);
+            if(read > 0)
+            {
+                axis2_char_t* tmp_str_line = NULL;
+                tmp_buf[read] = AXIS2_ESC_NULL;
+                tmp_str_line = axutil_stracat(env, str_line, tmp_buf);
+                if(tmp_str_line)
+                {
+                    if(str_line)
+                    {
+                        AXIS2_FREE(env->allocator, str_line);
+                    }
+                    str_line = tmp_str_line;
+                }
+            }
+        }
+    }
+
+    return str_line;
+}

Modified: webservices/axis2/trunk/c/src/core/transport/http/receiver/http_svr_thread.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/receiver/http_svr_thread.c?rev=810531&r1=810530&r2=810531&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/receiver/http_svr_thread.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/receiver/http_svr_thread.c Wed Sep  2 14:45:10 2009
@@ -243,15 +243,26 @@
 
     socket = arg_list->socket;
     svr_conn = axis2_simple_http_svr_conn_create(thread_env, (int)socket);
+    if(!svr_conn)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "creating simple_http_svr_connection failed");
+        return NULL;
+    }
+
     axis2_simple_http_svr_conn_set_rcv_timeout(svr_conn, thread_env, axis2_http_socket_read_timeout);
+
+    /* read HTTPMethod, URL, HTTP Version and http headers. Leave the remaining in the stream */
     request = axis2_simple_http_svr_conn_read_request(svr_conn, thread_env);
+    if(!request)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Could not create request");
+        return NULL;
+    }
+
     tmp = arg_list->worker;
     status = axis2_http_worker_process_request(tmp, thread_env, svr_conn, request);
     axis2_simple_http_svr_conn_free(svr_conn, thread_env);
-    if(request)
-    {
-        axis2_http_simple_request_free(request, thread_env);
-    }
+    axis2_http_simple_request_free(request, thread_env);
 
     IF_AXIS2_LOG_DEBUG_ENABLED(env->log)
     {

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=810531&r1=810530&r2=810531&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 Wed Sep  2 14:45:10 2009
@@ -353,7 +353,7 @@
             while(token);
         }
         if(accept_charset_record_list && axutil_array_list_size(accept_charset_record_list, env)
-            > 0)
+        > 0)
         {
             axis2_msg_ctx_set_http_accept_charset_record_list(msg_ctx, env,
                 accept_charset_record_list);
@@ -391,7 +391,7 @@
             while(token);
         }
         if(accept_language_record_list && axutil_array_list_size(accept_language_record_list, env)
-            > 0)
+        > 0)
         {
             axis2_msg_ctx_set_http_accept_language_record_list(msg_ctx, env,
                 accept_language_record_list);
@@ -574,8 +574,7 @@
             else if(axis2_msg_ctx_get_status_code(msg_ctx, env)
                 == AXIS2_HTTP_RESPONSE_REQUEST_ENTITY_TOO_LARGE_CODE_VAL)
             {
-                body_string
-                    = axis2_http_transport_utils_get_request_entity_too_large(env, conf_ctx);
+                body_string = axis2_http_transport_utils_get_request_entity_too_large(env, conf_ctx);
                 request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
                 request->status = HTTP_REQUEST_ENTITY_TOO_LARGE;
             }
@@ -711,549 +710,549 @@
             }
             if(axis2_msg_ctx_get_is_soap_11(msg_ctx, env))
             {
-fault_code            = AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":"
-            AXIOM_SOAP11_FAULT_CODE_SENDER;
-        }
-        else
-        {
-            fault_code = AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":"
-            AXIOM_SOAP12_SOAP_FAULT_VALUE_SENDER;
-        }
-        fault_ctx = axis2_engine_create_fault_msg_ctx(engine, env, msg_ctx,
-            fault_code,
-            axutil_error_get_message
-            (env->error));
-        axis2_engine_send_fault(engine, env, fault_ctx);
-        if (out_stream)
-        {
-            body_string = axutil_stream_get_buffer(out_stream, env);
-            body_string_len = axutil_stream_get_len(out_stream, env);
-        }
+                fault_code            = AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":"
+                    AXIOM_SOAP11_FAULT_CODE_SENDER;
+            }
+            else
+            {
+                fault_code = AXIOM_SOAP_DEFAULT_NAMESPACE_PREFIX ":"
+                    AXIOM_SOAP12_SOAP_FAULT_VALUE_SENDER;
+            }
+            fault_ctx = axis2_engine_create_fault_msg_ctx(engine, env, msg_ctx,
+                fault_code,
+                axutil_error_get_message
+                (env->error));
+            axis2_engine_send_fault(engine, env, fault_ctx);
+            if (out_stream)
+            {
+                body_string = axutil_stream_get_buffer(out_stream, env);
+                body_string_len = axutil_stream_get_len(out_stream, env);
+            }
 
-        /* In case of a SOAP Fault, we have to set the status to 500,
+            /* In case of a SOAP Fault, we have to set the status to 500,
          but still return OK because the module has handled the error
-         */
-        send_status = OK;
-        request->status = HTTP_INTERNAL_SERVER_ERROR;
+             */
+            send_status = OK;
+            request->status = HTTP_INTERNAL_SERVER_ERROR;
+        }
     }
-}
-else
-{
-    body_string =
-    axis2_http_transport_utils_get_not_implemented(env, conf_ctx);
-    request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
-
-    if (body_string)
+    else
     {
-        body_string_len = axutil_strlen(body_string);
-    }
-    send_status = OK;
-    request->status = HTTP_NOT_IMPLEMENTED;
-}
+        body_string =
+            axis2_http_transport_utils_get_not_implemented(env, conf_ctx);
+        request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
 
-op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env);
+        if (body_string)
+        {
+            body_string_len = axutil_strlen(body_string);
+        }
+        send_status = OK;
+        request->status = HTTP_NOT_IMPLEMENTED;
+    }
 
-if (op_ctx)
-{
-    axis2_msg_ctx_t *out_msg_ctx = NULL;
-    axis2_msg_ctx_t **msg_ctx_map = NULL;
+    op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env);
 
-    msg_ctx_map = axis2_op_ctx_get_msg_ctx_map(op_ctx, env);
-    out_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT];
-    if (out_msg_ctx)
+    if (op_ctx)
     {
-        content_language_header_value = axis2_msg_ctx_get_content_language(out_msg_ctx, env);
-    }
-}
+        axis2_msg_ctx_t *out_msg_ctx = NULL;
+        axis2_msg_ctx_t **msg_ctx_map = NULL;
 
-if (send_status == DECLINED)
-{
-    axis2_bool_t do_rest = AXIS2_FALSE;
-    if (M_POST != request->method_number ||
-        axis2_msg_ctx_get_doing_rest(msg_ctx, env))
-    {
-        do_rest = AXIS2_TRUE;
+        msg_ctx_map = axis2_op_ctx_get_msg_ctx_map(op_ctx, env);
+        out_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT];
+        if (out_msg_ctx)
+        {
+            content_language_header_value = axis2_msg_ctx_get_content_language(out_msg_ctx, env);
+        }
     }
-    if ((accept_header_value || accept_charset_header_value ||
-            accept_language_header_value) && do_rest)
-    {
-        axis2_char_t *content_type_header_value = NULL;
-        axis2_char_t *temp = NULL;
-        axis2_char_t *language_header_value = NULL;
 
-        content_type_header_value = (axis2_char_t *) request->content_type;
-        language_header_value = content_language_header_value;
-        if (content_type_header_value)
+    if (send_status == DECLINED)
+    {
+        axis2_bool_t do_rest = AXIS2_FALSE;
+        if (M_POST != request->method_number ||
+            axis2_msg_ctx_get_doing_rest(msg_ctx, env))
         {
-            temp = axutil_strdup(env, content_type_header_value);
+            do_rest = AXIS2_TRUE;
         }
-        if (temp)
+        if ((accept_header_value || accept_charset_header_value ||
+            accept_language_header_value) && do_rest)
         {
-            axis2_char_t *content_type = NULL;
-            axis2_char_t *char_set = NULL;
-            axis2_char_t *temp2 = NULL;
-
-            temp2 = strchr(temp, ';');
-            if (temp2)
+            axis2_char_t *content_type_header_value = NULL;
+            axis2_char_t *temp = NULL;
+            axis2_char_t *language_header_value = NULL;
+
+            content_type_header_value = (axis2_char_t *) request->content_type;
+            language_header_value = content_language_header_value;
+            if (content_type_header_value)
             {
-                *temp2 = '\0';
-                temp2++;
-                char_set = axutil_strcasestr(temp2, AXIS2_HTTP_CHAR_SET_ENCODING);
+                temp = axutil_strdup(env, content_type_header_value);
             }
-            if (char_set)
-            {
-                char_set = axutil_strltrim(env, char_set, " \t=");
-            }
-            if (char_set)
-            {
-                temp2 = strchr(char_set, ';');
-            }
-            if (temp2)
-            {
-                *temp2 = '\0';
-            }
-            content_type = axutil_strtrim(env, temp, NULL);
-
             if (temp)
             {
-                AXIS2_FREE(env->allocator, temp);
-                temp = NULL;
-            }
-            if (content_type && accept_header_value &&
-                !axutil_strcasestr(accept_header_value, content_type))
-            {
-                temp2 = strchr(content_type, '/');
+                axis2_char_t *content_type = NULL;
+                axis2_char_t *char_set = NULL;
+                axis2_char_t *temp2 = NULL;
+
+                temp2 = strchr(temp, ';');
                 if (temp2)
                 {
                     *temp2 = '\0';
-                    temp = AXIS2_MALLOC(env->allocator,
-                        sizeof(axis2_char_t) * ((int)strlen(content_type) + 3));
-                    if (!temp)
-                    {
-                        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
-                        return AXIS2_FALSE;
-                    }
-                    sprintf(temp, "%s/*", content_type);
-                    if (!axutil_strcasestr(accept_header_value, temp) &&
-                        !strstr(accept_header_value, AXIS2_HTTP_HEADER_ACCEPT_ALL))
-                    {
-                        body_string =
-                        axis2_http_transport_utils_get_not_acceptable(env, conf_ctx);
-                        request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
+                    temp2++;
+                    char_set = axutil_strcasestr(temp2, AXIS2_HTTP_CHAR_SET_ENCODING);
+                }
+                if (char_set)
+                {
+                    char_set = axutil_strltrim(env, char_set, " \t=");
+                }
+                if (char_set)
+                {
+                    temp2 = strchr(char_set, ';');
+                }
+                if (temp2)
+                {
+                    *temp2 = '\0';
+                }
+                content_type = axutil_strtrim(env, temp, NULL);
 
-                        if (body_string)
+                if (temp)
+                {
+                    AXIS2_FREE(env->allocator, temp);
+                    temp = NULL;
+                }
+                if (content_type && accept_header_value &&
+                    !axutil_strcasestr(accept_header_value, content_type))
+                {
+                    temp2 = strchr(content_type, '/');
+                    if (temp2)
+                    {
+                        *temp2 = '\0';
+                        temp = AXIS2_MALLOC(env->allocator,
+                            sizeof(axis2_char_t) * ((int)strlen(content_type) + 3));
+                        if (!temp)
                         {
-                            body_string_len = axutil_strlen(body_string);
+                            AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+                            return AXIS2_FALSE;
                         }
-                        send_status = OK;
-                        request->status = HTTP_NOT_ACCEPTABLE;
+                        sprintf(temp, "%s/*", content_type);
+                        if (!axutil_strcasestr(accept_header_value, temp) &&
+                            !strstr(accept_header_value, AXIS2_HTTP_HEADER_ACCEPT_ALL))
+                        {
+                            body_string =
+                                axis2_http_transport_utils_get_not_acceptable(env, conf_ctx);
+                            request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
+
+                            if (body_string)
+                            {
+                                body_string_len = axutil_strlen(body_string);
+                            }
+                            send_status = OK;
+                            request->status = HTTP_NOT_ACCEPTABLE;
+                        }
+                        AXIS2_FREE(env->allocator, temp);
                     }
-                    AXIS2_FREE(env->allocator, temp);
                 }
-            }
-            if (content_type)
-            {
-                AXIS2_FREE(env->allocator, content_type);
-            }
-            if (char_set && accept_charset_header_value &&
-                !axutil_strcasestr(accept_charset_header_value, char_set))
-            {
-                body_string =
-                axis2_http_transport_utils_get_not_acceptable(env, conf_ctx);
-                request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
+                if (content_type)
+                {
+                    AXIS2_FREE(env->allocator, content_type);
+                }
+                if (char_set && accept_charset_header_value &&
+                    !axutil_strcasestr(accept_charset_header_value, char_set))
+                {
+                    body_string =
+                        axis2_http_transport_utils_get_not_acceptable(env, conf_ctx);
+                    request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
 
-                if (body_string)
+                    if (body_string)
+                    {
+                        body_string_len = axutil_strlen(body_string);
+                    }
+                    send_status = OK;
+                    request->status = HTTP_NOT_ACCEPTABLE;
+                }
+                if (char_set)
                 {
-                    body_string_len = axutil_strlen(body_string);
+                    AXIS2_FREE(env->allocator, char_set);
                 }
-                send_status = OK;
-                request->status = HTTP_NOT_ACCEPTABLE;
             }
-            if (char_set)
-            {
-                AXIS2_FREE(env->allocator, char_set);
-            }
-        }
-        if (language_header_value)
-        {
-            if (accept_language_header_value &&
-                !axutil_strcasestr(accept_language_header_value, language_header_value))
+            if (language_header_value)
             {
-                body_string =
-                axis2_http_transport_utils_get_not_acceptable(env, conf_ctx);
-                request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
-
-                if (body_string)
+                if (accept_language_header_value &&
+                    !axutil_strcasestr(accept_language_header_value, language_header_value))
                 {
-                    body_string_len = axutil_strlen(body_string);
+                    body_string =
+                        axis2_http_transport_utils_get_not_acceptable(env, conf_ctx);
+                    request->content_type = AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML;
+
+                    if (body_string)
+                    {
+                        body_string_len = axutil_strlen(body_string);
+                    }
+                    send_status = OK;
+                    request->status = HTTP_NOT_ACCEPTABLE;
                 }
-                send_status = OK;
-                request->status = HTTP_NOT_ACCEPTABLE;
             }
         }
     }
-}
-if (send_status == DECLINED)
-{
-    axis2_bool_t do_rest = AXIS2_FALSE;
-    if (M_POST != request->method_number ||
-        axis2_msg_ctx_get_doing_rest(msg_ctx, env))
-    {
-        do_rest = AXIS2_TRUE;
-    }
-    if (op_ctx && axis2_op_ctx_get_response_written(op_ctx, env))
+    if (send_status == DECLINED)
     {
-        if (do_rest)
+        axis2_bool_t do_rest = AXIS2_FALSE;
+        if (M_POST != request->method_number ||
+            axis2_msg_ctx_get_doing_rest(msg_ctx, env))
         {
-            axis2_msg_ctx_t *out_msg_ctx = NULL;
-            axis2_msg_ctx_t *in_msg_ctx = NULL;
-            axis2_msg_ctx_t **msg_ctx_map = NULL;
-
-            msg_ctx_map = axis2_op_ctx_get_msg_ctx_map(op_ctx, env);
-            out_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT];
-            in_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_IN];
-            if (in_msg_ctx)
-            {
-                /* TODO: Add necessary handling */
-            }
-            if (out_msg_ctx)
+            do_rest = AXIS2_TRUE;
+        }
+        if (op_ctx && axis2_op_ctx_get_response_written(op_ctx, env))
+        {
+            if (do_rest)
             {
-                int size = 0;
-                axutil_array_list_t *output_header_list = NULL;
-                output_header_list = axis2_msg_ctx_get_http_output_headers(out_msg_ctx, env);
-                if (output_header_list)
-                {
-                    size = axutil_array_list_size(output_header_list, env);
-                }
-                while (size)
-                {
-                    axis2_http_header_t *output_header = NULL;
-                    size--;
-                    output_header = (axis2_http_header_t *)
-                    axutil_array_list_get(output_header_list, env, size);
-                    apr_table_set(request->err_headers_out,
-                        axis2_http_header_get_name(output_header, env),
-                        axis2_http_header_get_value(output_header, env));
+                axis2_msg_ctx_t *out_msg_ctx = NULL;
+                axis2_msg_ctx_t *in_msg_ctx = NULL;
+                axis2_msg_ctx_t **msg_ctx_map = NULL;
+
+                msg_ctx_map = axis2_op_ctx_get_msg_ctx_map(op_ctx, env);
+                out_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT];
+                in_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_IN];
+                if (in_msg_ctx)
+                {
+                    /* TODO: Add necessary handling */
                 }
-                if (axis2_msg_ctx_get_status_code(out_msg_ctx, env))
+                if (out_msg_ctx)
                 {
-                    int status_code = axis2_msg_ctx_get_status_code(out_msg_ctx, env);
-                    switch (status_code)
+                    int size = 0;
+                    axutil_array_list_t *output_header_list = NULL;
+                    output_header_list = axis2_msg_ctx_get_http_output_headers(out_msg_ctx, env);
+                    if (output_header_list)
+                    {
+                        size = axutil_array_list_size(output_header_list, env);
+                    }
+                    while (size)
+                    {
+                        axis2_http_header_t *output_header = NULL;
+                        size--;
+                        output_header = (axis2_http_header_t *)
+                        axutil_array_list_get(output_header_list, env, size);
+                        apr_table_set(request->err_headers_out,
+                            axis2_http_header_get_name(output_header, env),
+                            axis2_http_header_get_value(output_header, env));
+                    }
+                    if (axis2_msg_ctx_get_status_code(out_msg_ctx, env))
                     {
-                        case AXIS2_HTTP_RESPONSE_CONTINUE_CODE_VAL:
-                        request->status = HTTP_CONTINUE;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_ACK_CODE_VAL:
-                        request->status = HTTP_ACCEPTED;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_MULTIPLE_CHOICES_CODE_VAL:
-                        request->status = HTTP_MULTIPLE_CHOICES;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_MOVED_PERMANENTLY_CODE_VAL:
-                        request->status = HTTP_MOVED_PERMANENTLY;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_SEE_OTHER_CODE_VAL:
-                        request->status = HTTP_SEE_OTHER;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_NOT_MODIFIED_CODE_VAL:
-                        request->status = HTTP_NOT_MODIFIED;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_TEMPORARY_REDIRECT_CODE_VAL:
-                        request->status = HTTP_TEMPORARY_REDIRECT;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_BAD_REQUEST_CODE_VAL:
-                        request->status = HTTP_BAD_REQUEST;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_REQUEST_TIMEOUT_CODE_VAL:
-                        request->status = HTTP_REQUEST_TIME_OUT;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_CONFLICT_CODE_VAL:
-                        request->status = HTTP_CONFLICT;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_GONE_CODE_VAL:
-                        request->status = HTTP_GONE;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_PRECONDITION_FAILED_CODE_VAL:
-                        request->status = HTTP_PRECONDITION_FAILED;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_REQUEST_ENTITY_TOO_LARGE_CODE_VAL:
-                        request->status = HTTP_REQUEST_ENTITY_TOO_LARGE;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_SERVICE_UNAVAILABLE_CODE_VAL:
-                        request->status = HTTP_SERVICE_UNAVAILABLE;
-                        break;
-                        default:
-                        request->status = HTTP_OK;
-                        break;
+                        int status_code = axis2_msg_ctx_get_status_code(out_msg_ctx, env);
+                        switch (status_code)
+                        {
+                            case AXIS2_HTTP_RESPONSE_CONTINUE_CODE_VAL:
+                                request->status = HTTP_CONTINUE;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_ACK_CODE_VAL:
+                                request->status = HTTP_ACCEPTED;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_MULTIPLE_CHOICES_CODE_VAL:
+                                request->status = HTTP_MULTIPLE_CHOICES;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_MOVED_PERMANENTLY_CODE_VAL:
+                                request->status = HTTP_MOVED_PERMANENTLY;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_SEE_OTHER_CODE_VAL:
+                                request->status = HTTP_SEE_OTHER;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_NOT_MODIFIED_CODE_VAL:
+                                request->status = HTTP_NOT_MODIFIED;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_TEMPORARY_REDIRECT_CODE_VAL:
+                                request->status = HTTP_TEMPORARY_REDIRECT;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_BAD_REQUEST_CODE_VAL:
+                                request->status = HTTP_BAD_REQUEST;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_REQUEST_TIMEOUT_CODE_VAL:
+                                request->status = HTTP_REQUEST_TIME_OUT;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_CONFLICT_CODE_VAL:
+                                request->status = HTTP_CONFLICT;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_GONE_CODE_VAL:
+                                request->status = HTTP_GONE;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_PRECONDITION_FAILED_CODE_VAL:
+                                request->status = HTTP_PRECONDITION_FAILED;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_REQUEST_ENTITY_TOO_LARGE_CODE_VAL:
+                                request->status = HTTP_REQUEST_ENTITY_TOO_LARGE;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_SERVICE_UNAVAILABLE_CODE_VAL:
+                                request->status = HTTP_SERVICE_UNAVAILABLE;
+                                break;
+                            default:
+                                request->status = HTTP_OK;
+                                break;
+                        }
+                        send_status = DONE;
                     }
-                    send_status = DONE;
                 }
             }
-        }
-        if (send_status == DECLINED)
-        {
-            send_status = OK;
-            if (out_stream)
+            if (send_status == DECLINED)
             {
-                body_string = axutil_stream_get_buffer(out_stream, env);
-                body_string_len = axutil_stream_get_len(out_stream, env);
+                send_status = OK;
+                if (out_stream)
+                {
+                    body_string = axutil_stream_get_buffer(out_stream, env);
+                    body_string_len = axutil_stream_get_len(out_stream, env);
+                }
             }
         }
-    }
-    else if (op_ctx)
-    {
-        if (do_rest)
+        else if (op_ctx)
         {
-            axis2_msg_ctx_t *out_msg_ctx = NULL;
-            axis2_msg_ctx_t *in_msg_ctx = NULL;
-            axis2_msg_ctx_t **msg_ctx_map = NULL;
-
-            msg_ctx_map = axis2_op_ctx_get_msg_ctx_map(op_ctx, env);
-            out_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT];
-            in_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_IN];
-            if (in_msg_ctx)
-            {
-                /* TODO: Add necessary handling */
-            }
-            if (out_msg_ctx)
+            if (do_rest)
             {
-                int size = 0;
-                axutil_array_list_t *output_header_list = NULL;
-                output_header_list = axis2_msg_ctx_get_http_output_headers(out_msg_ctx, env);
-                if (output_header_list)
-                {
-                    size = axutil_array_list_size(output_header_list, env);
-                }
-                while (size)
-                {
-                    axis2_http_header_t *output_header = NULL;
-                    size--;
-                    output_header = (axis2_http_header_t *)
-                    axutil_array_list_get(output_header_list, env, size);
-                    apr_table_set(request->err_headers_out,
-                        axis2_http_header_get_name(output_header, env),
-                        axis2_http_header_get_value(output_header, env));
+                axis2_msg_ctx_t *out_msg_ctx = NULL;
+                axis2_msg_ctx_t *in_msg_ctx = NULL;
+                axis2_msg_ctx_t **msg_ctx_map = NULL;
+
+                msg_ctx_map = axis2_op_ctx_get_msg_ctx_map(op_ctx, env);
+                out_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT];
+                in_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_IN];
+                if (in_msg_ctx)
+                {
+                    /* TODO: Add necessary handling */
                 }
-                if (axis2_msg_ctx_get_no_content(out_msg_ctx, env))
+                if (out_msg_ctx)
                 {
-                    if (axis2_msg_ctx_get_status_code(out_msg_ctx, env))
+                    int size = 0;
+                    axutil_array_list_t *output_header_list = NULL;
+                    output_header_list = axis2_msg_ctx_get_http_output_headers(out_msg_ctx, env);
+                    if (output_header_list)
+                    {
+                        size = axutil_array_list_size(output_header_list, env);
+                    }
+                    while (size)
+                    {
+                        axis2_http_header_t *output_header = NULL;
+                        size--;
+                        output_header = (axis2_http_header_t *)
+                        axutil_array_list_get(output_header_list, env, size);
+                        apr_table_set(request->err_headers_out,
+                            axis2_http_header_get_name(output_header, env),
+                            axis2_http_header_get_value(output_header, env));
+                    }
+                    if (axis2_msg_ctx_get_no_content(out_msg_ctx, env))
+                    {
+                        if (axis2_msg_ctx_get_status_code(out_msg_ctx, env))
+                        {
+                            int status_code = axis2_msg_ctx_get_status_code(out_msg_ctx, env);
+                            switch (status_code)
+                            {
+                                case AXIS2_HTTP_RESPONSE_RESET_CONTENT_CODE_VAL:
+                                    request->status = HTTP_RESET_CONTENT;
+                                    break;
+                                case AXIS2_HTTP_RESPONSE_NOT_MODIFIED_CODE_VAL:
+                                    request->status = HTTP_NOT_MODIFIED;
+                                    break;
+                                default:
+                                    request->status = HTTP_NO_CONTENT;
+                                    break;
+                            }
+                        }
+                        else
+                        {
+                            request->status = HTTP_NO_CONTENT;
+                        }
+                        send_status = DONE;
+                    }
+                    else if (axis2_msg_ctx_get_status_code(out_msg_ctx, env))
                     {
                         int status_code = axis2_msg_ctx_get_status_code(out_msg_ctx, env);
                         switch (status_code)
                         {
-                            case AXIS2_HTTP_RESPONSE_RESET_CONTENT_CODE_VAL:
-                            request->status = HTTP_RESET_CONTENT;
-                            break;
+                            case AXIS2_HTTP_RESPONSE_CONTINUE_CODE_VAL:
+                                request->status = HTTP_CONTINUE;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_OK_CODE_VAL:
+                                request->status = HTTP_OK;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_MULTIPLE_CHOICES_CODE_VAL:
+                                request->status = HTTP_MULTIPLE_CHOICES;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_MOVED_PERMANENTLY_CODE_VAL:
+                                request->status = HTTP_MOVED_PERMANENTLY;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_SEE_OTHER_CODE_VAL:
+                                request->status = HTTP_SEE_OTHER;
+                                break;
                             case AXIS2_HTTP_RESPONSE_NOT_MODIFIED_CODE_VAL:
-                            request->status = HTTP_NOT_MODIFIED;
-                            break;
+                                request->status = HTTP_NOT_MODIFIED;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_TEMPORARY_REDIRECT_CODE_VAL:
+                                request->status = HTTP_TEMPORARY_REDIRECT;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_BAD_REQUEST_CODE_VAL:
+                                request->status = HTTP_BAD_REQUEST;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_REQUEST_TIMEOUT_CODE_VAL:
+                                request->status = HTTP_REQUEST_TIME_OUT;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_CONFLICT_CODE_VAL:
+                                request->status = HTTP_CONFLICT;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_GONE_CODE_VAL:
+                                request->status = HTTP_GONE;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_PRECONDITION_FAILED_CODE_VAL:
+                                request->status = HTTP_PRECONDITION_FAILED;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_REQUEST_ENTITY_TOO_LARGE_CODE_VAL:
+                                request->status = HTTP_REQUEST_ENTITY_TOO_LARGE;
+                                break;
+                            case AXIS2_HTTP_RESPONSE_SERVICE_UNAVAILABLE_CODE_VAL:
+                                request->status = HTTP_SERVICE_UNAVAILABLE;
+                                break;
                             default:
-                            request->status = HTTP_NO_CONTENT;
-                            break;
+                                request->status = HTTP_ACCEPTED;
+                                break;
                         }
+                        send_status = DONE;
                     }
-                    else
-                    {
-                        request->status = HTTP_NO_CONTENT;
-                    }
-                    send_status = DONE;
-                }
-                else if (axis2_msg_ctx_get_status_code(out_msg_ctx, env))
-                {
-                    int status_code = axis2_msg_ctx_get_status_code(out_msg_ctx, env);
-                    switch (status_code)
-                    {
-                        case AXIS2_HTTP_RESPONSE_CONTINUE_CODE_VAL:
-                        request->status = HTTP_CONTINUE;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_OK_CODE_VAL:
-                        request->status = HTTP_OK;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_MULTIPLE_CHOICES_CODE_VAL:
-                        request->status = HTTP_MULTIPLE_CHOICES;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_MOVED_PERMANENTLY_CODE_VAL:
-                        request->status = HTTP_MOVED_PERMANENTLY;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_SEE_OTHER_CODE_VAL:
-                        request->status = HTTP_SEE_OTHER;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_NOT_MODIFIED_CODE_VAL:
-                        request->status = HTTP_NOT_MODIFIED;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_TEMPORARY_REDIRECT_CODE_VAL:
-                        request->status = HTTP_TEMPORARY_REDIRECT;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_BAD_REQUEST_CODE_VAL:
-                        request->status = HTTP_BAD_REQUEST;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_REQUEST_TIMEOUT_CODE_VAL:
-                        request->status = HTTP_REQUEST_TIME_OUT;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_CONFLICT_CODE_VAL:
-                        request->status = HTTP_CONFLICT;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_GONE_CODE_VAL:
-                        request->status = HTTP_GONE;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_PRECONDITION_FAILED_CODE_VAL:
-                        request->status = HTTP_PRECONDITION_FAILED;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_REQUEST_ENTITY_TOO_LARGE_CODE_VAL:
-                        request->status = HTTP_REQUEST_ENTITY_TOO_LARGE;
-                        break;
-                        case AXIS2_HTTP_RESPONSE_SERVICE_UNAVAILABLE_CODE_VAL:
-                        request->status = HTTP_SERVICE_UNAVAILABLE;
-                        break;
-                        default:
-                        request->status = HTTP_ACCEPTED;
-                        break;
-                    }
-                    send_status = DONE;
                 }
             }
+            if (send_status == DECLINED)
+            {
+                request->status = HTTP_ACCEPTED;
+                send_status = DONE;
+            }
         }
-        if (send_status == DECLINED)
+        else
         {
-            request->status = HTTP_ACCEPTED;
             send_status = DONE;
+            request->status = HTTP_ACCEPTED;
         }
     }
-    else
+
+    if (content_language_header_value)
     {
-        send_status = DONE;
-        request->status = HTTP_ACCEPTED;
+        apr_table_set(request->err_headers_out, AXIS2_HTTP_HEADER_CONTENT_LANGUAGE,
+            content_language_header_value);
     }
-}
 
-if (content_language_header_value)
-{
-    apr_table_set(request->err_headers_out, AXIS2_HTTP_HEADER_CONTENT_LANGUAGE,
-        content_language_header_value);
-}
-
-if (op_ctx)
-{
-    axis2_msg_ctx_t *out_msg_ctx = NULL,
-    *in_msg_ctx = NULL;
-    axis2_msg_ctx_t **msg_ctx_map = NULL;
-    axis2_char_t *msg_id = NULL;
-    axis2_conf_ctx_t *conf_ctx = NULL;
-    msg_ctx_map = axis2_op_ctx_get_msg_ctx_map(op_ctx, env);
+    if (op_ctx)
+    {
+        axis2_msg_ctx_t *out_msg_ctx = NULL,
+            *in_msg_ctx = NULL;
+        axis2_msg_ctx_t **msg_ctx_map = NULL;
+        axis2_char_t *msg_id = NULL;
+        axis2_conf_ctx_t *conf_ctx = NULL;
+        msg_ctx_map = axis2_op_ctx_get_msg_ctx_map(op_ctx, env);
 
-    out_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT];
-    in_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_IN];
+        out_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT];
+        in_msg_ctx = msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_IN];
 
-    /* In mtom case we send the attachment differently */
+        /* In mtom case we send the attachment differently */
 
-    /* status = AXIS2_FAILURE means fault scenario. We are not
-     * doing MTOM for fault cases. */
+        /* status = AXIS2_FAILURE means fault scenario. We are not
+         * doing MTOM for fault cases. */
 
-    if(status != AXIS2_FAILURE)
-    {
-        do_mtom = axis2_msg_ctx_get_doing_mtom(out_msg_ctx, env);
-        if(do_mtom)
+        if(status != AXIS2_FAILURE)
         {
-            mime_parts = axis2_msg_ctx_get_mime_parts(out_msg_ctx, env);
-            if(!mime_parts)
-            {
-                return AXIS2_FAILURE;
-            }
-            callback_name_param = axis2_msg_ctx_get_parameter(msg_ctx, env ,
-                AXIS2_MTOM_SENDING_CALLBACK);
-            if(callback_name_param)
+            do_mtom = axis2_msg_ctx_get_doing_mtom(out_msg_ctx, env);
+            if(do_mtom)
             {
-                mtom_sending_callback_name =
-                (axis2_char_t *) axutil_param_get_value (callback_name_param, env);
+                mime_parts = axis2_msg_ctx_get_mime_parts(out_msg_ctx, env);
+                if(!mime_parts)
+                {
+                    return AXIS2_FAILURE;
+                }
+                callback_name_param = axis2_msg_ctx_get_parameter(msg_ctx, env ,
+                    AXIS2_MTOM_SENDING_CALLBACK);
+                if(callback_name_param)
+                {
+                    mtom_sending_callback_name =
+                        (axis2_char_t *) axutil_param_get_value (callback_name_param, env);
+                }
             }
         }
-    }
-
-    if (out_msg_ctx)
-    {
-        axis2_msg_ctx_free(out_msg_ctx, env);
-        out_msg_ctx = NULL;
-        msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT] = NULL;
-    }
 
-    if (in_msg_ctx)
-    {
-        msg_id =
-        axutil_strdup(env, axis2_msg_ctx_get_msg_id(in_msg_ctx, env));
-        conf_ctx = axis2_msg_ctx_get_conf_ctx(in_msg_ctx, env);
-        axis2_msg_ctx_reset_out_transport_info(in_msg_ctx, env);
-        axis2_msg_ctx_free(in_msg_ctx, env);
-        in_msg_ctx = NULL;
-        msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_IN] = NULL;
-    }
+        if (out_msg_ctx)
+        {
+            axis2_msg_ctx_free(out_msg_ctx, env);
+            out_msg_ctx = NULL;
+            msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT] = NULL;
+        }
 
-    if (!axis2_op_ctx_is_in_use(op_ctx, env))
-    {
-        axis2_op_ctx_destroy_mutex(op_ctx, env);
-        if (conf_ctx && msg_id)
+        if (in_msg_ctx)
         {
-            axis2_conf_ctx_register_op_ctx(conf_ctx, env, msg_id, NULL);
-            AXIS2_FREE(env->allocator, msg_id);
+            msg_id =
+                axutil_strdup(env, axis2_msg_ctx_get_msg_id(in_msg_ctx, env));
+            conf_ctx = axis2_msg_ctx_get_conf_ctx(in_msg_ctx, env);
+            axis2_msg_ctx_reset_out_transport_info(in_msg_ctx, env);
+            axis2_msg_ctx_free(in_msg_ctx, env);
+            in_msg_ctx = NULL;
+            msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_IN] = NULL;
         }
-        axis2_op_ctx_free(op_ctx, env);
-    }
 
-} /* Done freeing message contexts */
+        if (!axis2_op_ctx_is_in_use(op_ctx, env))
+        {
+            axis2_op_ctx_destroy_mutex(op_ctx, env);
+            if (conf_ctx && msg_id)
+            {
+                axis2_conf_ctx_register_op_ctx(conf_ctx, env, msg_id, NULL);
+                AXIS2_FREE(env->allocator, msg_id);
+            }
+            axis2_op_ctx_free(op_ctx, env);
+        }
 
-/* We send the message in parts when doing MTOM */
+    } /* Done freeing message contexts */
 
-if(do_mtom)
-{
-    axis2_status_t mtom_status = AXIS2_FAILURE;
+    /* We send the message in parts when doing MTOM */
 
-    if(!mtom_sending_callback_name)
+    if(do_mtom)
     {
-        /* If the callback name is not there, then we will check whether there
-         * is any mime_parts which has type callback. If we found then no point
-         * of continuing we should return a failure */
+        axis2_status_t mtom_status = AXIS2_FAILURE;
 
         if(!mtom_sending_callback_name)
         {
-            if(axis2_http_transport_utils_is_callback_required(
-                    env, mime_parts))
+            /* If the callback name is not there, then we will check whether there
+             * is any mime_parts which has type callback. If we found then no point
+             * of continuing we should return a failure */
+
+            if(!mtom_sending_callback_name)
             {
-                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Sender callback not specified");
-                return AXIS2_FAILURE;
+                if(axis2_http_transport_utils_is_callback_required(
+                    env, mime_parts))
+                {
+                    AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Sender callback not specified");
+                    return AXIS2_FAILURE;
+                }
             }
         }
+
+        mtom_status = apache2_worker_send_mtom_message(request, env, mime_parts,
+            mtom_sending_callback_name);
+        if(mtom_status == AXIS2_SUCCESS)
+        {
+            send_status = DONE;
+        }
+        else
+        {
+            send_status = DECLINED;
+        }
+
+        axis2_http_transport_utils_destroy_mime_parts(mime_parts, env);
+        mime_parts = NULL;
     }
 
-    mtom_status = apache2_worker_send_mtom_message(request, env, mime_parts,
-        mtom_sending_callback_name);
-    if(mtom_status == AXIS2_SUCCESS)
+    else if (body_string)
     {
-        send_status = DONE;
+        ap_rwrite(body_string, body_string_len, request);
+        body_string = NULL;
     }
-    else
+
+    if (request_body)
     {
-        send_status = DECLINED;
+        axutil_stream_free(request_body, env);
+        request_body = NULL;
     }
 
-    axis2_http_transport_utils_destroy_mime_parts(mime_parts, env);
-    mime_parts = NULL;
-}
-
-else if (body_string)
-{
-    ap_rwrite(body_string, body_string_len, request);
-    body_string = NULL;
-}
-
-if (request_body)
-{
-    axutil_stream_free(request_body, env);
-    request_body = NULL;
-}
-
-axutil_string_free(soap_action, env);
+    axutil_string_free(soap_action, env);
 
-msg_ctx = NULL;
-return send_status;
+    msg_ctx = NULL;
+    return send_status;
 }
 
 AXIS2_EXTERN axis2_char_t *AXIS2_CALL

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=810531&r1=810530&r2=810531&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 Wed Sep  2 14:45:10 2009
@@ -3106,7 +3106,6 @@
 /* This method takes an array_list as the input. It has items some 
  may be buffers and some may be files. This will send these part
  one by one to the wire using the chunked stream.*/
-
 AXIS2_EXTERN axis2_status_t AXIS2_CALL
 axis2_http_transport_utils_send_mtom_message(
     axutil_http_chunked_stream_t * chunked_stream,
@@ -3115,146 +3114,120 @@
     axis2_char_t *sending_callback_name)
 {
     int i = 0;
-    axiom_mime_part_t *mime_part = NULL;
     axis2_status_t status = AXIS2_SUCCESS;
-    int written = 0;
-    int len = 0;
 
-    if(mime_parts)
+    for(i = 0; i < axutil_array_list_size(mime_parts, env); i++)
     {
-        for(i = 0; i < axutil_array_list_size(mime_parts, env); i++)
-        {
-            mime_part = (axiom_mime_part_t *)axutil_array_list_get(mime_parts, env, i);
-
-            /* If it is a buffer just write it to the wire. This includes mime_bounadaries,
-             * mime_headers and SOAP */
-
-            if((mime_part->type) == AXIOM_MIME_PART_BUFFER)
-            {
-                written = 0;
-                while(written < mime_part->part_size)
-                {
-                    len = 0;
-                    len = axutil_http_chunked_stream_write(chunked_stream, env, mime_part->part
-                        + written, mime_part->part_size - written);
-                    if(len == -1)
-                    {
-                        status = AXIS2_FAILURE;
-                        break;
-                    }
-                    else
-                    {
-                        written += len;
-                    }
-                }
-            }
-
-            /* 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;
-                axis2_byte_t *output_buffer = NULL;
-                int output_buffer_size = 0;
-
-                f = fopen(mime_part->file_name, "rb");
-                if(!f)
-                {
-                    AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error opening file %s for reading",
-                        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 */
+        axiom_mime_part_t *mime_part = NULL;
+        mime_part = (axiom_mime_part_t *)axutil_array_list_get(mime_parts, env, i);
 
-                if(mime_part->part_size > AXIS2_MTOM_OUTPUT_BUFFER_SIZE)
+        /* If it is a buffer just write it to the wire. This includes mime_bounadaries,
+         * mime_headers and SOAP */
+        if(mime_part->type == AXIOM_MIME_PART_BUFFER)
+        {
+            int written = 0;
+            while(written < mime_part->part_size)
+            {
+                int len = 0;
+                len = axutil_http_chunked_stream_write(chunked_stream, env,
+                    mime_part->part + written, mime_part->part_size - written);
+                if(len == -1)
                 {
-                    output_buffer_size = AXIS2_MTOM_OUTPUT_BUFFER_SIZE;
+                    status = AXIS2_FAILURE;
+                    break;
                 }
                 else
                 {
-                    output_buffer_size = mime_part->part_size;
+                    written += len;
                 }
+            }
+        }
 
-                output_buffer = AXIS2_MALLOC(env->allocator, (output_buffer_size + 1)
-                    * sizeof(axis2_char_t));
+        /* 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;
+            axis2_byte_t *output_buffer = NULL;
+            int output_buffer_size = 0;
 
-                /*This is the method responsible for writing to the wire */
-                status = axis2_http_transport_utils_send_attachment_using_file(env, chunked_stream,
-                    f, output_buffer, output_buffer_size);
-                if(status == AXIS2_FAILURE)
-                {
-                    return status;
-                }
-            }
-            else if((mime_part->type) == AXIOM_MIME_PART_CALLBACK)
+            f = fopen(mime_part->file_name, "rb");
+            if(!f)
             {
-                void *handler = NULL;
-                axiom_mtom_sending_callback_t *callback = NULL;
-
-                handler = axis2_http_transport_utils_initiate_callback(env, sending_callback_name,
-                    mime_part->user_param, &callback);
+                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error opening file %s for reading",
+                    mime_part->file_name);
+                return AXIS2_FAILURE;
+            }
 
-                if(handler)
-                {
-                    status = axis2_http_transport_utils_send_attachment_using_callback(env,
-                        chunked_stream, callback, handler, mime_part->user_param);
-                }
-                else
-                {
-                    AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "MTOM Sending Callback loading failed");
-                    status = 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;
+            }
+            else
+            {
+                output_buffer_size = mime_part->part_size;
+            }
 
-                if(callback)
-                {
-                    axutil_param_t *param = NULL;
+            output_buffer = AXIS2_MALLOC(env->allocator, output_buffer_size * sizeof(axis2_char_t));
 
-                    param = callback->param;
+            /*This is the method responsible for writing to the wire */
+            status = axis2_http_transport_utils_send_attachment_using_file(env, chunked_stream,
+                f, output_buffer, output_buffer_size);
+            AXIS2_FREE(env->allocator, output_buffer);
+            fclose(f);
+        }
 
-                    AXIOM_MTOM_SENDING_CALLBACK_FREE(callback, env);
-                    callback = NULL;
-                    if(param)
-                    {
-                        axutil_param_free(param, env);
-                        param = NULL;
-                    }
-                }
+        /* if the callback is given, send data using callback */
+        else if((mime_part->type) == AXIOM_MIME_PART_CALLBACK)
+        {
+            void *handler = NULL;
+            axiom_mtom_sending_callback_t *callback = NULL;
 
-                if(status == AXIS2_FAILURE)
-                {
-                    return status;
-                }
+            handler = axis2_http_transport_utils_initiate_callback(env, sending_callback_name,
+                mime_part->user_param, &callback);
+            if(handler)
+            {
+                status = axis2_http_transport_utils_send_attachment_using_callback(env,
+                    chunked_stream, callback, handler, mime_part->user_param);
             }
             else
             {
-                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Unknown mime_part.");
-                return AXIS2_FAILURE;
+                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "MTOM Sending Callback loading failed");
+                status = AXIS2_FAILURE;
             }
-            if(status == AXIS2_FAILURE)
+
+            if(callback)
             {
-                break;
+                axutil_param_t *param = NULL;
+                param = callback->param;
+                AXIOM_MTOM_SENDING_CALLBACK_FREE(callback, env);
+                if(param)
+                {
+                    axutil_param_free(param, env);
+                }
             }
         }
-        if(status == AXIS2_SUCCESS)
+        else
         {
-            /* send the end of chunk */
-            axutil_http_chunked_stream_write_last_chunk(chunked_stream, env);
-            return AXIS2_SUCCESS;
+            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Unknown mime_part.");
+            status = AXIS2_FAILURE;
         }
-        else
+
+        if(status != AXIS2_SUCCESS)
         {
-            return status;
+            break;
         }
     }
-    else
+
+    if(status == AXIS2_SUCCESS)
     {
-        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Cannot send the attachment.Mime"
-            "Parts are not set properly.");
-        return AXIS2_FAILURE;
+        /* send the end of chunk */
+        axutil_http_chunked_stream_write_last_chunk(chunked_stream, env);
     }
+
+    return status;
 }
 
 static axis2_status_t
@@ -3265,88 +3238,40 @@
     axis2_byte_t *buffer,
     int buffer_size)
 {
-
-    int count = 0;
-    int len = 0;
-    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);
-        if(ferror(fp))
+        int written = 0;
+        int count = (int)fread(buffer, 1, buffer_size, fp);
+        if(ferror(fp) || (count <= 0))
         {
-            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error in reading file containg the attachment");
-            if(buffer)
-            {
-                AXIS2_FREE(env->allocator, buffer);
-                buffer = NULL;
-            }
-            fclose(fp);
+            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+                "Error in reading file containing the attachment");
             return AXIS2_FAILURE;
         }
 
         /*Writing the part we loaded to memory to the wire*/
-        if(count > 0)
-        {
-            written = 0;
-            while(written < count)
-            {
-                len = 0;
-                len = axutil_http_chunked_stream_write(chunked_stream, env, buffer + written, count
-                    - written);
-                if(len == -1)
-                {
-                    status = AXIS2_FAILURE;
-                    break;
-                }
-                else
-                {
-                    written += len;
-                }
-            }
-        }
-        else
+        while(written < count)
         {
-            if(buffer)
+            int len = axutil_http_chunked_stream_write(chunked_stream, env,
+                buffer + written, count - written);
+            if(len == -1)
             {
-                AXIS2_FREE(env->allocator, buffer);
-                buffer = NULL;
+                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "error in writing file to stream");
+                return AXIS2_FAILURE;
             }
-            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)
-        {
-            if(buffer)
-            {
-                AXIS2_FREE(env->allocator, buffer);
-                buffer = NULL;
-            }
-            fclose(fp);
-            return AXIS2_FAILURE;
+            written += len;
         }
     }
     while(!feof(fp));
 
-    if(buffer)
-    {
-        AXIS2_FREE(env->allocator, buffer);
-        buffer = NULL;
-    }
-
-    fclose(fp);
     return AXIS2_SUCCESS;
 }
 
-AXIS2_EXTERN void AXIS2_CALL axis2_http_transport_utils_destroy_mime_parts(
+AXIS2_EXTERN void AXIS2_CALL
+axis2_http_transport_utils_destroy_mime_parts(
     axutil_array_list_t *mime_parts,
     const axutil_env_t *env)
 {
@@ -3367,46 +3292,41 @@
     }
 }
 
-AXIS2_EXTERN void *AXIS2_CALL axis2_http_transport_utils_initiate_callback(
+AXIS2_EXTERN void *AXIS2_CALL
+axis2_http_transport_utils_initiate_callback(
     const axutil_env_t *env,
     axis2_char_t *callback_name,
     void *user_param,
     axiom_mtom_sending_callback_t **callback)
 {
-
     axutil_dll_desc_t *dll_desc = NULL;
     axutil_param_t *impl_info_param = NULL;
     void *ptr = NULL;
 
-    if(callback_name)
+    if(!callback_name)
     {
-        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Trying to load module = %s",
-            callback_name);
-        dll_desc = axutil_dll_desc_create(env);
-        axutil_dll_desc_set_name(dll_desc, env, callback_name);
-        impl_info_param = axutil_param_create(env, NULL, dll_desc);
-        /*Set the free function*/
-        axutil_param_set_value_free(impl_info_param, env, axutil_dll_desc_free_void_arg);
-        axutil_class_loader_init(env);
-        ptr = axutil_class_loader_create_dll(env, impl_info_param);
-
-        if (!ptr)
-        {
-            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
-                "Unable to load the module %s. ERROR", callback_name);
-            return NULL;
-        }
-
-        *callback = (axiom_mtom_sending_callback_t *)ptr;
-        (*callback)->param = impl_info_param;
-
-        return AXIOM_MTOM_SENDING_CALLBACK_INIT_HANDLER(*callback, env, user_param);
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "invalid callback name given");
+        return NULL;
     }
 
-    else
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Trying to load module = %s", callback_name);
+
+    dll_desc = axutil_dll_desc_create(env);
+    axutil_dll_desc_set_name(dll_desc, env, callback_name);
+    impl_info_param = axutil_param_create(env, NULL, dll_desc);
+    axutil_param_set_value_free(impl_info_param, env, axutil_dll_desc_free_void_arg);
+    axutil_class_loader_init(env);
+    ptr = axutil_class_loader_create_dll(env, impl_info_param);
+    if (!ptr)
     {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Unable to load the module %s.", callback_name);
         return NULL;
     }
+
+    *callback = (axiom_mtom_sending_callback_t *)ptr;
+    (*callback)->param = impl_info_param;
+
+    return AXIOM_MTOM_SENDING_CALLBACK_INIT_HANDLER(*callback, env, user_param);
 }
 
 static axis2_status_t
@@ -3418,41 +3338,29 @@
     void *user_param)
 {
     int count = 0;
-    int len = 0;
-    int written = 0;
     axis2_status_t status = AXIS2_SUCCESS;
     axis2_char_t *buffer = NULL;
 
-    /* Keep on loading the data in a loop until 
-     * all the data is sent */
-
+    /* Keep on loading the data in a loop until all the data is sent */
     while((count = AXIOM_MTOM_SENDING_CALLBACK_LOAD_DATA(callback, env, handler, &buffer)) > 0)
     {
-        written = 0;
+        int written = 0;
         while(written < count)
         {
-            len = 0;
-            len = axutil_http_chunked_stream_write(chunked_stream, env, buffer + written, count
-                - written);
+            int len = 0;
+            len = axutil_http_chunked_stream_write(chunked_stream, env,
+                buffer + written, count - written);
             if(len == -1)
             {
                 status = AXIS2_FAILURE;
                 break;
             }
-            else
-            {
-                written += len;
-            }
-        }
-    }
 
-    if(status == AXIS2_FAILURE)
-    {
-        AXIOM_MTOM_SENDING_CALLBACK_CLOSE_HANDLER(callback, env, handler);
-        return status;
+            written += len;
+        }
     }
 
-    status = AXIOM_MTOM_SENDING_CALLBACK_CLOSE_HANDLER(callback, env, handler);
+    status = AXIOM_MTOM_SENDING_CALLBACK_CLOSE_HANDLER(callback, env, handler) && status;
     return status;
 }
 
@@ -3463,13 +3371,12 @@
 {
     int size = 0;
     int i = 0;
-    axiom_mime_part_t *mime_part = NULL;
     axis2_bool_t is_required = AXIS2_FALSE;
 
     size = axutil_array_list_size(mime_parts, env);
-
     for(i = 0; i < size; i++)
     {
+        axiom_mime_part_t *mime_part = NULL;
         mime_part = (axiom_mime_part_t *)axutil_array_list_get(mime_parts, env, i);
         if(mime_part)
         {
@@ -3482,5 +3389,4 @@
     }
 
     return is_required;
-
 }