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 sa...@apache.org on 2004/10/21 07:05:48 UTC

cvs commit: ws-axis/c/samples/client/rpcfault MathOpsClient.cpp

sanjaya     2004/10/20 22:05:48

  Modified:    c/samples/client/rpcfault MathOpsClient.cpp
  Log:
  argument format of client changed
  
  Revision  Changes    Path
  1.9       +62 -30    ws-axis/c/samples/client/rpcfault/MathOpsClient.cpp
  
  Index: MathOpsClient.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/samples/client/rpcfault/MathOpsClient.cpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- MathOpsClient.cpp	6 Jul 2004 08:34:41 -0000	1.8
  +++ MathOpsClient.cpp	21 Oct 2004 05:05:48 -0000	1.9
  @@ -1,49 +1,86 @@
   #include "MathOps.h"
   #include <axis/server/AxisException.h>
   #include <ctype.h>
  +#include <iostream>
   
   void PrintUsage();
   bool IsNumber(const char* p);
   
  +static void
  +usage (char *programName, char *defaultURL)
  +{
  +    cout << "\nUsage:\n"
  +	<< programName << " [-? | div number1 number2 [service_url]] " << endl
  +	<< "    -?             Show this help.\n"
  +	<< "    service_url    URL of the service.\n"
  +	<< "    Default service URL is assumed to be " << defaultURL
  +	<<
  +	"\n    Could use http://localhost:8080/axis/services/echo to test with Axis Java."
  +	<< endl;
  +}
  +
   int main(int argc, char* argv[])
   {
   	char endpoint[256];
  -	const char* server="localhost";
  -	const char* port="80";
  +    char original[256];
   	const char* op = 0;
   	const char* p1 = 0;
   	const char* p2 = 0;
   	int i1=0, i2=0;
  -        int iResult;
  -        char* pcDetail;
  -        try
  +    int iResult;
  +    char* pcDetail;
  +
  +    // Set default service URL
  +    sprintf (endpoint, "http://localhost/axis/MathOps");
  +    sprintf(original, "http://localhost/axis/MathOps");
  +
  +    try
  +    {
  +    if( argc ==1 )
  +    {
  +        usage(argv[0], endpoint);
  +        return 2;
  +    }
  +    if (argc > 1)
  +    {
  +        if(!strncmp (argv[1], "-", 1))
  +	    {
  +            // Check for - only so that it works for 
  +            //-?, -h or --help; -anything 
  +
  +            usage(argv[0], endpoint);
  +            return 2;
  +	    }
  +        //less than minimum number of args OR greater than maximum number of args
  +       	else if (argc < 4 || argc > 5)
  +    	{
  +		    usage(argv[0], endpoint);
  +            return 2;
  +    	}
  +        else if (argc == 5)
           {
  -	if (argc < 6)
  -	{
  -		PrintUsage();
  -	}
  -	else
  -	{
  -		server = argv[1];
  -		port = argv[2];
  -	}
  -	printf("Sending Requests to Server http://%s:%s ........\n\n", server, port);
  -	sprintf(endpoint, "http://%s:%s/axis/MathOps", server, port);
  -	MathOps ws(endpoint);
  -
  -	op = argv[3];
  -	p1 = argv[4];
  -	p2 = argv[5];
  +            sprintf(endpoint, argv[4]);      
  +        }
  +    }
  +	cout << endl << " Using service at " << endpoint << endl << endl;
  +
  +    MathOps ws(endpoint);
  +
  +	op = argv[1];
  +	p1 = argv[2];
  +	p2 = argv[3];
   
   	if (!IsNumber(p1))
   	{
   		printf("Invalid value for first <parameter>\n\n");
  -		PrintUsage();
  +		usage(argv[0], original);
  +        return 2;
   	}
   	if (!IsNumber(p2))
   	{
   		printf("Invalid value for second <parameter>\n\n");
  -		PrintUsage();
  +		usage(argv[0], original);
  +        return 2;
   	}
   	
   	i1 = atoi(p1);
  @@ -57,7 +94,8 @@
   	else 
   	{
   		printf("Invalid operation %s\n\n", op);
  -		PrintUsage();
  +		usage(argv[0], original);
  +        return 2;
   	}
           }
           catch(AxisException& e)
  @@ -74,12 +112,6 @@
           }
   	
   	return 0;
  -}
  -
  -void PrintUsage()
  -{
  -	printf("Usage :\n MathOps <server> <port> <operation> <parameter> <parameter>\n\n");
  -	exit(1);
   }
   
   bool IsNumber(const char* p)