# 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: 24177 $
    00027  * $Author: rjongbloed $
    00028  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
    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
    00053
    00054 class PSOAPMessage : public PXML
    00055 {
    00056   PCLASSINFO(PSOAPMessage, PXML);
    00057 public:
    00058
    00060   PSOAPMessage( int options = PXMLParser::Indent + PXMLParser::NewLineAfterElement );
    00061
    00063   PSOAPMessage( const PString & method, const PString & nameSpace );
    00064
    00066   void SetMethod( const PString & name, const PString & nameSpace, const PString & methodPrefix = "m:" );
    00067
    00069   void GetMethod( PString & name, PString & nameSpace );
    00070
    00072   void AddParameter( PString name, PString type, PString value );
    00073
    00075   void AddParameter( PXMLElement* parameter, PBoolean dirty = true );
    00076
    00078   PBoolean GetParameter( const PString & name, PString & value );
    00079
    00081   PBoolean GetParameter( const PString & name, int & value );
    00082
    00084   PXMLElement* GetParameter( const PString & name );
    00085
    00087   PBoolean Load(const PString & str);
    00088
    00090   enum
    00091   {
    00093     NoFault,
    00095     VersionMismatch,
    00097     MustUnderstand,
    00099     Client,
    00101     Server
    00102   };
    00103
    00104   PINDEX  GetFaultCode() const                     { return faultCode; }
    00105   PString GetFaultText() const                     { return faultText; }
    00106   void SetFault( PINDEX code, const PString & text );
    00107
    00108 private:
    00109   PXMLElement* pSOAPBody;
    00110   PXMLElement* pSOAPMethod;
    00111   PString faultText;
    00112   PINDEX  faultCode;
    00113 };
    00114
    00115
    00120 class PSOAPServerRequestResponse : public PObject
    00121 {
    00122   PCLASSINFO( PSOAPServerRequestResponse, PObject );
    00123   public:
    00124     PSOAPServerRequestResponse( PSOAPMessage & req )
    00125       : request( req ) { }
    00126
    00127     PSOAPMessage & request;
    00128     PSOAPMessage response;
    00129 };
    00130
    00131
    00133 class PSOAPServerMethod : public PString
    00134 {
    00135   PCLASSINFO( PSOAPServerMethod, PString );
    00136   public:
    00137     PSOAPServerMethod( const PString & name )
    00138       : PString( name ) { }
    00139
    00140     PNotifier methodFunc;
    00141 };
    00142
    00143 PSORTED_LIST(PSOAPServerMethodList, PSOAPServerMethod);
    00144
    00145
    00147 class PSOAPServerResource : public PHTTPResource
    00148 {
    00149   PCLASSINFO( PSOAPServerResource, PHTTPResource );
    00150   public:
    00151     PSOAPServerResource();
    00152     PSOAPServerResource(
    00153       const PHTTPAuthority & auth
    00154     );
    00155     PSOAPServerResource(
    00156       const PURL & url
    00157     );
    00158     PSOAPServerResource(
    00159       const PURL & url,
    00160       const PHTTPAuthority & auth
    00161     );
    00162
    00163     // overrides from PHTTPResource
    00164     PBoolean LoadHeaders( PHTTPRequest & request );
    00165     PBoolean OnPOSTData( PHTTPRequest & request, const PStringToString & data );
    00166
    00167     // new functions
    00168     virtual PBoolean OnSOAPRequest( const PString & body, PString & reply );
    00169     virtual PBoolean SetMethod( const PString & methodName, const PNotifier & func );
    00170     PBoolean OnSOAPRequest( const PString & methodName, PSOAPMessage & request, PString & reply );
    00171
    00172     virtual PSOAPMessage FormatFault( PINDEX code, const PString & str );
    00173
    00175
    00178     void SetSOAPAction( PString saction ) { soapAction = saction; }
    00179
    00180   protected:
    00181     PMutex methodMutex;
    00182     PSOAPServerMethodList methodList;
    00183   private:
    00184     PString soapAction;
    00185 };
    00186
    00187
    00192 class PSOAPClient : public PObject
    00193 {
    00194   PCLASSINFO( PSOAPClient, PObject );
    00195   public:
    00196
    00197     PSOAPClient( const PURL & url );
    00198
    00199     void SetTimeout( const PTimeInterval & _timeout ) { timeout = _timeout; }
    00200
    00201     PBoolean MakeRequest( const PString & method, const PString & nameSpace );
    00202     PBoolean MakeRequest( const PString & method, const PString & nameSpace,  PSOAPMessage & response );
    00203     PBoolean MakeRequest( PSOAPMessage  & request, PSOAPMessage & response );
    00204
    00205     PString GetFaultText() const { return faultText; }
    00206     PINDEX  GetFaultCode() const { return faultCode; }
    00207
    00209     void setSOAPAction( PString saction ) { soapAction = saction; }
    00210   protected:
    00211     PBoolean PerformRequest( PSOAPMessage & request, PSOAPMessage & response );
    00212
    00213     PURL url;
    00214     PINDEX  faultCode;
    00215     PString faultText;
    00216     PTimeInterval timeout;
    00217   private:
    00218     PString soapAction;
    00219 };
    00220
    00221
    00222 #endif // P_SOAP
    00223
    00224
    00225 #endif // PTLIB_PSOAP_H
    00226
    00227
    00228 // End of file ////////////////////////////////////////////////////////////////