-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I have implemented some methods which were not there, in
axis2_http_transport_utils. Please apply the patch and commit the code.

- - Sahan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iQEVAwUBQ8S4BanIlEsDdb85AQLJcQgAg3r/r0ARn/fEBsgvlgMKI9gEdMHksQjc
VMlsAlheVweBuO6tJWqvoOyeuWorlGHtA7Yh99A0wciiX1mwOfVHXBIvjoPsPKwo
HR4XaUGkeT2HuVql6KVuF93U+oS9fUiM/ahfUTIM8cXg4avj0R8fjm4/cbNVQpop
lSz1jgKqgS1zokg5UAj3Hne1ZV7w9/z4SHMgzNrpp+gKqbUMXh0TfpcwAdQ2ODe+
YmNH6OI0HeTl/0PNatSgcOB6V+Hq0CQGsS1lOLDE95KI3mlNH1H/Bti7AAT6PEQb
exVAjrpt3EVgl+gFRGfja7yXmN3iWQjkOrqya+aGE99pXZbJy1ixyg==
=Rd0x
-----END PGP SIGNATURE-----

Index: include/axis2_http_transport_utils.h
===================================================================
--- include/axis2_http_transport_utils.h        (revision 367957)
+++ include/axis2_http_transport_utils.h        (working copy)
@@ -32,6 +32,7 @@
 #include <axis2_hash.h>
 #include <axis2_om_element.h>
 #include <axis2_stream.h>
+#include <axis2_soap_envelope.h>
 
 #ifdef __cplusplus
 extern "C"
@@ -42,6 +43,17 @@
  * @ingroup axis2_core_transport_http
  * @{
  */
+
+/* 
+ * struct to hold the callback information
+ */    
+struct axis2_callback_info
+{
+       axis2_env_t *env;
+       axis2_stream_t *in_stream;
+};
+typedef struct axis2_callback_info axis2_callback_info_t;
+
 axis2_status_t AXIS2_CALL 
 axis2_http_transport_utils_process_http_post_request
                         (axis2_env_t **env, axis2_msg_ctx_t *msg_ctx, 
@@ -53,15 +65,16 @@
 axis2_bool_t AXIS2_CALL 
 axis2_http_transport_utils_process_http_get_request
                         (axis2_env_t **env, axis2_msg_ctx_t *msg_ctx,
-                        axis2_stream_t *stream, axis2_char_t *content_type,
+                        axis2_stream_t *in_stream, axis2_stream_t *out_stream,
+                                               axis2_char_t *content_type,
                         axis2_char_t *soap_action_header, 
                         axis2_char_t *request_uri, axis2_conf_ctx_t *conf_ctx, 
                         axis2_hash_t *request_params);
     
-/*axis2_soap_envelope_t* AXIS2_CALL 
+axis2_soap_envelope_t* AXIS2_CALL 
 axis2_http_transport_utils_create_envelope_from_get_request
                         (axis2_env_t **env, axis2_char_t *request_uri,
-                        axis2_hash_t *request_params);*/
+                        axis2_hash_t *request_params);
     
 axis2_om_stax_builder_t* AXIS2_CALL 
 axis2_http_transport_utils_select_builder_for_mime
Index: modules/core/transport/http/axis2_http_worker.c
===================================================================
--- modules/core/transport/http/axis2_http_worker.c     (revision 367957)
+++ modules/core/transport/http/axis2_http_worker.c     (working copy)
@@ -200,7 +200,7 @@
                                                simple_request, env), env), 
AXIS2_HTTP_HEADER_GET))
        {
                processed = axis2_http_transport_utils_process_http_get_request
-                        (env, msg_ctx, request_body, 
+                        (env, msg_ctx, request_body, out_stream,
                                                
AXIS2_HTTP_SIMPLE_REQUEST_GET_CONTENT_TYPE(
                                                simple_request, env) 
,soap_action,
                                                AXIS2_HTTP_REQUEST_LINE_GET_URI(
Index: modules/core/transport/http/axis2_http_transport_utils.c
===================================================================
--- modules/core/transport/http/axis2_http_transport_utils.c    (revision 
367957)
+++ modules/core/transport/http/axis2_http_transport_utils.c    (working copy)
@@ -21,6 +21,13 @@
 #include <axis2_op.h>
 #include <axis2_qname.h>
 #include <axis2_http_transport.h>
+#include <axis2_soap_model_builder.h>
+#include <axis2_engine.h>
+#include <axis2_soap_body.h>
+#include <axis2_utils.h>
+#include <axis2_om_namespace.h>
+#include <axis2_om_node.h>
+#include <axis2_hash.h>
 
 /***************************** Function headers 
*******************************/
 
@@ -35,15 +42,16 @@
 axis2_bool_t AXIS2_CALL 
 axis2_http_transport_utils_process_http_get_request
                         (axis2_env_t **env, axis2_msg_ctx_t *msg_ctx,
-                        axis2_stream_t *stream, axis2_char_t *content_type,
+                        axis2_stream_t *in_stream, axis2_stream_t *out_stream,
+                                               axis2_char_t *content_type,
                         axis2_char_t *soap_action_header, 
                         axis2_char_t *request_uri, axis2_conf_ctx_t *conf_ctx, 
                         axis2_hash_t *request_params);
     
-/*axis2_soap_envelope_t* AXIS2_CALL 
+axis2_soap_envelope_t* AXIS2_CALL 
 axis2_http_transport_utils_create_envelope_from_get_request
                         (axis2_env_t **env, axis2_char_t *request_uri,
-                        axis2_hash_t *request_params);*/
+                        axis2_hash_t *request_params);
     
 axis2_om_stax_builder_t* AXIS2_CALL 
 axis2_http_transport_utils_select_builder_for_mime
@@ -77,7 +85,11 @@
 axis2_char_t* AXIS2_CALL
 axis2_http_transport_utils_get_services_html(axis2_env_t **env, 
                                                        axis2_conf_ctx_t 
*conf_ctx);
-                                
+axis2_char_t* AXIS2_CALL
+axis2_http_transport_utils_get_charset_enc(axis2_env_t **env, 
+                                               axis2_char_t *content_type);
+int
+axis2_http_transport_utils_on_data_request(char *buffer, int size, void *ctx); 
                                        
 /***************************** End of function headers 
************************/
 
 axis2_status_t AXIS2_CALL 
@@ -88,11 +100,27 @@
                         axis2_char_t *soap_action_header,
                         axis2_char_t *request_uri)
 {
+       axis2_soap_envelope_t *soap_envelope = NULL;
+       axis2_soap_model_builder_t *soap_builder = NULL;
+       axis2_om_stax_builder_t *om_builder = NULL;
+       axis2_bool_t is_soap11 = AXIS2_FALSE;
+       axis2_xml_reader_t *xml_reader = NULL;
+       axis2_char_t *char_set = NULL;
+       axis2_char_t *xml_char_set = NULL;
+       axis2_conf_ctx_t *conf_ctx = NULL;
+       axis2_callback_info_t callback_ctx;
+       
     AXIS2_PARAM_CHECK((*env)->error, msg_ctx, AXIS2_FAILURE);
        AXIS2_PARAM_CHECK((*env)->error, in_stream, AXIS2_FAILURE);
        AXIS2_PARAM_CHECK((*env)->error, out_stream, AXIS2_FAILURE);
        AXIS2_PARAM_CHECK((*env)->error, content_type, AXIS2_FAILURE);
        AXIS2_PARAM_CHECK((*env)->error, request_uri, AXIS2_FAILURE);
+       
+       conf_ctx = AXIS2_MSG_CTX_GET_CONF_CTX(msg_ctx, env);
+       
+       callback_ctx.in_stream = in_stream;
+       callback_ctx.env = *env;
+       
        if(NULL != soap_action_header)  
        {
                /* remove leading and trailing " s */
@@ -105,42 +133,218 @@
                {
                        soap_action_header[strlen(soap_action_header) -1] = 
'\0';
                }
-               AXIS2_MSG_CTX_SET_WSA_ACTION(msg_ctx, env, soap_action_header);
-               AXIS2_MSG_CTX_SET_SOAP_ACTION(msg_ctx, env, soap_action_header);
-               AXIS2_MSG_CTX_SET_TO(msg_ctx, env, 
axis2_endpoint_ref_create(env, 
-                                               request_uri));
-               AXIS2_MSG_CTX_SET_PROPERTY(msg_ctx, env, 
-                                               AXIS2_TRANSPORT_OUT, 
out_stream, AXIS2_FALSE);
-               AXIS2_MSG_CTX_SET_SERVER_SIDE(msg_ctx, env, AXIS2_TRUE);
-               
-               
        }
-       /*
-        TODO code
-    */
-    return AXIS2_SUCCESS;
+       AXIS2_MSG_CTX_SET_WSA_ACTION(msg_ctx, env, soap_action_header);
+       AXIS2_MSG_CTX_SET_SOAP_ACTION(msg_ctx, env, soap_action_header);
+       AXIS2_MSG_CTX_SET_TO(msg_ctx, env, axis2_endpoint_ref_create(env, 
+                                       request_uri));
+       AXIS2_MSG_CTX_SET_PROPERTY(msg_ctx, env, 
+                                       AXIS2_TRANSPORT_OUT, out_stream, 
AXIS2_FALSE);
+       AXIS2_MSG_CTX_SET_SERVER_SIDE(msg_ctx, env, AXIS2_TRUE);
+       
+       xml_reader = axis2_xml_reader_create_for_memory(env, 
+                                               
axis2_http_transport_utils_on_data_request, 
+                                               (void *)&callback_ctx, NULL);
+       char_set = axis2_http_transport_utils_get_charset_enc(env,content_type);
+       /* TODO set the charset of the stream before (at least default)
+        *      we read them
+        */
+       AXIS2_MSG_CTX_SET_PROPERTY(msg_ctx, env, AXIS2_CHARACTER_SET_ENCODING,
+                                       char_set, AXIS2_TRUE);
+       om_builder = axis2_om_stax_builder_create(env, xml_reader);
+       if(NULL != strstr(content_type, AXIS2_HTTP_HEADER_ACCEPT_APPL_SOAP))
+       {
+               is_soap11 = AXIS2_FALSE;
+               soap_builder = axis2_soap_model_builder_create(env, om_builder);
+               /* TODO set the soap12 namespace URI */
+               soap_envelope = 
AXIS2_SOAP_MODEL_BUILDER_GET_SOAP_ENVELOPE(soap_builder,
+                                       env);
+       }
+       else if(NULL != strstr(content_type, AXIS2_HTTP_HEADER_ACCEPT_TEXT_XML))
+       {
+               is_soap11 = AXIS2_TRUE;
+               if(NULL != soap_action_header && 
AXIS2_STRLEN(soap_action_header)
+                                       > 0)
+               {
+                       soap_builder = axis2_soap_model_builder_create(env, 
om_builder);
+                       /* TODO set the soap11 namespace URI */
+                       soap_envelope = 
AXIS2_SOAP_MODEL_BUILDER_GET_SOAP_ENVELOPE(
+                                       soap_builder, env);
+               }
+               /* REST support
+                * else
+                * {
+                *              envelope = 
AXIS2_SOAP_ENVELOPE_GET_DEFAULT_SOAP_ENVELOPE(
+                *                      env);
+                *              
AXIS2_SOAP_BODY_ADD_CHILD(AXIS2_SOAP_ENVELOPE_GET_BODY(
+                *                      envelope, env), 
AXIS2_OM_STAX_BUILDER_GET_DOCUMENT(
+                *                      om_builder, env));
+                */                     
+       }
+       /* xml_char_set = AXIS2_OM_DOCUMENT_GET_CHARSET_ENC(
+        *                                      
AXIS2_OM_STAX_BUILDER_GET_DOCUMENT(env om_builder),
+        *                                      env);
+        *
+        *if(0 != AXIS2_STRCMP(char_set, xml_char_set))
+        *{
+        *      AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_CHARSET_MISMATCH, 
+        *                                      AXIS2_FAILURE);
+        *      AXIS2_SOAP_ENVELOPE_FREE(envelope, env);
+        *      envelope = NULL;
+        *      AXIS2_XML_READER_FREE(xml_reader, env);
+        *      xml_reader = NULL;
+        *      AXIS2_OM_STAX_BUILDER_FREE(om_builder, env);
+        *      om_builder = NULL;
+        *      if(NULL != soap_builder)
+        *      {
+        *              AXIS2_SOAP_MODEL_BUILDER_FREE(soap_builder, env);
+        *              soap_builder = NULL;
+        *      }
+        *      return AXIS2_FAILURE;
+        *}
+        */
+       
+       AXIS2_MSG_CTX_SET_SOAP_ENVELOPE(msg_ctx, env, soap_envelope);
+       axis2_engine_t *engine = NULL;
+       engine = axis2_engine_create(env, conf_ctx);
+       if(AXIS2_TRUE == AXIS2_SOAP_BODY_HAS_FAULT(AXIS2_SOAP_ENVELOPE_GET_BODY(
+                                               soap_envelope, env), env))
+       {
+               AXIS2_ENGINE_RECEIVE_FAULT(engine, env, msg_ctx);
+       }
+       else
+       {
+               AXIS2_ENGINE_RECEIVE(engine, env, msg_ctx);
+       }
+       if(NULL == AXIS2_MSG_CTX_GET_SOAP_ENVELOPE(msg_ctx, env) && 
+                                               AXIS2_FALSE == is_soap11)
+       {
+               axis2_soap_envelope_t *def_envelope = 
axis2_soap_envelope_create_null
+                                               (env);
+               AXIS2_MSG_CTX_SET_SOAP_ENVELOPE(msg_ctx, env, def_envelope);
+       }
+       return AXIS2_SUCCESS;
 }
 
 
 axis2_bool_t AXIS2_CALL 
 axis2_http_transport_utils_process_http_get_request
                         (axis2_env_t **env, axis2_msg_ctx_t *msg_ctx,
-                        axis2_stream_t *stream, axis2_char_t *content_type,
+                        axis2_stream_t *in_stream, axis2_stream_t *out_stream,
+                                               axis2_char_t *content_type,
                         axis2_char_t *soap_action_header, 
                         axis2_char_t *request_uri, axis2_conf_ctx_t *conf_ctx, 
                         axis2_hash_t *request_params)
 {
+       axis2_soap_envelope_t *soap_envelope = NULL;
+       axis2_engine_t *engine = NULL;
+               
+       AXIS2_PARAM_CHECK((*env)->error, msg_ctx, AXIS2_FALSE);
+       AXIS2_PARAM_CHECK((*env)->error, in_stream, AXIS2_FALSE);
+       AXIS2_PARAM_CHECK((*env)->error, out_stream, AXIS2_FALSE);
+       AXIS2_PARAM_CHECK((*env)->error, content_type, AXIS2_FALSE);
+       AXIS2_PARAM_CHECK((*env)->error, request_uri, AXIS2_FALSE);
+       AXIS2_PARAM_CHECK((*env)->error, request_params, AXIS2_FALSE);
+       
+       if(NULL != soap_action_header)  
+       {
+               /* remove leading and trailing " s */
+               if('"' == soap_action_header[0])
+               {
+                       memmove(soap_action_header, 
soap_action_header+sizeof(axis2_char_t),
+                                               strlen(soap_action_header) + 
sizeof(axis2_char_t));
+               }
+               if('"' == soap_action_header[strlen(soap_action_header) -1])
+               {
+                       soap_action_header[strlen(soap_action_header) -1] = 
'\0';
+               }
+       }
+       AXIS2_MSG_CTX_SET_WSA_ACTION(msg_ctx, env, soap_action_header);
+       AXIS2_MSG_CTX_SET_SOAP_ACTION(msg_ctx, env, soap_action_header);
+       AXIS2_MSG_CTX_SET_TO(msg_ctx, env, axis2_endpoint_ref_create(env, 
+                                       request_uri));
+       AXIS2_MSG_CTX_SET_PROPERTY(msg_ctx, env, 
+                                       AXIS2_TRANSPORT_OUT, out_stream, 
AXIS2_FALSE);
+       AXIS2_MSG_CTX_SET_SERVER_SIDE(msg_ctx, env, AXIS2_TRUE);
+       
+       soap_envelope = 
axis2_http_transport_utils_create_envelope_from_get_request(
+                                       env, request_uri, request_params);
+       if(NULL == soap_envelope)
+       {
+               return AXIS2_FALSE;
+       }
+       else
+       {
+               AXIS2_MSG_CTX_SET_DOING_REST(msg_ctx, env, AXIS2_TRUE);
+               AXIS2_MSG_CTX_SET_SOAP_ENVELOPE(msg_ctx, env, soap_envelope);
+               engine = axis2_engine_create(env, conf_ctx);
+               AXIS2_ENGINE_RECEIVE(engine, env, msg_ctx);
+               return AXIS2_TRUE;
+       }
     return AXIS2_FALSE;
 }
 
 
-/*axis2_soap_envelope_t* AXIS2_CALL 
+axis2_soap_envelope_t* AXIS2_CALL 
 axis2_http_transport_utils_create_envelope_from_get_request
                         (axis2_env_t **env, axis2_char_t *request_uri,
                         axis2_hash_t *request_params)
 {
-    return NULL;
-}*/
+       axis2_char_t **values = NULL;
+       axis2_soap_envelope_t *envelope = NULL;
+       axis2_om_namespace_t *om_ns = NULL;
+       axis2_om_namespace_t *def_om_ns = NULL;
+       axis2_om_node_t *document_node = NULL;
+       axis2_om_node_t *op_node = NULL;
+       axis2_om_element_t *op_ele = NULL;
+       axis2_hash_index_t *hi = NULL;
+       AXIS2_PARAM_CHECK((*env)->error, request_uri, NULL);
+       AXIS2_PARAM_CHECK((*env)->error, request_params, NULL);
+       
+       values = axis2_parse_request_url_for_svc_and_op(env, request_uri);
+       if(NULL == values)
+       {
+               return NULL;
+       }
+       if(NULL == values[0] && NULL != values[1])
+       {
+               AXIS2_FREE((*env)->allocator, values[1]);
+               AXIS2_FREE((*env)->allocator, values);
+               return NULL;
+       }
+       if(NULL != values[0] && NULL == values[1])
+       {
+               AXIS2_FREE((*env)->allocator, values[0]);
+               AXIS2_FREE((*env)->allocator, values);
+               return NULL;
+       }
+       if(NULL == values[0] && NULL == values[1])
+       {
+               AXIS2_FREE((*env)->allocator, values);
+               return NULL;
+       }
+       envelope = axis2_soap_envelope_create_null(env);
+       om_ns = axis2_om_namespace_create(env, values[0], "services");
+       def_om_ns = axis2_om_namespace_create(env, "", NULL);
+       document_node = 
AXIS2_SOAP_BODY_GET_BASE_NODE(AXIS2_SOAP_ENVELOPE_GET_BODY(
+                                               envelope, env), env);
+       op_ele = axis2_om_element_create(env, document_node, values[1], om_ns, 
+                                               &op_node);
+       
+       for(hi = axis2_hash_first(request_params, env); NULL != hi; 
+                                               axis2_hash_next(env, hi))
+       {
+               axis2_char_t *name = NULL;
+               axis2_char_t *value = NULL;
+               axis2_om_element_t *tmp_ele = NULL;
+               axis2_om_node_t *tmp_node = NULL;
+               axis2_hash_this(hi, (const void **)&name, NULL, (void**)&value);
+               tmp_ele = axis2_om_element_create(env, op_node, name, 
def_om_ns, 
+                                               &tmp_node);
+               AXIS2_OM_ELEMENT_SET_TEXT(tmp_ele, env, value, tmp_node);
+       }
+    return envelope;
+}
 
 
 axis2_om_stax_builder_t* AXIS2_CALL 
@@ -149,6 +353,9 @@
                         axis2_msg_ctx_t *msg_ctx, axis2_stream_t *in_stream,
                         axis2_char_t *content_type)
 {
+       /*
+        TODO implement when MTOM support is added
+    */
     return NULL;
 }
 
@@ -157,6 +364,9 @@
 axis2_http_transport_utils_is_optimized(axis2_env_t **env, 
                                         axis2_om_element_t *om_element)
 {
+       /*
+        TODO implement when MTOM support is added
+    */
     return AXIS2_FALSE;
 }
 
@@ -424,3 +634,17 @@
        }
        return AXIS2_STRDUP(tmp, env);
 }
+
+int
+axis2_http_transport_utils_on_data_request(char *buffer, int size, void *ctx)
+{
+       axis2_stream_t *in_stream = NULL;
+       axis2_env_t **env = NULL;
+       if(NULL == buffer || NULL == ctx)
+       {
+               return 0;
+       }
+       in_stream = ((axis2_callback_info_t*)ctx)->in_stream;
+       env = &((axis2_callback_info_t*)ctx)->env;
+       return AXIS2_STREAM_READ(in_stream, env, buffer, size);
+}

Reply via email to