PTLib  Version 2.18.8
 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 
27 
28 #ifndef PTLIB_PSOAP_H
29 #define PTLIB_PSOAP_H
30 
31 #ifdef P_USE_PRAGMA
32 #pragma interface
33 #endif
34 
35 
36 #if P_SOAP
37 
38 #include <ptclib/pxml.h>
39 #include <ptclib/http.h>
40 
41 
42 #define DEFAULT_SOAP_URL "/soap"
43 
44 
49 class PSOAPMessage : public PXML
51 {
52  PCLASSINFO(PSOAPMessage, PXML);
53 public:
54 
56  PSOAPMessage(Options options = Indent + NewLineAfterElement);
57 
59  PSOAPMessage( const PString & method, const PString & nameSpace );
60 
62  void SetMethod( const PString & name, const PString & nameSpace, const PString & methodPrefix = "m:" );
63 
65  void GetMethod( PString & name, PString & nameSpace );
66 
68  void AddParameter( PString name, PString type, PString value );
69 
71  void AddParameter( PXMLElement* parameter, PBoolean dirty = true );
72 
74  PBoolean GetParameter( const PString & name, PString & value );
75 
77  PBoolean GetParameter( const PString & name, int & value );
78 
80  PXMLElement* GetParameter( const PString & name );
81 
83  PBoolean Load(const PString & str);
84 
86  enum
87  {
98  };
99 
100  PINDEX GetFaultCode() const { return faultCode; }
101  PString GetFaultText() const { return faultText; }
102  void SetFault( PINDEX code, const PString & text );
103 
104 private:
105  PXMLElement* pSOAPBody;
106  PXMLElement* pSOAPMethod;
107  PString faultText;
108  PINDEX faultCode;
109 };
110 
111 
117 {
118  PCLASSINFO( PSOAPServerRequestResponse, PObject );
119  public:
121  : request( req ) { }
122 
125 };
126 
127 
130 {
131  PCLASSINFO( PSOAPServerMethod, PString );
132  public:
133  PSOAPServerMethod( const PString & name )
134  : PString( name ) { }
135 
137 };
138 
139 PSORTED_LIST(PSOAPServerMethodList, PSOAPServerMethod);
140 
141 
144 {
145  PCLASSINFO( PSOAPServerResource, PHTTPResource );
146  public:
149  const PHTTPAuthority & auth
150  );
152  const PURL & url
153  );
155  const PURL & url,
156  const PHTTPAuthority & auth
157  );
158 
159  // overrides from PHTTPResource
160  PBoolean LoadHeaders( PHTTPRequest & request );
161  PBoolean OnPOSTData( PHTTPRequest & request, const PStringToString & data );
162 
163  // new functions
164  virtual PBoolean OnSOAPRequest( const PString & body, PString & reply );
165  virtual PBoolean SetMethod( const PString & methodName, const PNotifier & func );
166  PBoolean OnSOAPRequest( const PString & methodName, PSOAPMessage & request, PString & reply );
167 
168  virtual PSOAPMessage FormatFault( PINDEX code, const PString & str );
169 
171 
174  void SetSOAPAction( PString saction ) { soapAction = saction; }
175 
176  protected:
177  PDECLARE_MUTEX(methodMutex);
178  PSOAPServerMethodList methodList;
179  private:
180  PString soapAction;
181 };
182 
183 
188 class PSOAPClient : public PObject
189 {
190  PCLASSINFO( PSOAPClient, PObject );
191  public:
192 
193  PSOAPClient( const PURL & url );
194 
195  void SetTimeout( const PTimeInterval & _timeout ) { timeout = _timeout; }
196 
197  PBoolean MakeRequest( const PString & method, const PString & nameSpace );
198  PBoolean MakeRequest( const PString & method, const PString & nameSpace, PSOAPMessage & response );
199  PBoolean MakeRequest( PSOAPMessage & request, PSOAPMessage & response );
200 
201  PString GetFaultText() const { return faultText; }
202  PINDEX GetFaultCode() const { return faultCode; }
203 
205  void setSOAPAction( PString saction ) { soapAction = saction; }
206  protected:
207  PBoolean PerformRequest( PSOAPMessage & request, PSOAPMessage & response );
208 
210  PINDEX faultCode;
213  private:
214  PString soapAction;
215 };
216 
217 
218 #endif // P_SOAP
219 
220 
221 #endif // PTLIB_PSOAP_H
222 
223 
224 // End of file ////////////////////////////////////////////////////////////////
Error processing SOAP Header field &quot;mustUnderstand&quot;.
Definition: psoap.h:93
PURL url
Definition: psoap.h:209
PINDEX GetFaultCode() const
Definition: psoap.h:202
PString GetFaultText() const
Definition: psoap.h:201
PSOAPMessage(Options options=Indent+NewLineAfterElement)
Construct a SOAP message.
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:51
Everything is alright.
Definition: psoap.h:89
void SetTimeout(const PTimeInterval &_timeout)
Definition: psoap.h:195
This resource will bind the methods to an http resource (a url)
Definition: psoap.h:143
PSOAPMessage response
Definition: psoap.h:124
Class specialisation for PNotifierTemplate&lt;P_INT_PTR&gt;
This abstract class describes the authorisation mechanism for a Universal Resource Locator...
Definition: http.h:1452
PSOAPServerRequestResponse(PSOAPMessage &req)
Definition: psoap.h:120
SOAP client classes.
Definition: psoap.h:188
This is a dictionary collection class of PString objects, keyed by another string.
Definition: pstring.h:3151
PINDEX GetFaultCode() const
Definition: psoap.h:100
PBoolean LoadHeaders(PHTTPRequest &request)
Get the headers for block of data (eg HTML) that the resource contains.
virtual PBoolean SetMethod(const PString &methodName, const PNotifier &func)
PINDEX faultCode
Definition: psoap.h:210
This object describes a HyperText Transport Protocol resource.
Definition: http.h:1680
Invalid namespace for SOAP Envelope.
Definition: psoap.h:91
Definition: pxml.h:101
void SetSOAPAction(PString saction)
Use this method to have the server check for SOAPAction field in HTTP header.
Definition: psoap.h:174
SOAP Server classes.
Definition: psoap.h:116
virtual PBoolean OnSOAPRequest(const PString &body, PString &reply)
void setSOAPAction(PString saction)
Set a specific SOAPAction field in the HTTTP header, default = &quot; &quot;.
Definition: psoap.h:205
PSOAPServerMethod(const PString &name)
Definition: psoap.h:133
PBoolean PerformRequest(PSOAPMessage &request, PSOAPMessage &response)
PBoolean Load(const PString &str)
Parse a string for a valid SOAP message.
PNotifier methodFunc
Definition: psoap.h:136
bool PBoolean
Definition: object.h:174
The character string class.
Definition: pstring.h:108
void AddParameter(PString name, PString type, PString value)
Add a simple parameter called name, with type type and value value.
The request could not be processed for reasons not directly attributable to the contents of the messa...
Definition: psoap.h:97
The request was incorrectly formed or did not contain the appropriate information in order to succeed...
Definition: psoap.h:95
Definition: pxml.h:398
PBoolean MakeRequest(const PString &method, const PString &nameSpace)
PSOAPMessage & request
Definition: psoap.h:123
void GetMethod(PString &name, PString &nameSpace)
Get the method name and namespace.
void SetMethod(const PString &name, const PString &nameSpace, const PString &methodPrefix="m:")
Set the method name and namespace.
SOAP Message classes.
Definition: psoap.h:50
PBoolean GetParameter(const PString &name, PString &value)
Get parameter &quot;name&quot; with type &quot;string&quot;.
PString faultText
Definition: psoap.h:211
PTimeInterval timeout
Definition: psoap.h:212
PDECLARE_MUTEX(methodMutex)
PString GetFaultText() const
Definition: psoap.h:101
PSOAPClient(const PURL &url)
PSOAPServerMethodList methodList
Definition: psoap.h:178
void SetFault(PINDEX code, const PString &text)
#define PSORTED_LIST(cls, T)
Declare a sorted list class.
Definition: lists.h:1116
This object describes a HyperText Transport Protocol request.
Definition: http.h:1417
Ultimate parent class for all objects in the class library.
Definition: object.h:2204
This class describes a Universal Resource Locator.
Definition: url.h:56
Create an association between a method and its &quot;notifier&quot;, the handler function.
Definition: psoap.h:129
PBoolean OnPOSTData(PHTTPRequest &request, const PStringToString &data)
Send the data associated with a POST command.
virtual PSOAPMessage FormatFault(PINDEX code, const PString &str)