main.cpp

Go to the documentation of this file.
00001 /*
00002         Main.cpp For Simple SOAP test Server
00003 
00004         This is the Server driver program for the Simple SOAP Test Server.  This
00005         server allows you to test compatablility of a Simple SOAP Client with the
00006         Simple SOAP Server.  The Server assumes 127.0.0.1 with port 8080 as the server
00007         port.  It responds to requests on the port just like a Simple SOAP Server.
00008 
00009         It prints all of it's requests.
00010 
00011         This Program requires the Simple SOAP server Library from Scott Seeley
00012         and the Simple Soap TCP Server from Jasen Plietz
00013 
00014         History:
00015 
00016                 18-Aug-2003             GJPC    Intial Type in
00017                 09-Sep-2003             GJPC    added set/get logmask
00018 
00019         $Log: main.cpp,v $
00020         Revision 1.1  2005/03/22 22:30:32  gjpc
00021         This is the intial check in of the Simple SOAP library.
00022         
00023         The code compiles and executes under MSVC .NET and GNU 3.3
00024         
00025         It has been run under Debian, SUSE, CYGWIN and WinXP
00026         
00027         Revision 1.3  2004/04/23 19:53:32  gjpc
00028         Re-formatted output to look like client output
00029         
00030         Revision 1.2  2004/04/23 16:58:36  gjpc
00031         expanded the Simple SOAP package to allow RPC's within RPC's
00032         extended the test client to allow for programable validation
00033         
00034 
00035 */
00036 #include <iostream>
00037 //#pragma warning( disable: 4786 )
00038 #include "networkApp.h"
00039 #if !defined(SOAPONHTTP_H)
00040     #include "SOAPonHTTP.h"    
00041 #endif // !defined(SOAPONHTTP_H)
00042 #if !defined(SOAPELEMENT_H)
00043     #include "SOAPElement.h"
00044 #endif // !defined(SOAPELEMENT_H)
00045 #if !defined(SOAPDISPATCHER_H)
00046     #include "SOAPDispatcher.h"
00047 #endif // !defined(SOAPDISPATCHER_H)
00048 #if !defined(SOAPFAULT_H)
00049     #include "SOAPFault.h"
00050 #endif // !defined(SOAPFAULT_H)
00051 #ifndef TSOAPOBJECTCREATOR_H
00052     #include "TSOAPObjectCreator.h"
00053 #endif // TSOAPOBJECTCREATOR_H
00054 #ifndef __TestSOAP__
00055         #include "TestSOAP.h"
00056 #endif // __TestSOAP__
00057 
00058 #ifdef _MSC_VER
00059 #include <process.h>
00060 #include <windows.h>
00061 #endif
00062 
00063 #include <iostream>
00064 #include <fstream>
00065 
00066 #define VersionString   "Simple SOAP Test Server V 2.1 build 0"
00067 
00068 
00069 void registerObjects()
00070 {
00071     SOAPDispatcher::Instance().registerObject( 
00072         new TSOAPObjectCreator<TestSOAP>( std::string("SimpleSOAP") ) );
00073 }
00074 
00075 void processSocket( TcpSocket& socket )
00076 {
00077     long nBuffSize = socket.getReceivingBufferSize();
00078     char* buff = new char[ nBuffSize + 1 ];
00079     std::string szReply;
00080     std::string szSOAPMessage("");
00081 
00082     bool bSendingFault = false;
00083     try
00084     {
00085                 // handle message longer than the Receive buf size - GJPC
00086                 // not elegant TODO: time out and eject 
00087         int bytes;
00088                 do
00089                 {
00090                         bytes = socket.read( buff, nBuffSize ); 
00091                         buff[bytes] = 0;
00092                         szSOAPMessage += buff;
00093                 }
00094                 while ( strstr( buff, "</SOAP-ENV:Envelope>" ) == NULL );
00095 
00096     }
00097     catch( NetworkException& e )
00098     {
00099                 std::cerr << "Network exception: " << e.what();
00100     }
00101     catch( ... )
00102     {
00103                 std::cerr << "Unknown Exception while getting SOAP msg";
00104         socket.close();
00105         return;
00106     }
00107 
00108         // print out the SOAP request
00109         std::cout << "\r\n\n================= " << szSOAPMessage.length()  << " byte SOAP Message ===================\r\n\n";
00110         std::cout << szSOAPMessage << std::endl;
00111     // Process the SOAP message-- should be the contents of the
00112     // message from "<SOAP:" to the end of the string.
00113     SOAPonHTTP soapOnHTTP;
00114     std::string szObjectName;
00115     std::string szMethodName;
00116     SOAPElement theCall;
00117 
00118     if ( soapOnHTTP.getMethodDetails( 
00119         szSOAPMessage, szObjectName, szMethodName, theCall ) )
00120     {
00121         szReply = SOAPDispatcher::Instance().processMessage( 
00122             szObjectName, szMethodName, theCall, bSendingFault );
00123     }
00124     else
00125     {
00126         // Create a SOAP fault.  Client error-- the message could not be understood.
00127                 std::cerr << "<<<<<<<<<<<<<<<<<< Couldn't parse this message >>>>>>>>>>>>>" ;
00128         bSendingFault = true;
00129         szReply = szObjectName;
00130     }
00131 
00132     szReply = soapOnHTTP.getSendableResponse( szReply, bSendingFault );
00133     socket.write( szReply.c_str(), szReply.length() + 1 );
00134     socket.close();
00135 
00136         // now print the reply on the console
00137         std::cout << std::endl 
00138                 << "------------------ SOAP Response -------------------------" 
00139                 << std::endl << std::endl ;
00140     std::cout << szReply << std::endl;
00141 
00142     delete[] buff;
00143 }
00144 
00145 //int __cdecl networkAppMain(int argc, char* argv[])
00146 int  networkAppMain(int argc, char* argv[])
00147 {
00148         std::cout << VersionString << std::endl ;
00149     // Create connection server with well-known port on local host.
00150         int port = 8080;
00151         if ( argc > 1 )
00152                 port = atoi( argv[1] );
00153 
00154         SocketAddress addr( port );
00155     TcpConnectionServer server( addr );
00156        
00157     // Perform registration.
00158     registerObjects();
00159 
00160     TcpSocket socket;
00161     while (true) 
00162     {
00163         server.accept( socket ); // Accept incoming connection.
00164         processSocket( socket );
00165     }
00166     
00167     return 0;
00168 }
00169 
00170 int main( int argc, char* argv[] )
00171 {
00172         return NetworkStart( argc, argv, networkAppMain );
00173 }

Generated on Tue Mar 28 09:10:14 2006 for Simple SOAP by  doxygen 1.4.6