00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _WSDLINVOKERH
00023 #define _WSDLINVOKERH
00024
00025 #include "xmlpull/XmlSerializer.h"
00026 #include "wsdlparser/WsdlParser.h"
00027 #include "wsdlparser/Soap.h"
00028 #include "xmlpull/wsdlpull_export.h"
00029 #ifdef WITH_CURL
00030 #include <curl/curl.h>
00031 #endif
00032
00033 namespace WsdlPull{
00034
00035 struct Parameter
00036 {
00037 Parameter(Schema::Type ,std::string,int m,int x,const SchemaParser* s,
00038 const std::vector<std::string>& parents);
00039 Schema::Type type_;
00040 std::string tag_;
00041 unsigned int min_;
00042 unsigned int max_;
00043 int n_;
00044 std::vector<std::string> data_;
00045
00046 const SchemaParser* sParser_;
00047 std::vector<std::string> parents_;
00048
00049 };
00050
00051 class WSDLPULL_EXPORT WsdlInvoker
00052 {
00053 public:
00054
00055
00056
00057
00058
00059
00060
00061 WsdlInvoker(const std::string &url);
00062 WsdlInvoker(const std::string &url, const std::string &schemaPath);
00063 WsdlInvoker(std::istream &input, const std::string &schemaPath = "");
00064 WsdlInvoker();
00065 ~WsdlInvoker();
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 bool setWSDLUri(const std::string &url, const std::string & schemaPath="");
00076
00077
00078
00079
00080
00081 int getOperations(std::vector<std::string> & operations);
00082 std::string getOpDocumentation(const std::string & n);
00083 std::string getDocumentation();
00084
00085
00086
00087
00088
00089 bool setOperation(const std::string & operation,
00090 WsdlPull::MessageType mType = WsdlPull::Input);
00091
00092
00093
00094 std::string getServiceEndPoint(const std::string & opname) ;
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 bool setValue(const std::string & param,void* val);
00112 bool setValue(const std::string & param,void** values,unsigned int occur);
00113 bool setValue(const std::string & param,std::string val);
00114 bool setValue(const std::string & param,std::vector<std::string> values);
00115 bool setValue(const std::vector<std::string> & parents,void* val);
00116
00117
00118
00119
00120
00121 bool invoke(long timeout = 0);
00122
00123
00124
00125
00126
00127
00128
00129
00130 void* getValue(const std::string & param,Schema::Type & t);
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 int getNextInput(std::string & param ,Schema::Type & type,int & minimum,int & maximum);
00152 int getNextInput(std::string & param ,Schema::Type & type,int & minimum,int & maximum,
00153 std::vector<std::string>& parents);
00154
00155
00156
00157
00158
00159 int getNextHeaderInput(std::string & param ,Schema::Type & type,int & minimum,int & maximum);
00160 int getNextHeaderInput(std::string & param ,Schema::Type & type,int & minimum,int & maximum,
00161 std::vector<std::string>& parents);
00162
00163
00164
00165 int nInputHeaders()const;
00166
00167
00168
00169
00170
00171
00172
00173
00174 bool setInputValue(const int param,void* val);
00175 bool setInputValue(const int id,void** values,unsigned int occur);
00176
00177
00178
00179
00180
00181
00182
00183
00184 bool setInputValue(const int param,std::string val);
00185 bool setInputValue(const int param,std::vector<std::string> values);
00186
00187
00188
00189
00190
00191
00192 bool getNextOutput(std::string & name,TypeContainer * & tc);
00193
00194
00195
00196
00197
00198 TypeContainer* getOutput(const std::string & name);
00199
00200
00201
00202
00203
00204
00205 bool getNextHeaderOutput(std::string & name,TypeContainer*& tc);
00206
00207
00208
00209 void setLocation(const std::string & url);
00210
00211 void setCredentials(const std::string & user, const std::string & pass);
00212
00213 void setAuth(const std::string & user, const std::string & pass);
00214
00215 std::string getSoapMessage();
00216 std::string getXMLResponse();
00217 void setProxy(const std::string & host,int port=80);
00218
00219 void setVerbose(bool f);
00220
00221
00222
00223 void printTypeNames(bool f);
00224
00225 std::string errors();
00226
00227 bool status()const;
00228
00229
00230 std::string getFaultCode() const;
00231 std::string getFaultSubCode() const;
00232 std::string getFaultString() const;
00233 std::string getFaultActor() const;
00234
00235
00236 private:
00237
00238
00239 bool init(WsdlParser* parser);
00240
00241 void serialize();
00242 void serializeType(Schema::Type typeId,
00243 const std::string &tag,
00244 const SchemaParser * sParser,
00245 int minimum,
00246 int maximum,
00247 std::vector<std::string> parents,
00248 const std::string nsp="",
00249 bool isRoot = false);
00250
00251 void serializeParam(int n,const std::string & tag,
00252 const SchemaParser * sParser,
00253 const std::string nsp="",
00254 bool isRoot = false);
00255 void serializeContentModel(ContentModel *cm,
00256 const SchemaParser *sParser,
00257 std::vector<std::string> parents);
00258
00259
00260
00261
00262 void post(long timeout=0, std::string username="", std::string passwd="");
00263 void processResults();
00264 void processFault(XmlPullParser* xpp);
00265 void processHeader(XmlPullParser *xpp);
00266 void processBody(const Message* m,XmlPullParser* xpp);
00267 void parseWsdl(const std::string & url, const std::string & schemaPath = "");
00268 void serializeHeader();
00269 bool isSoapArray (const ComplexType * ct,const SchemaParser * sParser);
00270
00271 void reset();
00272 void getOperationDetails(const Operation* op);
00273 std::string getPrefix(const std::string& nsp);
00274
00275 WsdlParser * wParser_;
00276 WsdlParser * ourParser_;
00277 XmlSerializer * xmlStream_;
00278 Soap* soap_;
00279 bool soapheaders_;
00280 int hPartId_;
00281 std::string hnsp_;
00282 std::ostringstream * soapstr_;
00283 std::ostringstream logger_;
00284 bool status_;
00285 bool serializeMode_;
00286 bool verbose_;
00287 bool dontPost_;
00288 int oHeaders_;
00289 std::map<std::string,const Operation*> opMap_;
00290 const Operation* op_;
00291 Soap::Encoding use_;
00292 std::string encodingStyle_;
00293 Soap::Style style_;
00294 std::string nsp_;
00295 std::string location_;
00296 std::string username_,password_,host_;
00297 int port_;
00298 std::string action_;
00299 std::vector<Parameter> elems_;
00300 size_t n_;
00301 int iHeaders_;
00302 std::vector<std::pair<std::string,TypeContainer*> > outputs_;
00303 std::vector<const XSDType* > avoidrecurse_;
00304 WsdlPull::MessageType messageType_;
00305
00306 std::vector<std::string> prefixes_;
00307 bool bAuth;
00308 std::string sAuthUser;
00309 std::string sAuthPass;
00310
00311 std::string sFaultCode;
00312 std::string sFaultSubCode;
00313 std::string sFaultString;
00314 std::string sFaultActor;
00315 #ifdef WITH_CURL
00316 CURL * ctx;
00317 #endif
00318 };
00319
00320 inline
00321 Parameter::Parameter(Schema::Type t,std::string n,int m,int x,const SchemaParser* s,
00322 const std::vector<std::string>& parents)
00323 :type_(t),
00324 tag_(n),
00325 min_(m),
00326 max_(x),
00327 n_(0),
00328 sParser_(s),
00329 parents_(parents)
00330
00331 {
00332 }
00333
00334 inline
00335 std::string
00336 WsdlInvoker::errors()
00337 {
00338 return logger_.str();
00339 }
00340
00341 inline
00342 bool
00343 WsdlInvoker::setWSDLUri(const std::string &url,const std::string & schemaPath)
00344 {
00345 parseWsdl(url,schemaPath);
00346 return status_;
00347 }
00348
00349 inline
00350 bool
00351 WsdlInvoker::status()const
00352 {
00353 return status_;
00354 }
00355
00356 inline
00357 void
00358 WsdlInvoker::setLocation(const std::string & url)
00359 {
00360 location_ = url;
00361 }
00362
00363 inline
00364 void
00365 WsdlInvoker::setVerbose(bool f)
00366 {
00367 verbose_ = f;
00368 }
00369
00370 inline
00371 int
00372 WsdlInvoker::nInputHeaders()const
00373 {
00374 return iHeaders_;
00375 }
00376
00377 inline
00378 std::string
00379 WsdlInvoker::getFaultCode() const
00380 {
00381 return sFaultCode;
00382 }
00383
00384 inline
00385 std::string
00386 WsdlInvoker::getFaultSubCode() const
00387 {
00388 return sFaultSubCode;
00389 }
00390
00391 inline
00392 std::string
00393 WsdlInvoker::getFaultString() const
00394 {
00395 return sFaultString;
00396 }
00397
00398 inline
00399 std::string
00400 WsdlInvoker::getFaultActor() const
00401 {
00402 return sFaultActor;
00403 }
00404
00405
00406 }
00407 #endif