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  * $Revision: 21788 $
00027  * $Author: rjongbloed $
00028  * $Date: 2008-12-11 23:42:13 -0600 (Thu, 11 Dec 2008) $
00029  */
00030 
00031 
00032 #ifndef PTLIB_PSOAP_H
00033 #define PTLIB_PSOAP_H
00034 
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038 
00039 
00040 #if P_SOAP
00041 
00042 #include <ptclib/pxml.h>
00043 #include <ptclib/http.h>
00044 
00045 
00046 #define DEFAULT_SOAP_URL "/soap"
00047 
00048 
00054 
00055 class PSOAPMessage : public PXML
00056 {
00057   PCLASSINFO(PSOAPMessage, PXML);
00058 public:
00059   
00061   PSOAPMessage( int options = PXMLParser::Indent + PXMLParser::NewLineAfterElement );
00062 
00064   PSOAPMessage( const PString & method, const PString & nameSpace );
00065 
00067   void SetMethod( const PString & name, const PString & nameSpace );
00068 
00070   void GetMethod( PString & name, PString & nameSpace );
00071   
00073   void AddParameter( PString name, PString type, PString value );
00074 
00076   void AddParameter( PXMLElement* parameter, PBoolean dirty = PTrue );
00077 
00079   PBoolean GetParameter( const PString & name, PString & value );
00080 
00082   PBoolean GetParameter( const PString & name, int & value );
00083 
00085   PXMLElement* GetParameter( const PString & name );
00086 
00088   void PrintOn(ostream & strm) const;
00089 
00091   PString AsString( void );
00092   
00094   PBoolean Load(const PString & str);
00095 
00097   enum 
00098   {
00100     NoFault,
00102     VersionMismatch,
00104     MustUnderstand,
00106     Client,
00108     Server
00109   };
00110 
00111   PINDEX  GetFaultCode() const                     { return faultCode; }
00112   PString GetFaultText() const                     { return faultText; }
00113   void SetFault( PINDEX code, const PString & text );
00114 
00115 private:
00116   PXMLElement* pSOAPBody;
00117   PXMLElement* pSOAPMethod;
00118   PString faultText;
00119   PINDEX  faultCode;
00120 };
00121 
00122 
00128 class PSOAPServerRequestResponse : public PObject 
00129 {
00130   PCLASSINFO( PSOAPServerRequestResponse, PObject );
00131   public:
00132     PSOAPServerRequestResponse( PSOAPMessage & req )
00133       : request( req ) { }
00134 
00135     PSOAPMessage & request;
00136     PSOAPMessage response;
00137 };
00138 
00139 
00141 class PSOAPServerMethod : public PString
00142 {
00143   PCLASSINFO( PSOAPServerMethod, PString );
00144   public:
00145     PSOAPServerMethod( const PString & name ) 
00146       : PString( name ) { }
00147 
00148     PNotifier methodFunc;
00149 };
00150 
00151 PSORTED_LIST(PSOAPServerMethodList, PSOAPServerMethod);
00152 
00153 
00155 class PSOAPServerResource : public PHTTPResource
00156 {
00157   PCLASSINFO( PSOAPServerResource, PHTTPResource );
00158   public:
00159     PSOAPServerResource();
00160     PSOAPServerResource(
00161       const PHTTPAuthority & auth    
00162     );
00163     PSOAPServerResource(
00164       const PURL & url               
00165     );
00166     PSOAPServerResource(
00167       const PURL & url,              
00168       const PHTTPAuthority & auth    
00169     );
00170 
00171     // overrides from PHTTPResource
00172     PBoolean LoadHeaders( PHTTPRequest & request );
00173     PBoolean OnPOSTData( PHTTPRequest & request, const PStringToString & data );
00174 
00175     // new functions
00176     virtual PBoolean OnSOAPRequest( const PString & body, PString & reply );
00177     virtual PBoolean SetMethod( const PString & methodName, const PNotifier & func );
00178     PBoolean OnSOAPRequest( const PString & methodName, PSOAPMessage & request, PString & reply );
00179 
00180     virtual PSOAPMessage FormatFault( PINDEX code, const PString & str );
00181 
00183 
00186     void SetSOAPAction( PString saction ) { soapAction = saction; }
00187 
00188   protected:
00189     PMutex methodMutex;
00190     PSOAPServerMethodList methodList;
00191   private:
00192     PString soapAction;
00193 };
00194 
00195 
00201 class PSOAPClient : public PObject
00202 {
00203   PCLASSINFO( PSOAPClient, PObject );
00204   public:
00205 
00206     PSOAPClient( const PURL & url );
00207 
00208     void SetTimeout( const PTimeInterval & _timeout ) { timeout = _timeout; }
00209 
00210     PBoolean MakeRequest( const PString & method, const PString & nameSpace );
00211     PBoolean MakeRequest( const PString & method, const PString & nameSpace,  PSOAPMessage & response );
00212     PBoolean MakeRequest( PSOAPMessage  & request, PSOAPMessage & response );
00213 
00214     PString GetFaultText() const { return faultText; }
00215     PINDEX  GetFaultCode() const { return faultCode; }
00216 
00218     void setSOAPAction( PString saction ) { soapAction = saction; }
00219   protected:
00220     PBoolean PerformRequest( PSOAPMessage & request, PSOAPMessage & response );
00221 
00222     PURL url;
00223     PINDEX  faultCode;
00224     PString faultText;
00225     PTimeInterval timeout;
00226   private:
00227     PString soapAction;
00228 };
00229 
00230 
00231 #endif // P_SOAP
00232 
00233 
00234 #endif // PTLIB_PSOAP_H
00235 
00236 
00237 // End of file ////////////////////////////////////////////////////////////////

Generated on Thu May 27 01:36:48 2010 for PTLib by  doxygen 1.4.7