axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From din...@apache.org
Subject svn commit: r557749 - in /webservices/axis2/scratch/c/dinesh/602/c/src/core/transport/tcp: receiver/tcp_worker.c sender/tcp_transport_sender.c
Date Thu, 19 Jul 2007 19:28:33 GMT
Author: dinesh
Date: Thu Jul 19 12:28:30 2007
New Revision: 557749

URL: http://svn.apache.org/viewvc?view=rev&rev=557749
Log:
tcp sender improved, more error handling

Modified:
    webservices/axis2/scratch/c/dinesh/602/c/src/core/transport/tcp/receiver/tcp_worker.c
    webservices/axis2/scratch/c/dinesh/602/c/src/core/transport/tcp/sender/tcp_transport_sender.c

Modified: webservices/axis2/scratch/c/dinesh/602/c/src/core/transport/tcp/receiver/tcp_worker.c
URL: http://svn.apache.org/viewvc/webservices/axis2/scratch/c/dinesh/602/c/src/core/transport/tcp/receiver/tcp_worker.c?view=diff&rev=557749&r1=557748&r2=557749
==============================================================================
--- webservices/axis2/scratch/c/dinesh/602/c/src/core/transport/tcp/receiver/tcp_worker.c
(original)
+++ webservices/axis2/scratch/c/dinesh/602/c/src/core/transport/tcp/receiver/tcp_worker.c
Thu Jul 19 12:28:30 2007
@@ -118,6 +118,7 @@
     axutil_stream_t *svr_stream = NULL;
     axis2_char_t *buffer = NULL;
     int len = 0;
+    int write = -1;
 
     reader = axiom_xml_reader_create_for_memory(env, simple_request,
         axutil_strlen(simple_request), NULL, AXIS2_XML_PARSER_TYPE_BUFFER);
@@ -181,9 +182,18 @@
     len = out_stream->len;
 
     if (svr_stream && buffer)
-        axutil_stream_write (svr_stream, env, buffer, len + 1);
+    {
+        write = axutil_stream_write (svr_stream, env, buffer, len + 1);
+        if (write < 0)
+        {
+            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "stream write failed");
+            return AXIS2_FAILURE;
+        }
+        axutil_stream_close (svr_stream, env);
+        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "stream wrote:%s", buffer);
+    }
 
-    return AXIS2_TRUE;
+    return AXIS2_SUCCESS;
 }
 
 static axis2_status_t 

Modified: webservices/axis2/scratch/c/dinesh/602/c/src/core/transport/tcp/sender/tcp_transport_sender.c
URL: http://svn.apache.org/viewvc/webservices/axis2/scratch/c/dinesh/602/c/src/core/transport/tcp/sender/tcp_transport_sender.c?view=diff&rev=557749&r1=557748&r2=557749
==============================================================================
--- webservices/axis2/scratch/c/dinesh/602/c/src/core/transport/tcp/sender/tcp_transport_sender.c
(original)
+++ webservices/axis2/scratch/c/dinesh/602/c/src/core/transport/tcp/sender/tcp_transport_sender.c
Thu Jul 19 12:28:30 2007
@@ -26,9 +26,10 @@
 #include <axis2_tcp_transport.h>
 #include <axis2_tcp_sender.h>
 #include <axiom_soap_body.h>
+#include <axiom_soap.h>
 #include <axutil_types.h>
 
-
+#define RES_BUFF 50
 /**
  * TCP Transport Sender struct impl
  * Axis2 TCP Transport Sender impl
@@ -159,43 +160,186 @@
 
     is_server = axis2_msg_ctx_get_server_side (msg_ctx, env);
 
-    if (is_server)
-    {
-        soap_envelope = axis2_msg_ctx_get_soap_envelope(msg_ctx, env);
+    soap_envelope = axis2_msg_ctx_get_soap_envelope(msg_ctx, env);
     
-        xml_writer = axiom_xml_writer_create_for_memory(env, NULL,
+    xml_writer = axiom_xml_writer_create_for_memory(env, NULL,
                                                     AXIS2_TRUE, 0, 
                                                     AXIS2_XML_PARSER_TYPE_BUFFER);
-        if (!xml_writer)
+    if (!xml_writer)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                        "[tcp]Failed to create XML writer");
+        return AXIS2_FAILURE;
+    }
+    
+    om_output = axiom_output_create(env, xml_writer);
+    if (!om_output)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                        "[tcp]Failed to create OM output");
+        axiom_xml_writer_free(xml_writer, env);
+        xml_writer = NULL;
+        return AXIS2_FAILURE;
+    }
+    
+    axiom_soap_envelope_serialize(soap_envelope, env, om_output, AXIS2_FALSE);
+    
+    buffer = (axis2_char_t *)axiom_xml_writer_get_xml(xml_writer, env);
+    if (!buffer)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                        "[tcp]Failed to serialize the SOAP envelope");
+        return AXIS2_FAILURE;
+    }
+    buffer_size = axiom_xml_writer_get_xml_size (xml_writer, env);
+
+    if (is_server)
+    {
+        out_stream = axis2_msg_ctx_get_transport_out_stream (msg_ctx, env);
+        axutil_stream_write (out_stream, env, buffer, buffer_size);
+    }
+    else
+    {
+        axis2_endpoint_ref_t *to = NULL;
+        axutil_url_t *to_url = NULL;
+        const axis2_char_t *to_str = NULL;
+        const axis2_char_t *host = NULL;
+        int port = 0;
+        int socket = -1;
+        axutil_stream_t *stream;
+        int write = -1;
+        int read = -1;
+        axis2_char_t buff [1];
+        axis2_char_t *res_buffer = (axis2_char_t *)AXIS2_MALLOC (env->allocator, 
+                                                                 RES_BUFF);
+        int res_size = 0;
+        int size = 0;
+        axiom_xml_reader_t *reader = NULL;
+        axiom_stax_builder_t *builder = NULL;
+        axiom_soap_builder_t *soap_builder = NULL;
+        axiom_soap_envelope_t *soap_envelope = NULL;
+
+        to = axis2_msg_ctx_get_to (msg_ctx, env);
+
+        if (!to)
+        {
+            AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "To epr not presant");
+            return AXIS2_FAILURE;
+        }
+
+        to_str = axis2_endpoint_ref_get_address (to, env);
+        if (!to_str)
+        {
+            AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, 
+                             "unable to convert epr to string");
+            return AXIS2_FAILURE;
+        }
+
+        to_url = axutil_url_parse_string (env, to_str);
+
+        if (!to_url)
+        {
+            AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, 
+                             "unable to parser string to url");
+            return AXIS2_FAILURE;
+        }
+
+
+        host = axutil_url_get_server (to_url, env);
+        if (!host)
+        {
+            AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, 
+                             "retrieving host failed");
+            return AXIS2_FAILURE;
+        }
+
+        port = axutil_url_get_port (to_url, env);
+        if (!port)
+        {
+            AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, 
+                             "retrieving port failed");
+            return AXIS2_FAILURE;
+        }
+
+        AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "host:%s port:%d",host, port);
+
+        socket = axutil_network_handler_open_socket (env, host, port);
+        if (!socket)
+        {
+            AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "socket creation failed");
+            return AXIS2_FAILURE;
+        }
+
+        stream = axutil_stream_create_socket (env, socket);
+        if (!stream)
+        {
+            AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "stream creation failed");
+            return AXIS2_FAILURE;
+        }
+
+        write = axutil_stream_write (stream, env, buffer, buffer_size);
+        if (write < 0)
+        {
+            AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "stream write error");
+            return AXIS2_FAILURE;
+        }
+        AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "stream wrote soap msg: %s", 
+                         buffer);
+        size = RES_BUFF;
+        while ((read = axutil_stream_read (stream, env, &buff, 1)) > 0)
+        {
+            if (res_size >= size)
+            {
+                axis2_char_t *tmp_buff = NULL;
+                size <<= 2;
+                tmp_buff = AXIS2_MALLOC (env->allocator, size);
+                memcpy (tmp_buff, res_buffer, res_size);
+                AXIS2_FREE (env->allocator, res_buffer);
+                res_buffer = tmp_buff;
+            }
+            memcpy (res_buffer + res_size, buff, 1);
+            res_size ++;
+        }
+
+        reader = axiom_xml_reader_create_for_memory(
+            env, res_buffer, res_size, 
+            NULL, 
+            AXIS2_XML_PARSER_TYPE_BUFFER);
+
+        if (!reader)
         {
             AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
-                            "[tcp]Failed to create XML writer");
+                            "Failed to create XML reader");
             return AXIS2_FAILURE;
         }
-        
-        om_output = axiom_output_create(env, xml_writer);
-        if (!om_output)
+
+        builder = axiom_stax_builder_create(env, reader);
+        if (!builder)
         {
             AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
-                            "[tcp]Failed to create OM output");
-            axiom_xml_writer_free(xml_writer, env);
-            xml_writer = NULL;
+                            "Failed to create Stax builder");
             return AXIS2_FAILURE;
         }
-        
-        axiom_soap_envelope_serialize(soap_envelope, env, om_output, AXIS2_FALSE);
-        
-        buffer = (axis2_char_t *)axiom_xml_writer_get_xml(xml_writer, env);
-        if (!buffer)
+
+        soap_builder = axiom_soap_builder_create(
+            env, builder,
+            AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI);
+        if (!soap_builder)
         {
             AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
-                            "[tcp]Failed to serialize the SOAP envelope");
+                            "Failed to create SOAP builder");
             return AXIS2_FAILURE;
         }
-        buffer_size = axiom_xml_writer_get_xml_size (xml_writer, env);
+        soap_envelope = axiom_soap_builder_get_soap_envelope (soap_builder, env);
 
-        out_stream = axis2_msg_ctx_get_transport_out_stream (msg_ctx, env);
-        axutil_stream_write (out_stream, env, buffer, buffer_size);
+        if (!soap_envelope)
+        {
+            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                            "Failed to create SOAP envelope");
+            return AXIS2_FAILURE;
+        }
+
+        axis2_msg_ctx_set_response_soap_envelope (msg_ctx, env, soap_envelope);
         
     }
     AXIS2_LOG_DEBUG (env->log, AXIS2_LOG_SI, "end:tcp transport sender invoke");



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


Mime
View raw message