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 da...@apache.org on 2004/12/31 12:30:48 UTC
cvs commit: ws-axis/c/tests/utils/simple-server-client build_client.sh build_server.sh cli.cpp cli_message.txt readme serv.cpp serv_message.txt
damitha 2004/12/31 03:30:48
Added: c/tests/utils/simple-server-client build_client.sh
build_server.sh cli.cpp cli_message.txt readme
serv.cpp serv_message.txt
Log:
added a small testing server and client. Read the readme file in the folder
for further info
Revision Changes Path
1.1 ws-axis/c/tests/utils/simple-server-client/build_client.sh
Index: build_client.sh
===================================================================
g++ -I/usr/local/ssl/include -L/usr/local/ssl/lib -lssl cli.cpp -ocli
1.1 ws-axis/c/tests/utils/simple-server-client/build_server.sh
Index: build_server.sh
===================================================================
g++ -I/usr/local/ssl/include -L/usr/local/ssl/lib -lssl serv.cpp -oserv
1.1 ws-axis/c/tests/utils/simple-server-client/cli.cpp
Index: cli.cpp
===================================================================
#include <stdio.h>
#include <memory.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdlib.h>
#include <string>
#define CHK_NULL(x) if ((x)==NULL) exit (1)
#define CHK_ERR(err,s) if ((err)==-1){ perror(s); exit(1); }
const unsigned int INVALID_SOCKET = 0;
const int SOCKET_ERROR = -1;
int main ()
{
int err;
int sd;
struct sockaddr_in sa;
char* str;
char buf [4096];
char msg [8096];
int message_size = 8192;
// Message that comes on the wire. This could be a soap message or
// mime or chunked data
char msgLine[message_size];
FILE* pFile;
char filename[32];
strcpy(filename, "cli_message.txt");
// Open the file to read the message
if ((pFile = fopen (filename, "r")) == NULL)
return 1;
char sLine[message_size];
std::string message = msgLine;
// Read the properly formatted soap message
while(fgets (sLine, message_size, pFile) != NULL )
{
message += sLine;
message.replace(message.length() -1 , 1, "\r\n");
}
printf("message:%s\n", message.c_str());
// -----------------------------------------------
// Create a socket and connect to server using normal socket calls.
sd = socket (AF_INET, SOCK_STREAM, 0);
CHK_ERR(sd, "socket");
memset (&sa, '\0', sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr ("127.0.0.1"); // Server IP
sa.sin_port = htons (1111); // Server Port number
err = connect(sd, (struct sockaddr*) &sa,
sizeof(sa));
CHK_ERR(err, "connect");
// ---------------------------------------------------
// DATA EXCHANGE - Send a message and receive a reply.
if( (err = send( sd, message.c_str(), strlen(message.c_str()), MSG_DONTROUTE)) == SOCKET_ERROR)
{
printf( "<write exception, error no:%d\n", err);
}
int nByteRecv = 0;
int msg_size = 0;
do
{
if( (nByteRecv = recv(sd, buf, sizeof(buf)-1, 0)) == SOCKET_ERROR)
{
printf( "Channel error while getting data\n");
}
if( nByteRecv)
{
// printf("nByteRecv:%d\n", nByteRecv);
buf[nByteRecv] = '\0';
strcpy(msg, buf);
msg_size += nByteRecv;
}
else
{
printf ("execution break\n");
}
}
while(nByteRecv < 0);
msg[msg_size] = '\0';
printf ("Got %d chars:\n%s\n", msg_size, buf);
// Clean up.
//close (sd);
return 0;
}
// EOF - cli.cpp
1.1 ws-axis/c/tests/utils/simple-server-client/cli_message.txt
Index: cli_message.txt
===================================================================
HTTP/1.1 200 OK
Date: Sat, 27 Nov 2004 11:59:29 GMT
Server: Apache/2.0.52 (Unix) mod_ssl/2.0.52 OpenSSL/0.9.7e
Content-Type: Multipart/Related; boundary=mime-bound; type=text/xml; start=\"mimeroot-start\"
Content-Length: 400
Content-Type: text/xml
--mime-bound
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: mimeroot-start
<?xml version='1.0' encoding='utf-8' ?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><SOAP-ENV:Body><ns1:addResponse xmlns:ns1=\"http://localhost/axis/Calculator\"><addReturn xsi:type=\"xsd:int\">15</addReturn></ns1:addResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
--mime-bound
Content-Type: image/tiff
Content-Transfer-Encoding: base64
Content-ID: cont1
dfdsfsdfowesdfsdfowefsdfslsdfffffffffffffffowefsdfoefhosdfwoehdsfoiwefhodsfwefnodsiftwefnweo
--mime-bound
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-ID: cont2
fsdffffffffffffffffffdswodfowefhdosfwefhosdfwehosdfhloewofhdsofwefosdfwefbowewefnow
--mime-bound--
1.1 ws-axis/c/tests/utils/simple-server-client/readme
Index: readme
===================================================================
We have a test server and client here
The purpose of the test server is to provide a testing environment
for a soap client engine. It just accept whatever the request
sent to it, dicard it and then send back a hard coded soap message
read from a file. This is very useful to test a client engine with
different soap messages.
The purpose of the test client is to provide a testing environment
for a soap server engine. Client can send arbirtray messages read from
a file and send it to a server. It then read the response sent from the
server
to build the test server
sh build_server.sh
to run the server
./serv
Then this will listen to client request
Once a request comes it just receive it and discard it.
It read from the serv_message.txt file and
this is what it returns as the response.
So you need to paste properly formatted soap message that you
need to test ,into serv_message.txt, before you start the server.
Before you build the client just change the host
and port against which you need to test it with.
Also paste your message to test into cli_message.txt file.
to build the client
sh build_client.sh
to run the client
./cli
1.1 ws-axis/c/tests/utils/simple-server-client/serv.cpp
Index: serv.cpp
===================================================================
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <memory.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <string>
const unsigned int INVALID_SOCKET = 0;
const int SOCKET_ERROR = -1;
#define CHK_NULL(x) if ((x)==NULL) exit (1)
#define CHK_ERR(err,s) if ((err)==-1) { perror(s); exit(1); }
int main ()
{
int err;
int listen_sd;
int sd;
struct sockaddr_in sa_serv;
struct sockaddr_in sa_cli;
size_t client_len;
char* str;
char buf [4096];
int message_size = 8192;
// Message that comes on the wire. This could be a soap message or
// mime or chunked data
char msgLine[message_size];
FILE* pFile;
char filename[32];
strcpy(filename, "serv_message.txt");
// Open the file to read the message
if ((pFile = fopen (filename, "r")) == NULL)
return 1;
char sLine[message_size];
std::string message = msgLine;
// Read the properly formatted soap message
while(fgets (sLine, message_size, pFile) != NULL )
{
message += sLine;
message.replace(message.length() -1 , 1, "\r\n");
}
// Prepare TCP socket for receiving connections
listen_sd = socket (AF_INET, SOCK_STREAM, 0);
CHK_ERR(listen_sd, "socket");
memset (&sa_serv, '\0', sizeof(sa_serv));
sa_serv.sin_family = AF_INET;
sa_serv.sin_addr.s_addr = INADDR_ANY;
sa_serv.sin_port = htons (1111); // Server Port number
err = bind(listen_sd, (struct sockaddr*) &sa_serv,
sizeof (sa_serv));
CHK_ERR(err, "bind");
// Receive a TCP connection.
err = listen (listen_sd, 5);
CHK_ERR(err, "listen");
client_len = sizeof(sa_cli);
sd = accept (listen_sd, (struct sockaddr*) &sa_cli, &client_len);
CHK_ERR(sd, "accept");
close (listen_sd);
printf ("Connection from %lx, port %x\n",
sa_cli.sin_addr.s_addr, sa_cli.sin_port);
int nByteRecv = 0;
int recv_msg_size = 0;
char recv_msg[8096];
do
{
if( (nByteRecv = recv( sd, buf, sizeof(buf)-1, 0)) == SOCKET_ERROR)
{
printf( "Channel error while getting data\n");
}
if( nByteRecv)
{
// printf("nByteRecv:%d\n", nByteRecv);
buf[nByteRecv] = '\0';
strcpy(recv_msg, buf);
recv_msg_size += nByteRecv;
}
else
{
printf ("execution break\n");
}
}
while(nByteRecv < 0);
// DATA EXCHANGE - Receive message and send reply.
recv_msg[recv_msg_size] = '\0';
printf ("Received message:\n%s\n", buf);
if( (err = send( sd, message.c_str(), strlen(message.c_str()), MSG_DONTROUTE)) == SOCKET_ERROR)
{
printf( "<write exception, error no:%d\n", err);
}
// Clean up.
close (sd);
return 0;
}
// EOF - serv.cpp
1.1 ws-axis/c/tests/utils/simple-server-client/serv_message.txt
Index: serv_message.txt
===================================================================
HTTP/1.1 200 OK
Date: Sat, 27 Nov 2004 11:59:29 GMT
Server: Apache/2.0.52 (Unix) mod_ssl/2.0.52 OpenSSL/0.9.7e
Content-Type: Multipart/Related; boundary=mime-bound; type=text/xml; start=\"mimeroot-start\"
Content-Length: 400
Content-Type: text/xml
--mime-bound
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: mimeroot-start
<?xml version='1.0' encoding='utf-8' ?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><SOAP-ENV:Body><ns1:addResponse xmlns:ns1=\"http://localhost/axis/Calculator\"><addReturn xsi:type=\"xsd:int\">15</addReturn></ns1:addResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
--mime-bound
Content-Type: image/tiff
Content-Transfer-Encoding: base64
Content-ID: cont1
dfdsfsdfowesdfsdfowefsdfslsdfffffffffffffffowefsdfoefhosdfwoehdsfoiwefhodsfwefnodsiftwefnweo
--mime-bound
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-ID: cont2
fsdffffffffffffffffffdswodfowefhdosfwefhosdfwehosdfhloewofhdsofwefosdfwefbowewefnow
--mime-bound--