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/12/11 06:00:50 UTC

svn commit: r725576 - in /webservices/axis2/trunk/c/src/core/transport/http/server/apache2: apache2_worker.c mod_axis2.c

Author: manjula
Date: Wed Dec 10 21:00:50 2008
New Revision: 725576

URL: http://svn.apache.org/viewvc?rev=725576&view=rev
Log:
Adding fixes for httpd for Axis2C-1301.

Modified:
    webservices/axis2/trunk/c/src/core/transport/http/server/apache2/apache2_worker.c
    webservices/axis2/trunk/c/src/core/transport/http/server/apache2/mod_axis2.c

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=725576&r1=725575&r2=725576&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 Dec 10 21:00:50 2008
@@ -35,22 +35,32 @@
 #include <axutil_class_loader.h>
 #include <axutil_string_util.h>
 #include <axiom_mime_part.h>
+#include <axiom_mtom_sending_callback.h>
 
 #define READ_SIZE  2048
 
 static axis2_status_t apache2_worker_send_mtom_message(
     request_rec *request,
     const axutil_env_t * env,
-    axutil_array_list_t *mime_parts);
+    axutil_array_list_t *mime_parts,
+    axis2_char_t *mtom_sending_callback_name);
 
 static axis2_status_t 
-apache2_worker_send_attachment(
+apache2_worker_send_attachment_using_file(
     const axutil_env_t * env,
     request_rec *request,
     FILE *fp,
     axis2_byte_t *buffer,
     int buffer_size);
 
+static axis2_status_t
+apache2_worker_send_attachment_using_callback(
+    const axutil_env_t * env,
+    request_rec *request,
+    axiom_mtom_sending_callback_t *callback,
+    void *handler,
+    void *user_param);
+
 
 struct axis2_apache2_worker
 {
@@ -190,6 +200,10 @@
     axis2_char_t *content_language_header_value = NULL;
     axis2_bool_t do_mtom = AXIS2_FALSE;
     axutil_array_list_t *mime_parts = NULL;
+    axutil_param_t *callback_name_param = NULL;
+    axis2_char_t *mtom_sending_callback_name = NULL;
+    
+
 
     AXIS2_ENV_CHECK(env, AXIS2_CRITICAL_FAILURE);
     AXIS2_PARAM_CHECK(env->error, request, AXIS2_CRITICAL_FAILURE);
@@ -1187,6 +1201,13 @@
             {
                 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)
@@ -1225,7 +1246,26 @@
     if(do_mtom)
     {
         axis2_status_t mtom_status = AXIS2_FAILURE;
-        mtom_status = apache2_worker_send_mtom_message(request, env, mime_parts);
+
+        if(!mtom_sending_callback_name)
+        {
+            /* 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)
+            {
+                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;
@@ -1307,7 +1347,8 @@
 static axis2_status_t apache2_worker_send_mtom_message(
     request_rec *request,
     const axutil_env_t * env,
-    axutil_array_list_t *mime_parts)
+    axutil_array_list_t *mime_parts,
+    axis2_char_t *mtom_sending_callback_name)
 {
     int i = 0;
     axiom_mime_part_t *mime_part = NULL;
@@ -1360,13 +1401,42 @@
                     (output_buffer_size + 1) * sizeof(axis2_char_t));
  
  
-                status = apache2_worker_send_attachment(env, request, 
+                status = apache2_worker_send_attachment_using_file(env, request, 
                     f, output_buffer, output_buffer_size);
                 if(status == AXIS2_FAILURE)
                 {
                     return status;
                 }
             }
+            else if((mime_part->type) == AXIOM_MIME_PART_CALLBACK)
+            {
+                void *handler = NULL;
+                axiom_mtom_sending_callback_t *callback = NULL;
+
+                handler = axis2_http_transport_utils_initiate_callback(env,
+                    mtom_sending_callback_name, mime_part->user_param, &callback);
+               
+                if(handler)
+                {
+                    status = apache2_worker_send_attachment_using_callback(env,
+                        request, callback, handler, mime_part->user_param);
+                }
+                else
+                {
+                    AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "MTOM Sending Callback loading failed");
+                    status = AXIS2_FAILURE;
+                }
+                if(callback)
+                {
+                    AXIOM_MTOM_SENDING_CALLBACK_FREE(callback, env);
+                    callback = NULL;
+                }
+
+                if(status == AXIS2_FAILURE)
+                {
+                    return status;
+                }
+            }
             else
             {
                 return AXIS2_FAILURE;
@@ -1386,7 +1456,7 @@
 
 
 static axis2_status_t
-apache2_worker_send_attachment(
+apache2_worker_send_attachment_using_file(
     const axutil_env_t * env,
     request_rec *request,
     FILE *fp,
@@ -1455,3 +1525,41 @@
     buffer = NULL;    
     return AXIS2_SUCCESS;    
 }
+
+static axis2_status_t
+apache2_worker_send_attachment_using_callback(
+    const axutil_env_t * env,
+    request_rec *request,
+    axiom_mtom_sending_callback_t *callback,
+    void *handler,
+    void *user_param)
+{
+    int count = 0;
+    int len = 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 */
+
+    while((count = AXIOM_MTOM_SENDING_CALLBACK_LOAD_DATA(callback, env, handler, &buffer)) > 0)
+    {
+        len = 0;
+        len = ap_rwrite(buffer, count, request);
+        ap_rflush(request);
+        if(len == -1)
+        {
+            status = AXIS2_FAILURE;
+            break;
+        }
+    }
+
+    if (status == AXIS2_FAILURE)
+    {
+        AXIOM_MTOM_SENDING_CALLBACK_CLOSE_HANDLER(callback, env, handler);
+        return status;
+    }
+
+    status = AXIOM_MTOM_SENDING_CALLBACK_CLOSE_HANDLER(callback, env, handler);
+    return status;
+}

Modified: webservices/axis2/trunk/c/src/core/transport/http/server/apache2/mod_axis2.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/server/apache2/mod_axis2.c?rev=725576&r1=725575&r2=725576&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/server/apache2/mod_axis2.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/server/apache2/mod_axis2.c Wed Dec 10 21:00:50 2008
@@ -320,10 +320,14 @@
     axutil_allocator_t *allocator = NULL;
     axutil_error_t *error = NULL;
 
+    apr_allocator_t *local_allocator = NULL;
+    apr_pool_t *local_pool = NULL;
+
     if (strcmp(req->handler, "axis2_module"))
     {
         return DECLINED;
     }
+
     /* Set up the read policy from the client. */
     if ((rv = ap_setup_client_block(req, REQUEST_CHUNKED_DECHUNK)) != OK)
     {
@@ -331,6 +335,10 @@
     }
     ap_should_client_block(req);
 
+    apr_allocator_create(&local_allocator);
+    apr_pool_create_ex(&local_pool, NULL, NULL, local_allocator);
+
+    
 
     /*thread_env = axutil_init_thread_env(axutil_env);*/
 
@@ -338,8 +346,12 @@
     rv = AXIS2_APACHE2_WORKER_PROCESS_REQUEST(axis2_worker, axutil_env, req);*/
 
     /* create new allocator for this request */
-    allocator = (axutil_allocator_t *) apr_palloc(req->pool,
+    /*allocator = (axutil_allocator_t *) apr_palloc(req->pool,
+                                                  sizeof(axutil_allocator_t));*/
+
+    allocator = (axutil_allocator_t *) apr_palloc(local_pool,
                                                   sizeof(axutil_allocator_t));
+
     if (!allocator)
     {
         return HTTP_INTERNAL_SERVER_ERROR;
@@ -347,8 +359,8 @@
     allocator->malloc_fn = axis2_module_malloc;
     allocator->realloc = axis2_module_realloc;
     allocator->free_fn = axis2_module_free;
-    allocator->local_pool = (void *)req->pool ;
-    allocator->current_pool = (void *)req->pool;
+    allocator->local_pool = (void *)local_pool;
+    allocator->current_pool = (void *)local_pool;
     allocator->global_pool = axutil_env->allocator->global_pool;
 
     error = axutil_error_create(allocator);
@@ -364,6 +376,10 @@
         return HTTP_INTERNAL_SERVER_ERROR;
     }
 
+    apr_pool_destroy(local_pool);
+    apr_allocator_destroy(local_allocator);
+
+
     return rv;
 }