PTLib  Version 2.10.10
 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: 24177 $
27  * $Author: rjongbloed $
28  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
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 class PSOAPMessage : public PXML
55 {
56  PCLASSINFO(PSOAPMessage, PXML);
57 public:
58 
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 ////////////////////////////////////////////////////////////////
PURL url
Definition: psoap.h:213
PINDEX GetFaultCode() const
Definition: psoap.h:206
PString GetFaultText() const
Definition: psoap.h:205
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:55
void SetTimeout(const PTimeInterval &_timeout)
Definition: psoap.h:199
This resource will bind the methods to an http resource (a url)
Definition: psoap.h:147
PSOAPMessage response
Definition: psoap.h:128
Class specialisation for PNotifierTemplate<INT>
This abstract class describes the authorisation mechanism for a Universal Resource Locator...
Definition: http.h:1002
PSOAPServerRequestResponse(PSOAPMessage &req)
Definition: psoap.h:124
Error processing SOAP Header field "mustUnderstand".
Definition: psoap.h:97
SOAP client classes.
Definition: psoap.h:192
Invalid namespace for SOAP Envelope.
Definition: psoap.h:95
This is a dictionary collection class of PString objects, keyed by another string.
Definition: pstring.h:2784
PINDEX GetFaultCode() const
Definition: psoap.h:104
PBoolean LoadHeaders(PHTTPRequest &request)
Get the headers for block of data (eg HTML) that the resource contains.
PSOAPMessage(int options=PXMLParser::Indent+PXMLParser::NewLineAfterElement)
Construct a SOAP message.
virtual PBoolean SetMethod(const PString &methodName, const PNotifier &func)
Everything is alright.
Definition: psoap.h:93
PINDEX faultCode
Definition: psoap.h:214
This object describes a HyperText Transport Protocol resource.
Definition: http.h:1222
Definition: pxml.h:114
void SetSOAPAction(PString saction)
Use this method to have the server check for SOAPAction field in HTTP header.
Definition: psoap.h:178
BOOL PBoolean
Definition: object.h:102
SOAP Server classes.
Definition: psoap.h:120
virtual PBoolean OnSOAPRequest(const PString &body, PString &reply)
void setSOAPAction(PString saction)
Set a specific SOAPAction field in the HTTTP header, default = " ".
Definition: psoap.h:209
PSOAPServerMethod(const PString &name)
Definition: psoap.h:137
PBoolean PerformRequest(PSOAPMessage &request, PSOAPMessage &response)
PBoolean Load(const PString &str)
Parse a string for a valid SOAP message.
PNotifier methodFunc
Definition: psoap.h:140
The request was incorrectly formed or did not contain the appropriate information in order to succeed...
Definition: psoap.h:99
Definition: pxml.h:74
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.
Definition: pxml.h:353
PSORTED_LIST(PSOAPServerMethodList, PSOAPServerMethod)
PBoolean MakeRequest(const PString &method, const PString &nameSpace)
PSOAPMessage & request
Definition: psoap.h:127
PMutex methodMutex
Definition: psoap.h:181
The request could not be processed for reasons not directly attributable to the contents of the messa...
Definition: psoap.h:101
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:54
PBoolean GetParameter(const PString &name, PString &value)
Get parameter "name" with type "string".
PString faultText
Definition: psoap.h:215
Synonym for PTimedMutex.
PTimeInterval timeout
Definition: psoap.h:216
PString GetFaultText() const
Definition: psoap.h:105
PSOAPClient(const PURL &url)
PSOAPServerMethodList methodList
Definition: psoap.h:182
Definition: pxml.h:73
void SetFault(PINDEX code, const PString &text)
This object describes a HyperText Transport Protocol request.
Definition: http.h:968
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
This class describes a Universal Resource Locator.
Definition: url.h:54
Create an association between a method and its "notifier", the handler function.
Definition: psoap.h:133
PBoolean OnPOSTData(PHTTPRequest &request, const PStringToString &data)
Send the data associated with a POST command.
virtual PSOAPMessage FormatFault(PINDEX code, const PString &str)