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.5  2005/11/30 12:47:37  csoutheren
00028  * Removed tabs, reformatted some code, and changed tags for Doxygen
00029  *
00030  * Revision 1.4  2003/03/31 06:21:19  craigs
00031  * Split the expat wrapper from the XML file handling to allow reuse of the parser
00032  *
00033  * Revision 1.3  2003/02/09 23:31:39  robertj
00034  * Added referention PString's for efficiency.
00035  *
00036  * Revision 1.2  2003/02/09 23:22:37  robertj
00037  * Fixed spelling errors, and setting return values, thanks Andreas Sikkema
00038  *
00039  * Revision 1.1  2003/02/04 22:46:48  robertj
00040  * Added basic SOAP support, thanks Andreas Sikkema
00041  *
00042  */
00043 
00044 
00045 #ifndef _PSOAP_H
00046 #define _PSOAP_H
00047 
00048 #ifdef P_USE_PRAGMA
00049 #pragma interface
00050 #endif
00051 
00052 
00053 #if P_EXPAT
00054 
00055 #include <ptclib/pxml.h>
00056 #include <ptclib/http.h>
00057 
00058 
00059 #define DEFAULT_SOAP_URL "/soap"
00060 
00061 
00067 
00068 class PSOAPMessage : public PXML
00069 {
00070   PCLASSINFO(PSOAPMessage, PXML);
00071 public:
00072   
00074   PSOAPMessage( int options = PXMLParser::Indent + PXMLParser::NewLineAfterElement );
00075 
00077   PSOAPMessage( const PString & method, const PString & nameSpace );
00078 
00080   void SetMethod( const PString & name, const PString & nameSpace );
00081 
00083   void GetMethod( PString & name, PString & nameSpace );
00084   
00086   void AddParameter( PString name, PString type, PString value );
00087 
00089   void AddParameter( PXMLElement* parameter, BOOL dirty = TRUE );
00090 
00092   BOOL GetParameter( const PString & name, PString & value );
00093 
00095   BOOL GetParameter( const PString & name, int & value );
00096 
00098   PXMLElement* GetParameter( const PString & name );
00099 
00101   void PrintOn(ostream & strm) const;
00102 
00104   PString AsString( void );
00105   
00107   BOOL Load(const PString & str);
00108 
00110   enum 
00111   {
00113     NoFault,
00115     VersionMismatch,
00117     MustUnderstand,
00119     Client,
00121     Server
00122   };
00123 
00124   PINDEX  GetFaultCode() const                     { return faultCode; }
00125   PString GetFaultText() const                     { return faultText; }
00126   void SetFault( PINDEX code, const PString & text );
00127 
00128 private:
00129   PXMLElement* pSOAPBody;
00130   PXMLElement* pSOAPMethod;
00131   PString faultText;
00132   PINDEX  faultCode;
00133 };
00134 
00135 
00141 class PSOAPServerRequestResponse : public PObject 
00142 {
00143   PCLASSINFO( PSOAPServerRequestResponse, PObject );
00144   public:
00145     PSOAPServerRequestResponse( PSOAPMessage & _request )
00146       : request( _request ) { }
00147 
00148     PSOAPMessage & request;
00149     PSOAPMessage response;
00150 };
00151 
00152 
00154 class PSOAPServerMethod : public PString
00155 {
00156   PCLASSINFO( PSOAPServerMethod, PString );
00157   public:
00158     PSOAPServerMethod( const PString & name ) 
00159       : PString( name ) { }
00160 
00161     PNotifier methodFunc;
00162 };
00163 
00164 PSORTED_LIST(PSOAPServerMethodList, PSOAPServerMethod);
00165 
00166 
00168 class PSOAPServerResource : public PHTTPResource
00169 {
00170   PCLASSINFO( PSOAPServerResource, PHTTPResource );
00171   public:
00172     PSOAPServerResource();
00173     PSOAPServerResource(
00174       const PHTTPAuthority & auth    
00175     );
00176     PSOAPServerResource(
00177       const PURL & url               
00178     );
00179     PSOAPServerResource(
00180       const PURL & url,              
00181       const PHTTPAuthority & auth    
00182     );
00183 
00184     // overrides from PHTTPResource
00185     BOOL LoadHeaders( PHTTPRequest & request );
00186     BOOL OnPOSTData( PHTTPRequest & request, const PStringToString & data );
00187 
00188     // new functions
00189     virtual BOOL OnSOAPRequest( const PString & body, PString & reply );
00190     virtual BOOL SetMethod( const PString & methodName, const PNotifier & func );
00191     BOOL OnSOAPRequest( const PString & methodName, PSOAPMessage & request, PString & reply );
00192 
00193     virtual PSOAPMessage FormatFault( PINDEX code, const PString & str );
00194 
00196 
00199     void SetSOAPAction( PString saction ) { soapAction = saction; }
00200 
00201   protected:
00202     PMutex methodMutex;
00203     PSOAPServerMethodList methodList;
00204   private:
00205     PString soapAction;
00206 };
00207 
00208 
00214 class PSOAPClient : public PObject
00215 {
00216   PCLASSINFO( PSOAPClient, PObject );
00217   public:
00218 
00219     PSOAPClient( const PURL & url );
00220 
00221     void SetTimeout( const PTimeInterval & _timeout ) { timeout = _timeout; }
00222 
00223     BOOL MakeRequest( const PString & method, const PString & nameSpace );
00224     BOOL MakeRequest( const PString & method, const PString & nameSpace,  PSOAPMessage & response );
00225     BOOL MakeRequest( PSOAPMessage  & request, PSOAPMessage & response );
00226 
00227     PString GetFaultText() const { return faultText; }
00228     PINDEX  GetFaultCode() const { return faultCode; }
00229 
00231     void setSOAPAction( PString saction ) { soapAction = saction; }
00232   protected:
00233     BOOL PerformRequest( PSOAPMessage & request, PSOAPMessage & response );
00234 
00235     PURL url;
00236     PINDEX  faultCode;
00237     PString faultText;
00238     PTimeInterval timeout;
00239   private:
00240     PString soapAction;
00241 };
00242 
00243 
00244 #endif // P_EXPAT
00245 
00246 
00247 #endif // _PSOAP_H
00248 
00249 
00250 // End of file ////////////////////////////////////////////////////////////////

Generated on Fri Mar 7 06:25:02 2008 for PTLib by  doxygen 1.5.1