00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <iostream>
00037
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
00086
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
00109 std::cout << "\r\n\n================= " << szSOAPMessage.length() << " byte SOAP Message ===================\r\n\n";
00110 std::cout << szSOAPMessage << std::endl;
00111
00112
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
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
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
00146 int networkAppMain(int argc, char* argv[])
00147 {
00148 std::cout << VersionString << std::endl ;
00149
00150 int port = 8080;
00151 if ( argc > 1 )
00152 port = atoi( argv[1] );
00153
00154 SocketAddress addr( port );
00155 TcpConnectionServer server( addr );
00156
00157
00158 registerObjects();
00159
00160 TcpSocket socket;
00161 while (true)
00162 {
00163 server.accept( socket );
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 }