00001 00024 00025 /* 00026 #if !defined(SOAPENCODER_H) 00027 #include "SOAPEncoder.h" 00028 #endif // SOAPENCODER_H 00029 */ 00030 00031 #if !defined(SOAPENCODER_H) 00032 #define SOAPENCODER_H 00033 00034 #ifndef _STRING_ 00035 #include <string> 00036 #endif // _STRING_ 00037 00038 #ifndef _INC_TIME 00039 #include <time.h> 00040 #endif // _INC_TIME 00041 00042 #ifndef _VECTOR_ 00043 #include <vector> 00044 #endif // _VECTOR_ 00045 00046 // Forward declaration. 00047 class SOAPMethod; 00048 class SOAPFault; 00049 00050 // Here's something that templates and C++ still can't handle. Using this 00051 // in conjunction with the encodeArgument() methods below, we avoid 00052 // type WRT the argument names. Spell it wrong and you get a compile 00053 // time error. Better at compile-time then run-time :). 00054 00055 #define encodeArg(a) encodeArgument( "" #a "" , a ) 00056 #define __int64 long long 00057 00058 class SOAPEncoder 00059 { 00060 public: 00061 00062 typedef std::vector<long> LongArray; 00063 typedef std::vector<std::string> StringArray; 00064 // Constructor/ Destructor 00065 SOAPEncoder(); 00066 virtual ~SOAPEncoder(); 00067 00068 // Encoding functions 00069 00070 // encodeMethodCall 00071 // Description: 00072 // Given a method, turns it into a SOAP message. 00073 // Arugments: 00074 // aMethod: The method to encode. 00075 // Return Value: 00076 // aMethod as a SOAP compliant string. 00077 virtual std::string encodeMethodCall( SOAPMethod& aMethod ); 00078 00079 // encodeMethodResponse 00080 // Description: 00081 // Pretty much the same thing as encodeMethodCall, 00082 // except this one sets the aMethod name to the following: 00083 // [aMethod.methodName()]Response. You will see this called 00084 // in response to a call to SOAPMethod.execute(). 00085 // Arugments: 00086 // aMethod: The method to encode. 00087 // Return Value: 00088 // aMethod as a SOAP compliant string. 00089 virtual std::string encodeMethodResponse( SOAPMethod& aMethod ); 00090 00091 // encodeArgument 00092 // Description: 00093 // This set of overloads encodes the argument using 00094 // the xsd:[type] data as <szArgName>value</szArgName>. 00095 // To avoid spelling errors, I recommend using the 00096 // encodeArg macro, which can produce the argument name 00097 // and value. 00098 // Arugments: 00099 // szArgName: Name of the arguement. 00100 // value: Value to encode. 00101 // Return Value: 00102 // Returns a string representing the value when encoded. 00103 virtual std::string encodeArgument( const std::string& szArg ); 00104 virtual std::string encodeArgument( const std::string& szArgName, 00105 const std::string& value ); 00106 virtual std::string encodeArgument( const std::string& szArgName, 00107 const int& value ); 00108 virtual std::string encodeArgument( const std::string& szArgName, 00109 const __int64& value ); 00110 virtual std::string encodeArgument( const std::string& szArgName, 00111 const short& value ); 00112 virtual std::string encodeArgument( const std::string& szArgName, 00113 const char& value ); 00114 virtual std::string encodeArgument( const std::string& szArgName, 00115 const unsigned int& value ); 00116 virtual std::string encodeArgument( const std::string& szArgName, 00117 const unsigned __int64& value ); 00118 virtual std::string encodeArgument( const std::string& szArgName, 00119 const unsigned short& value ); 00120 virtual std::string encodeArgument( const std::string& szArgName, 00121 const unsigned char& value ); 00122 virtual std::string encodeArgument( const std::string& szArgName, 00123 const float& value ); 00124 virtual std::string encodeArgument( const std::string& szArgName, 00125 const double& value ); 00126 virtual std::string encodeArgument( const std::string& szArgName, 00127 const bool& value ); 00128 virtual std::string encodeArgument( const std::string& szArgName, 00129 LongArray& value ); 00130 virtual std::string encodeArgument( const std::string& szArgName, 00131 StringArray& value ); 00132 00133 // encodeBase64 00134 // Description: 00135 // This one is a bit special. It takes a pointer and the length 00136 // of the data to encode from that pointer in bytes, then base64 00137 // encodes the data. 00138 // Arugments: 00139 // szArgName: Name of the argument. 00140 // value: Pointer to the start of the bytestream. 00141 // ulSizeofValue: Length of the stream, in bytes. 00142 // Return Value: 00143 // Returns a string representing the encoded value. 00144 virtual std::string encodeBase64 ( const std::string& szArgName, 00145 void* value, unsigned long ulSizeofValue ); 00146 00147 // clientFaultClass 00148 // Description: 00149 // For this encoder, returns a string that represents the 00150 // Client fault class. 00151 // Arugments: 00152 // N/A 00153 // Return Value: 00154 // See description. 00155 virtual std::string clientFaultClass(); 00156 00157 // serverFaultClass 00158 // Description: 00159 // For this encoder, returns a string that represents the 00160 // Client fault class. 00161 // Arugments: 00162 // N/A 00163 // Return Value: 00164 // See description. 00165 virtual std::string serverFaultClass(); 00166 00167 // versionMismatchFaultClass 00168 // Description: 00169 // For this encoder, returns a string that represents the 00170 // Client fault class. 00171 // Arugments: 00172 // N/A 00173 // Return Value: 00174 // See description. 00175 virtual std::string versionMismatchFaultClass(); 00176 00177 // mustUnderstandFaultClass 00178 // Description: 00179 // For this encoder, returns a string that represents the 00180 // Client fault class. 00181 // Arugments: 00182 // N/A 00183 // Return Value: 00184 // See description. 00185 virtual std::string mustUnderstandFaultClass(); 00186 00187 // addBeginTag 00188 // Description: 00189 // For this encoder, adds a begin tag to the stream. You 00190 // must not provide anything other than the name. 00191 // Ex. give the method "startTag", not "<startTag>" 00192 // Arugments: 00193 // szValue: Name of the tag. 00194 // Return Value: 00195 // The string as encoded to this point. 00196 virtual std::string addBeginTag( const std::string& szValue ); 00197 00198 // addEndTag 00199 // Description: 00200 // For this encoder, adds an end tag to the stream. You 00201 // must not provide anything other than the name. 00202 // Ex. give the method "endTag", not "</endTag>" 00203 // Arugments: 00204 // szValue: Name of the tag. 00205 // Return Value: 00206 // The string as encoded to this point. 00207 virtual std::string addEndTag( const std::string& szValue ); 00208 00209 // encodeFault 00210 // Description: 00211 // For this encoder, encodes the SOAPFault. 00212 // Must be used apart from other SOAPEncoder methods. 00213 // Arugments: 00214 // soapFault: Name of the tag. 00215 // Return Value: 00216 // Encodes the complete fault into a complete SOAP Envelope. 00217 virtual std::string encodeFault( SOAPFault& soapFault ); 00218 00219 // encodeFaultContent 00220 // write the contents of the fault into an ostream 00221 // we need this to allow embedding of fault return in a 00222 // detail description of a container RPC fault 00223 // Arguments: 00224 // soapFault - the RPC's fault object 00225 // szSteam - the Container RPC's detail fault stream 00226 virtual void encodeFaultContent( SOAPFault& soapFault, std::ostringstream &szStream ); 00227 00228 // encodeMethodResonseContents 00229 // write the contents of a Method response return to a string 00230 // this allows the returns from embeded RPC's to be returned 00231 // into the Container RPC's 00232 // Argument 00233 // aMethod - the Soap Method that will encode it's success response 00234 virtual std::string encodeMethodResonseContents( SOAPMethod& aMethod ); 00235 00236 protected: 00237 00238 // encodeMethod 00239 // Description: 00240 // Called by the encodeMethodResponse 00241 // and encodeMethodCall members to finish 00242 // encoding the method. As you may guess, the 00243 // two methods share a lot, and this item holds 00244 // that common code. 00245 // Arugments: 00246 // aMethod: The method being encoded. 00247 // Return Value: 00248 // Returns the value of the encoded method as 00249 // a valid SOAP string. 00250 virtual std::string encodeMethod( SOAPMethod& aMethod ); 00251 00252 // envelopeOpen 00253 // Description: 00254 // For this encoder, returns a string that represents the 00255 // opening of a Envelope element. 00256 // Arugments: 00257 // N/A 00258 // Return Value: 00259 // See description. 00260 virtual std::string envelopeOpen(); 00261 00262 // envelopeClose 00263 // Description: 00264 // For this encoder, returns a string that represents the 00265 // closing of a Envelope element. 00266 // Arugments: 00267 // N/A 00268 // Return Value: 00269 // See description. 00270 virtual std::string envelopeClose(); 00271 00272 // headerOpen 00273 // Description: 00274 // For this encoder, returns a string that represents the 00275 // opening of a Header element. 00276 // Arugments: 00277 // N/A 00278 // Return Value: 00279 // See description. 00280 virtual std::string headerOpen(); 00281 00282 // headerContents 00283 // Description: 00284 // At this point, this is a place holder. I haven't 00285 // implemented anything that allows the use of header 00286 // elements yet. When I need it, I'll get this one done. 00287 // Arugments: 00288 // N/A 00289 // Return Value: 00290 // Returns the contents of the header field. 00291 virtual std::string headerContents(); 00292 00293 // headerClose 00294 // Description: 00295 // For this encoder, returns a string that represents the 00296 // closing of a Header element. 00297 // Arugments: 00298 // N/A 00299 // Return Value: 00300 // See description. 00301 virtual std::string headerClose(); 00302 00303 // bodyOpen 00304 // Description: 00305 // For this encoder, returns a string that represents the 00306 // opening of a Body element. 00307 // Arugments: 00308 // N/A 00309 // Return Value: 00310 // See description. 00311 virtual std::string bodyOpen(); 00312 00313 // bodyClose 00314 // Description: 00315 // For this encoder, returns a string that represents the 00316 // opening of a Body element. 00317 // Arugments: 00318 // N/A 00319 // Return Value: 00320 // See description. 00321 virtual std::string bodyClose(); 00322 00323 // faultOpen 00324 // Description: 00325 // For this encoder, returns a string that represents the 00326 // opening of a Fault element. 00327 // Arugments: 00328 // N/A 00329 // Return Value: 00330 // See description. 00331 virtual std::string faultOpen(); 00332 00333 // faultClose 00334 // Description: 00335 // For this encoder, returns a string that represents the 00336 // closing of a Fault element. 00337 // Arugments: 00338 // N/A 00339 // Return Value: 00340 // See description. 00341 virtual std::string faultClose(); 00342 00343 // faultcodeOpen 00344 // Description: 00345 // For this encoder, returns a string that represents the 00346 // opening of a Fault:faultcode element. 00347 // Arugments: 00348 // N/A 00349 // Return Value: 00350 // See description. 00351 virtual std::string faultcodeOpen(); 00352 00353 // faultcodeClose 00354 // Description: 00355 // For this encoder, returns a string that represents the 00356 // closing of a Fault:faultcode element. 00357 // Arugments: 00358 // N/A 00359 // Return Value: 00360 // See description. 00361 virtual std::string faultcodeClose(); 00362 00363 // faultstringOpen 00364 // Description: 00365 // For this encoder, returns a string that represents the 00366 // opening of a Fault:faultstring element. 00367 // Arugments: 00368 // N/A 00369 // Return Value: 00370 // See description. 00371 virtual std::string faultstringOpen(); 00372 00373 // faultstringClose 00374 // Description: 00375 // For this encoder, returns a string that represents the 00376 // closing of a Fault:faultstring element. 00377 // Arugments: 00378 // N/A 00379 // Return Value: 00380 // See description. 00381 virtual std::string faultstringClose(); 00382 00383 // faultactorOpen 00384 // Description: 00385 // For this encoder, returns a string that represents the 00386 // opening of a Fault:faultactor element. 00387 // Arugments: 00388 // N/A 00389 // Return Value: 00390 // See description. 00391 virtual std::string faultactorOpen(); 00392 00393 // faultactorClose 00394 // Description: 00395 // For this encoder, returns a string that represents the 00396 // closing of a Fault:faultactor element. 00397 // Arugments: 00398 // N/A 00399 // Return Value: 00400 // See description. 00401 virtual std::string faultactorClose(); 00402 00403 // faultdetailOpen 00404 // Description: 00405 // For this encoder, returns a string that represents the 00406 // opening of a Fault:detail element. 00407 // Arugments: 00408 // N/A 00409 // Return Value: 00410 // See description. 00411 virtual std::string faultdetailOpen(); 00412 00413 // faultdetailClose 00414 // Description: 00415 // For this encoder, returns a string that represents the 00416 // closing of a Fault:detail element. 00417 // Arugments: 00418 // N/A 00419 // Return Value: 00420 // See description. 00421 virtual std::string faultdetailClose(); 00422 00423 // isEncodingResponse 00424 // Description: 00425 // Used to indicate if the encoder is currently 00426 // closing a SOAP response. 00427 // Arugments: 00428 // N/A 00429 // Return Value: 00430 // true: It is encoding. 00431 // false: Is not encoding. 00432 bool isEncodingResponse(); 00433 00434 private: 00435 00436 // m_bIsResponse 00437 // Description: Remembers if this item is encoding 00438 // a SOAP response. 00439 bool m_bIsResponse; 00440 00441 // m_encodedValue 00442 // Description: Keeps the value of the encoded string 00443 // as this object moves itself throughout the encoding process. 00444 std::string m_encodedValue; 00445 }; 00446 00447 #endif // !defined(SOAPENCODER_H)