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 se...@apache.org on 2008/03/15 21:37:24 UTC

svn commit: r637463 - in /webservices/axis2/trunk/c: include/ src/core/transport/http/common/ src/core/transport/http/util/

Author: senaka
Date: Sat Mar 15 13:37:23 2008
New Revision: 637463

URL: http://svn.apache.org/viewvc?rev=637463&view=rev
Log:
Fixing a memory leak in http_worker, adding a method to report an appropriate message along with a 500 Error, fixing JIRA Issue AXIS2C-1056, and using the more appropriate 501 Not Implemented status instead of 400 Bad Request

Modified:
    webservices/axis2/trunk/c/include/axis2_http_transport.h
    webservices/axis2/trunk/c/include/axis2_http_transport_utils.h
    webservices/axis2/trunk/c/src/core/transport/http/common/http_worker.c
    webservices/axis2/trunk/c/src/core/transport/http/common/simple_http_svr_conn.c
    webservices/axis2/trunk/c/src/core/transport/http/util/http_transport_utils.c

Modified: webservices/axis2/trunk/c/include/axis2_http_transport.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/include/axis2_http_transport.h?rev=637463&r1=637462&r2=637463&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_http_transport.h (original)
+++ webservices/axis2/trunk/c/include/axis2_http_transport.h Sat Mar 15 13:37:23 2008
@@ -114,6 +114,11 @@
 #define AXIS2_HTTP_RESPONSE_INTERNAL_SERVER_ERROR_CODE_VAL 500
 
     /**
+     * RESPONSE_NOT_IMPLEMENTED_CODE_VAL
+     */
+#define AXIS2_HTTP_RESPONSE_NOT_IMPLEMENTED_CODE_VAL 501
+
+    /**
      * RESPONSE_CONTINUE_CODE_NAME
      */
 #define AXIS2_HTTP_RESPONSE_CONTINUE_CODE_NAME "Continue"
@@ -157,6 +162,11 @@
      * RESPONSE_INTERNAL_SERVER_ERROR_CODE_NAME
      */
 #define AXIS2_HTTP_RESPONSE_INTERNAL_SERVER_ERROR_CODE_NAME "Internal Server Error"
+
+    /**
+     * RESPONSE_NOT_IMPLEMENTED_CODE_NAME
+     */
+#define AXIS2_HTTP_RESPONSE_NOT_IMPLEMENTED_CODE_NAME "Not Implemented"
 
     /**
      * SOCKET

Modified: webservices/axis2/trunk/c/include/axis2_http_transport_utils.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/include/axis2_http_transport_utils.h?rev=637463&r1=637462&r2=637463&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_http_transport_utils.h (original)
+++ webservices/axis2/trunk/c/include/axis2_http_transport_utils.h Sat Mar 15 13:37:23 2008
@@ -151,7 +151,17 @@
         axis2_conf_ctx_t * conf_ctx);
 
     AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+    axis2_http_transport_utils_get_not_implemented(
+        const axutil_env_t * env,
+        axis2_conf_ctx_t * conf_ctx);
+
+    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
     axis2_http_transport_utils_get_method_not_allowed(
+        const axutil_env_t * env,
+        axis2_conf_ctx_t * conf_ctx);
+
+    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+    axis2_http_transport_utils_get_internal_server_error(
         const axutil_env_t * env,
         axis2_conf_ctx_t * conf_ctx);
 

Modified: webservices/axis2/trunk/c/src/core/transport/http/common/http_worker.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/common/http_worker.c?rev=637463&r1=637462&r2=637463&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/common/http_worker.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/common/http_worker.c Sat Mar 15 13:37:23 2008
@@ -129,10 +129,11 @@
     axis2_bool_t is_head = AXIS2_FALSE;
     axis2_bool_t is_put = AXIS2_FALSE;
     axis2_bool_t is_delete = AXIS2_FALSE;
+    axis2_bool_t request_handled = AXIS2_FALSE;
 
-    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
-    AXIS2_PARAM_CHECK(env->error, svr_conn, AXIS2_FAILURE);
-    AXIS2_PARAM_CHECK(env->error, simple_request, AXIS2_FAILURE);
+    AXIS2_ENV_CHECK(env, AXIS2_FALSE);
+    AXIS2_PARAM_CHECK(env->error, svr_conn, AXIS2_FALSE);
+    AXIS2_PARAM_CHECK(env->error, simple_request, AXIS2_FALSE);
 
     conf_ctx = http_worker->conf_ctx;
 
@@ -152,7 +153,7 @@
     {
         AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NULL_HTTP_VERSION,
                         AXIS2_FAILURE);
-        return AXIS2_FAILURE;
+        return AXIS2_FALSE;
     }
     AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Client HTTP version %s",
                     http_version);
@@ -445,8 +446,8 @@
                                                            AXIS2_HTTP_RESPONSE_INTERNAL_SERVER_ERROR_CODE_VAL,
                                                            AXIS2_HTTP_RESPONSE_INTERNAL_SERVER_ERROR_CODE_NAME);
 
-                body_string = axis2_http_transport_utils_get_services_html(env,
-                                                                           conf_ctx);
+                body_string = axis2_http_transport_utils_get_internal_server_error(env,
+                                                                                   conf_ctx);
                 cont_type = axis2_http_header_create(env,
                                                      AXIS2_HTTP_HEADER_CONTENT_TYPE,
                                                      AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML);
@@ -471,7 +472,8 @@
                                                    simple_request, response, 0);
             axis2_simple_http_svr_conn_write_response(svr_conn, env, response);
             axis2_http_simple_response_free(response, env);
-            return AXIS2_TRUE;
+            request_handled = AXIS2_TRUE;
+            status = AXIS2_TRUE;
         }
     }
     else if (0 ==
@@ -561,8 +563,8 @@
                                                            AXIS2_HTTP_RESPONSE_INTERNAL_SERVER_ERROR_CODE_VAL,
                                                            AXIS2_HTTP_RESPONSE_INTERNAL_SERVER_ERROR_CODE_NAME);
 
-                body_string = axis2_http_transport_utils_get_services_html(env,
-                                                                           conf_ctx);
+                body_string = axis2_http_transport_utils_get_internal_server_error(env,
+                                                                                   conf_ctx);
                 cont_type = axis2_http_header_create(env,
                                                      AXIS2_HTTP_HEADER_CONTENT_TYPE,
                                                      AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML);
@@ -587,7 +589,8 @@
                                                    simple_request, response, 0);
             axis2_simple_http_svr_conn_write_response(svr_conn, env, response);
             axis2_http_simple_response_free(response, env);
-            return AXIS2_TRUE;
+            request_handled = AXIS2_TRUE;
+            status = AXIS2_TRUE;
         }
         else if (status == AXIS2_FAILURE)
         {
@@ -672,41 +675,78 @@
 
             status = axis2_simple_http_svr_conn_write_response(svr_conn, env,
                                                                response);
-            return status;
-
+            request_handled = AXIS2_TRUE;
         }
     }
-
-    op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env);
-    if (axis2_op_ctx_get_response_written(op_ctx, env))
+    else
     {
-        axis2_http_simple_response_set_status_line(response, env, http_version,
-                                                   AXIS2_HTTP_RESPONSE_OK_CODE_VAL,
-                                                   AXIS2_HTTP_RESPONSE_OK_CODE_NAME);
-        if (!is_head)
+        axis2_http_header_t *cont_len = NULL;
+        axis2_http_header_t *cont_type = NULL;
+        axis2_char_t *body_string = NULL;
+        axis2_http_simple_response_set_status_line(response, env,
+                                                   http_version,
+                                                   AXIS2_HTTP_RESPONSE_NOT_IMPLEMENTED_CODE_VAL,
+                                                   AXIS2_HTTP_RESPONSE_NOT_IMPLEMENTED_CODE_NAME);
+        body_string = axis2_http_transport_utils_get_not_implemented(env,
+                                                                     conf_ctx);
+        cont_type = axis2_http_header_create(env,
+                                             AXIS2_HTTP_HEADER_CONTENT_TYPE,
+                                             AXIS2_HTTP_HEADER_ACCEPT_TEXT_HTML);
+        axis2_http_simple_response_set_header(response, env, cont_type);
+        if (body_string)
         {
-            axis2_http_simple_response_set_body_stream(response, env, out_stream);
+            axis2_char_t str_len[10];
+            axis2_http_simple_response_set_body_string(response, env,
+                                                       body_string);
+            sprintf(str_len, "%d", axutil_strlen(body_string));
+            cont_len = axis2_http_header_create(env,
+                                                AXIS2_HTTP_HEADER_CONTENT_LENGTH,
+                                                str_len);
+            axis2_http_simple_response_set_header(response, env, cont_len);
         }
+        axis2_http_worker_set_response_headers(http_worker, env, svr_conn,
+                                               simple_request, response, 0);
+        axis2_simple_http_svr_conn_write_response(svr_conn, env, response);
+        axis2_http_simple_response_free(response, env);
+        request_handled = AXIS2_TRUE;
+        status = AXIS2_TRUE;
     }
-    else
+    if (!request_handled)
     {
-        axis2_http_simple_response_set_status_line(response, env, http_version,
-                                                   AXIS2_HTTP_RESPONSE_ACK_CODE_VAL,
-                                                   AXIS2_HTTP_RESPONSE_ACK_CODE_NAME);
-    }
-    axis2_http_worker_set_response_headers(http_worker, env, svr_conn,
-                                           simple_request, response,
-                                           axutil_stream_get_len(out_stream,
-                                                                 env));
-
-    status = axis2_simple_http_svr_conn_write_response(svr_conn, env, response);
-    AXIS2_FREE(env->allocator, url_external_form);
-    url_external_form = NULL;
+        op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env);
+        if (axis2_op_ctx_get_response_written(op_ctx, env))
+        {
+            axis2_http_simple_response_set_status_line(response, env, http_version,
+                                                       AXIS2_HTTP_RESPONSE_OK_CODE_VAL,
+                                                       AXIS2_HTTP_RESPONSE_OK_CODE_NAME);
+            if (!is_head)
+            {
+                axis2_http_simple_response_set_body_stream(response, env, out_stream);
+            }
+        }
+        else
+        {
+            axis2_http_simple_response_set_status_line(response, env, http_version,
+                                                       AXIS2_HTTP_RESPONSE_ACK_CODE_VAL,
+                                                       AXIS2_HTTP_RESPONSE_ACK_CODE_NAME);
+        }
+        axis2_http_worker_set_response_headers(http_worker, env, svr_conn,
+                                               simple_request, response,
+                                               axutil_stream_get_len(out_stream,
+                                                                     env));
+
+        status = axis2_simple_http_svr_conn_write_response(svr_conn, env, response);
+    }
+    if (url_external_form)
+    {
+        AXIS2_FREE(env->allocator, url_external_form);
+        url_external_form = NULL;
+    }
     op_ctx = axis2_msg_ctx_get_op_ctx(msg_ctx, env);
     if (op_ctx)
     {
-        axis2_msg_ctx_t *out_msg_ctx = NULL,
-            *in_msg_ctx = NULL;
+        axis2_msg_ctx_t *out_msg_ctx = NULL;
+        axis2_msg_ctx_t *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;

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=637463&r1=637462&r2=637463&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 Sat Mar 15 13:37:23 2008
@@ -189,7 +189,7 @@
         }
     }
 
-    if (strlen(str_line))
+    /*if (strlen(str_line))
     {
         if (0 != axutil_strncasecmp(str_line, "GET", 3) && 0 !=
             axutil_strncasecmp(str_line, "POST", 4) && 0 !=
@@ -206,7 +206,7 @@
                                 axutil_strlen(write_buf) + 1);
             return NULL;
         }
-    }
+    }*/
     request_line = axis2_http_request_line_parse_line(env, str_line);
     if (!request_line)
     {

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=637463&r1=637462&r2=637463&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 Sat Mar 15 13:37:23 2008
@@ -1344,6 +1344,27 @@
 }
 
 AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+axis2_http_transport_utils_get_not_implemented(
+    const axutil_env_t * env,
+    axis2_conf_ctx_t * conf_ctx)
+{
+    return "<html><head><title>501 Not Implemented</title></head>"
+        "<body><h2>Not Found</h2><p>The requested Method is not"
+        " implemented on this server.</p></body></html>";
+}
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+axis2_http_transport_utils_get_internal_server_error(
+    const axutil_env_t * env,
+    axis2_conf_ctx_t * conf_ctx)
+{
+    return "<html><head><title>500 Internal Server Error</title></head>"
+        "<body><h2>Not Found</h2><p>The server encountered an unexpected"
+        " condition which prevented it from fulfilling the request."
+        "</p></body></html>";
+}
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
 axis2_http_transport_utils_get_method_not_allowed(
     const axutil_env_t * env,
     axis2_conf_ctx_t * conf_ctx)



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org