Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

psoap.h

Go to the documentation of this file.
00001 /* 00002 * psoap.h 00003 * 00004 * SOAP client / server classes. 00005 * 00006 * Portable Windows Library 00007 * 00008 * Copyright (c) 2003 Andreas Sikkema 00009 * 00010 * The contents of this file are subject to the Mozilla Public License 00011 * Version 1.0 (the "License"); you may not use this file except in 00012 * compliance with the License. You may obtain a copy of the License at 00013 * http://www.mozilla.org/MPL/ 00014 * 00015 * Software distributed under the License is distributed on an "AS IS" 00016 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00017 * the License for the specific language governing rights and limitations 00018 * under the License. 00019 * 00020 * The Original Code is Portable Windows Library. 00021 * 00022 * The Initial Developer of the Original Code is Andreas Sikkema 00023 * 00024 * Contributor(s): ______________________________________. 00025 * 00026 * $Log: psoap.h,v $ 00027 * Revision 1.4 2003/03/31 06:21:19 craigs 00028 * Split the expat wrapper from the XML file handling to allow reuse of the parser 00029 * 00030 * Revision 1.3 2003/02/09 23:31:39 robertj 00031 * Added referention PString's for efficiency. 00032 * 00033 * Revision 1.2 2003/02/09 23:22:37 robertj 00034 * Fixed spelling errors, and setting return values, thanks Andreas Sikkema 00035 * 00036 * Revision 1.1 2003/02/04 22:46:48 robertj 00037 * Added basic SOAP support, thanks Andreas Sikkema 00038 * 00039 */ 00040 00041 00042 #ifndef _PSOAP_H 00043 #define _PSOAP_H 00044 00045 #ifdef P_USE_PRAGMA 00046 #pragma interface 00047 #endif 00048 00049 00050 #if P_EXPAT 00051 00052 #include <ptclib/pxml.h> 00053 #include <ptclib/http.h> 00054 00055 00056 #define DEFAULT_SOAP_URL "/soap" 00057 00058 00064 00065 class PSOAPMessage : public PXML 00066 { 00067 PCLASSINFO(PSOAPMessage, PXML); 00068 public: 00069 00071 PSOAPMessage( int options = PXMLParser::Indent + PXMLParser::NewLineAfterElement ); 00072 00074 PSOAPMessage( const PString & method, const PString & nameSpace ); 00075 00077 void SetMethod( const PString & name, const PString & nameSpace ); 00078 00080 void GetMethod( PString & name, PString & nameSpace ); 00081 00083 void AddParameter( PString name, PString type, PString value ); 00084 00086 void AddParameter( PXMLElement* parameter, BOOL dirty = TRUE ); 00087 00089 BOOL GetParameter( const PString & name, PString & value ); 00090 00092 BOOL GetParameter( const PString & name, int & value ); 00093 00095 PXMLElement* GetParameter( const PString & name ); 00096 00098 void PrintOn(ostream & strm) const; 00099 00101 PString AsString( void ); 00102 00104 BOOL Load(const PString & str); 00105 00107 enum 00108 { 00110 NoFault, 00112 VersionMismatch, 00114 MustUnderstand, 00116 Client, 00118 Server 00119 }; 00120 00121 PINDEX GetFaultCode() const { return faultCode; } 00122 PString GetFaultText() const { return faultText; } 00123 void SetFault( PINDEX code, const PString & text ); 00124 00125 private: 00126 PXMLElement* pSOAPBody; 00127 PXMLElement* pSOAPMethod; 00128 PString faultText; 00129 PINDEX faultCode; 00130 }; 00131 00132 00138 class PSOAPServerRequestResponse : public PObject 00139 { 00140 PCLASSINFO( PSOAPServerRequestResponse, PObject ); 00141 public: 00142 PSOAPServerRequestResponse( PSOAPMessage & _request ) 00143 : request( _request ) { } 00144 00145 PSOAPMessage & request; 00146 PSOAPMessage response; 00147 }; 00148 00149 00151 class PSOAPServerMethod : public PString 00152 { 00153 PCLASSINFO( PSOAPServerMethod, PString ); 00154 public: 00155 PSOAPServerMethod( const PString & name ) 00156 : PString( name ) { } 00157 00158 PNotifier methodFunc; 00159 }; 00160 00161 PSORTED_LIST(PSOAPServerMethodList, PSOAPServerMethod); 00162 00163 00165 class PSOAPServerResource : public PHTTPResource 00166 { 00167 PCLASSINFO( PSOAPServerResource, PHTTPResource ); 00168 public: 00169 PSOAPServerResource(); 00170 PSOAPServerResource( 00171 const PHTTPAuthority & auth // Authorisation for the resource. 00172 ); 00173 PSOAPServerResource( 00174 const PURL & url // Name of the resource in URL space. 00175 ); 00176 PSOAPServerResource( 00177 const PURL & url, // Name of the resource in URL space. 00178 const PHTTPAuthority & auth // Authorisation for the resource. 00179 ); 00180 00181 // overrides from PHTTPResource 00182 BOOL LoadHeaders( PHTTPRequest & request ); 00183 BOOL OnPOSTData( PHTTPRequest & request, const PStringToString & data ); 00184 00185 // new functions 00186 virtual BOOL OnSOAPRequest( const PString & body, PString & reply ); 00187 virtual BOOL SetMethod( const PString & methodName, const PNotifier & func ); 00188 BOOL OnSOAPRequest( const PString & methodName, PSOAPMessage & request, PString & reply ); 00189 00190 virtual PSOAPMessage FormatFault( PINDEX code, const PString & str ); 00191 00193 00196 void SetSOAPAction( PString saction ) { soapAction = saction; } 00197 00198 protected: 00199 PMutex methodMutex; 00200 PSOAPServerMethodList methodList; 00201 private: 00202 PString soapAction; 00203 }; 00204 00205 00211 class PSOAPClient : public PObject 00212 { 00213 PCLASSINFO( PSOAPClient, PObject ); 00214 public: 00215 00216 PSOAPClient( const PURL & url ); 00217 00218 void SetTimeout( const PTimeInterval & _timeout ) { timeout = _timeout; } 00219 00220 BOOL MakeRequest( const PString & method, const PString & nameSpace ); 00221 BOOL MakeRequest( const PString & method, const PString & nameSpace, PSOAPMessage & response ); 00222 BOOL MakeRequest( PSOAPMessage & request, PSOAPMessage & response ); 00223 00224 PString GetFaultText() const { return faultText; } 00225 PINDEX GetFaultCode() const { return faultCode; } 00226 00228 void setSOAPAction( PString saction ) { soapAction = saction; } 00229 protected: 00230 BOOL PerformRequest( PSOAPMessage & request, PSOAPMessage & response ); 00231 00232 PURL url; 00233 PINDEX faultCode; 00234 PString faultText; 00235 PTimeInterval timeout; 00236 private: 00237 PString soapAction; 00238 }; 00239 00240 00241 #endif // P_EXPAT 00242 00243 00244 #endif // _PSOAP_H 00245 00246 00247 // End of file ////////////////////////////////////////////////////////////////

Generated on Sat Jul 24 15:35:56 2004 for PWLib by doxygen 1.3.7