PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
psoap.h
Go to the documentation of this file.
1 /*
2  * psoap.h
3  *
4  * SOAP client / server classes.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 2003 Andreas Sikkema
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Andreas Sikkema
23  *
24  * Contributor(s): ______________________________________.
25  *
26  * $Revision: 27039 $
27  * $Author: rjongbloed $
28  * $Date: 2012-02-22 18:19:46 +1100 (Wed, 22 Feb 2012) $
29  */
30 
31 
32 #ifndef PTLIB_PSOAP_H
33 #define PTLIB_PSOAP_H
34 
35 #ifdef P_USE_PRAGMA
36 #pragma interface
37 #endif
38 
39 
40 #if P_SOAP
41 
42 #include <ptclib/pxml.h>
43 #include <ptclib/http.h>
44 
45 
46 #define DEFAULT_SOAP_URL "/soap"
47 
48 
53 
54 class PSOAPMessage : public PXML
55 {
56  PCLASSINFO(PSOAPMessage, PXML);
57 public:
58 
60  PSOAPMessage(Options options = Indent + NewLineAfterElement);
61 
63  PSOAPMessage( const PString & method, const PString & nameSpace );
64 
66  void SetMethod( const PString & name, const PString & nameSpace, const PString & methodPrefix = "m:" );
67 
69  void GetMethod( PString & name, PString & nameSpace );
70 
72  void AddParameter( PString name, PString type, PString value );
73 
75  void AddParameter( PXMLElement* parameter, PBoolean dirty = true );
76 
78  PBoolean GetParameter( const PString & name, PString & value );
79 
81  PBoolean GetParameter( const PString & name, int & value );
82 
84  PXMLElement* GetParameter( const PString & name );
85 
87  PBoolean Load(const PString & str);
88 
90  enum
91  {
102  };
103 
104  PINDEX GetFaultCode() const { return faultCode; }
105  PString GetFaultText() const { return faultText; }
106  void SetFault( PINDEX code, const PString & text );
107 
108 private:
109  PXMLElement* pSOAPBody;
110  PXMLElement* pSOAPMethod;
111  PString faultText;
112  PINDEX faultCode;
113 };
114 
115 
121 {
122  PCLASSINFO( PSOAPServerRequestResponse, PObject );
123  public:
125  : request( req ) { }
126 
129 };
130 
131 
134 {
135  PCLASSINFO( PSOAPServerMethod, PString );
136  public:
137  PSOAPServerMethod( const PString & name )
138  : PString( name ) { }
139 
141 };
142 
143 PSORTED_LIST(PSOAPServerMethodList, PSOAPServerMethod);
144 
145 
148 {
149  PCLASSINFO( PSOAPServerResource, PHTTPResource );
150  public:
153  const PHTTPAuthority & auth
154  );
156  const PURL & url
157  );
159  const PURL & url,
160  const PHTTPAuthority & auth
161  );
162 
163  // overrides from PHTTPResource
164  PBoolean LoadHeaders( PHTTPRequest & request );
165  PBoolean OnPOSTData( PHTTPRequest & request, const PStringToString & data );
166 
167  // new functions
168  virtual PBoolean OnSOAPRequest( const PString & body, PString & reply );
169  virtual PBoolean SetMethod( const PString & methodName, const PNotifier & func );
170  PBoolean OnSOAPRequest( const PString & methodName, PSOAPMessage & request, PString & reply );
171 
172  virtual PSOAPMessage FormatFault( PINDEX code, const PString & str );
173 
175 
178  void SetSOAPAction( PString saction ) { soapAction = saction; }
179 
180  protected:
182  PSOAPServerMethodList methodList;
183  private:
184  PString soapAction;
185 };
186 
187 
192 class PSOAPClient : public PObject
193 {
194  PCLASSINFO( PSOAPClient, PObject );
195  public:
196 
197  PSOAPClient( const PURL & url );
198 
199  void SetTimeout( const PTimeInterval & _timeout ) { timeout = _timeout; }
200 
201  PBoolean MakeRequest( const PString & method, const PString & nameSpace );
202  PBoolean MakeRequest( const PString & method, const PString & nameSpace, PSOAPMessage & response );
203  PBoolean MakeRequest( PSOAPMessage & request, PSOAPMessage & response );
204 
205  PString GetFaultText() const { return faultText; }
206  PINDEX GetFaultCode() const { return faultCode; }
207 
209  void setSOAPAction( PString saction ) { soapAction = saction; }
210  protected:
211  PBoolean PerformRequest( PSOAPMessage & request, PSOAPMessage & response );
212 
214  PINDEX faultCode;
217  private:
218  PString soapAction;
219 };
220 
221 
222 #endif // P_SOAP
223 
224 
225 #endif // PTLIB_PSOAP_H
226 
227 
228 // End of file ////////////////////////////////////////////////////////////////