You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sa...@apache.org on 2006/01/26 10:12:52 UTC

svn commit: r372490 - /webservices/axis2/trunk/c/test/core/clientapi/test_client.c

Author: sahan
Date: Thu Jan 26 01:12:48 2006
New Revision: 372490

URL: http://svn.apache.org/viewcvs?rev=372490&view=rev
Log:
Fixed bugs in the test. Cleaned up the code

Modified:
    webservices/axis2/trunk/c/test/core/clientapi/test_client.c

Modified: webservices/axis2/trunk/c/test/core/clientapi/test_client.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/test/core/clientapi/test_client.c?rev=372490&r1=372489&r2=372490&view=diff
==============================================================================
--- webservices/axis2/trunk/c/test/core/clientapi/test_client.c (original)
+++ webservices/axis2/trunk/c/test/core/clientapi/test_client.c Thu Jan 26 01:12:48 2006
@@ -10,6 +10,10 @@
 #include <unistd.h>
 #include <axis2.h>
 
+/* Function prototypes */
+int write_to_socket(char *address, char* port, char* filename, char* endpoint);
+/* End of function prototypes */
+
 void error(char *msg)
 {
     perror(msg);
@@ -20,7 +24,7 @@
 {
     axis2_char_t *hostname = "localhost";
     axis2_char_t *port = "9090";
-    axis2_char_t *filename = "soap_req";
+    axis2_char_t *filename = "echo.xml";
     axis2_char_t *endpoint = "/axis2/services/echo/echo";
     int c;
     extern char *optarg;
@@ -74,65 +78,66 @@
          (char *)&serv_addr.sin_addr.s_addr,
          server->h_length);
     serv_addr.sin_port = htons(portno);
-    if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0) 
+    if (connect(sockfd, (struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0) 
         error("ERROR connecting");
 
+    /* Read from file */
     stat(filename, &buf);
-    bufsize = buf.st_size* sizeof(char);
+    bufsize = (buf.st_size + 1) * sizeof(char);
     buffer = (char *) malloc(bufsize);
+    int fd = open(filename, O_RDONLY, 0);
+    if (fd == -1)
+    {
+        printf("can't open file %s\n", filename);
+        return -1;
+    }
+    else
+        printf("opened file %s\n", filename);
+
+    i = read(fd, buffer, bufsize - 1);
+    if (i > 0)
+    {
+        buffer[i] = '\0';
+        printf("%s...\n", buffer);
+    }
 	sprintf(buffer_l, "POST %s HTTP/1.1\r\nUser-Agent: Axis/2.0/C\r\nConnection: Keep-Alive\r\nHost: ", endpoint);
 	strcat(buffer_l, address);
 	strcat(buffer_l, ":");
 	strcat(buffer_l, port);
 	strcat(buffer_l, "\r\n");
 	strcat(buffer_l, "Content-Length: ");
-	sprintf(tmpstr, "%d", buf.st_size - 1);
+	sprintf(tmpstr, "%d", strlen(buffer));
 	strcat(buffer_l, tmpstr);
 	strcat(buffer_l, "\r\n");
 	strcat(buffer_l, "Content-Type: application/soap+xml;\r\n");
 	strcat(buffer_l, "\r\n");
 
-    int fd = open(filename, O_RDONLY, 0);
-    if (fd == -1)
-    {
-        printf("can't open file %s\n", filename);
-        return;
-    }
-    else
-        printf("opened file %s\n", filename);
 	
     printf("Writing buffer_1...\n%s", buffer_l);
 	n = write(sockfd, buffer_l, strlen(buffer_l));
 
-    /*while((i = read(fd, buffer, bufsize - 1)) > 0)
-    {*/
-    i = read(fd, buffer, bufsize - 1);
-        buffer[i] = '\0';
-        printf("%s...\n", buffer);
-    	n = write(sockfd,buffer,strlen(buffer));
-    	if (n < 0) 
-       	    error("ERROR writing to socket");
-    	/*n = write(sockfd,"\r\n",2);
-    	if (n < 0) 
-       	    error("ERROR writing to socket");*/
-    /*}*/
+    n = write(sockfd,buffer,strlen(buffer));
+    if (n < 0) 
+       	error("ERROR writing to socket");
 
     printf("Done writing to server\n");
 
     buffer[0] = '\0';
 	
+    printf("Reading the reply from server :\n");
     while((n = read(sockfd, buffer, bufsize - 1)) > 0)
     {
         buffer[n] = '\0';
-        printf("%s %d\n", buffer, n);
+        printf("%s", buffer);
     }
+    printf("\nReading from server done ...\n");
 
     if (n < 0)
     {
         error("ERROR reading from socket");
         buffer[0] = '\0';
     }
-    printf("%s\n",buffer);
 	free(buffer);
+    return 0;
 }