wsdlpull svntrunk
Loading...
Searching...
No Matches
WsdlInvoker.h
Go to the documentation of this file.
1/*
2 * wsdlpull - A C++ parser for WSDL (Web services description language)
3 * Copyright (C) 2005-2007 Vivek Krishna
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20//An api to examine and invoke the web service in a protocol independent fashion
21
22#ifndef _WSDLINVOKERH
23#define _WSDLINVOKERH
24
27#include "wsdlparser/Soap.h"
29
30#include "xmlpull/XmlDoc.h"
31
32namespace WsdlPull{
33
34 struct Parameter
35 {
36 Parameter(Schema::Type ,std::string,int m,int x,const SchemaParser* s,
37 const std::vector<std::string>& parents);
39 std::string tag_;
40 unsigned int min_;
41 unsigned int max_;
42 int n_;
43 std::vector<std::string> data_;
44 //bool str_;
46 std::vector<std::string> parents_;
47
48 };
49
51{
52 public:
61 WsdlInvoker(const std::string &url, const std::string &schemaPath="");
62 WsdlInvoker(std::istream &input, const std::string &schemaPath = "");
66
74 bool setWSDLUri(const std::string &url, const std::string & schemaPath="");
80 int getOperations(std::vector<std::string> & operations);
81 std::string getOpDocumentation(const std::string & n);
82 std::string getDocumentation();
88 bool setOperation(const std::string & operation,
93 std::string getServiceEndPoint(const std::string & opname) ;
95
96
99
110 bool setValue(const std::string & param,void* val);
111 bool setValue(const std::string & param,void** values,unsigned int occur);
112 bool setValue(const std::string & param,std::string val);
113 bool setValue(const std::string & param,std::vector<std::string> values);//multiple occurrences
114 bool setValue(const std::vector<std::string> & parents,void* val);
120 bool invoke(long timeout = 0,bool processResponse = true);
129 void* getValue(const std::string & param,Schema::Type & t);
130
131
152 template <typename T>
153 T getValue(const std::string & xpath, size_t p_index = 1);
154
155 /* identical to previous method but returns multiple matches if found in the document*/
156 template <typename T>
157 std::vector<T> getValues(const std::string & xpath);
159
162
177 int getNextInput(std::string & param ,Schema::Type & type,int & minimum,int & maximum);
178 int getNextInput(std::string & param ,Schema::Type & type,int & minimum,int & maximum,
179 std::vector<std::string>& parents);
185 int getNextHeaderInput(std::string & param ,Schema::Type & type,int & minimum,int & maximum);
186 int getNextHeaderInput(std::string & param ,Schema::Type & type,int & minimum,int & maximum,
187 std::vector<std::string>& parents);
191 int nInputHeaders()const;
192
200 bool setInputValue(const int param,void* val);
201 bool setInputValue(const int id,void** values,unsigned int occur);
202
210 bool setInputValue(const int param,std::string val);
211 bool setInputValue(const int param,std::vector<std::string> values);//multiple occurrences
212
218 bool getNextOutput(std::string & name,TypeContainer * & tc);
219
224 TypeContainer* getOutput(const std::string & name);
225
231 bool getNextHeaderOutput(std::string & name,TypeContainer*& tc);
232
234 // change location of the service
235 void setLocation(const std::string & url);
236 // set credentials for the service
237 void setCredentials(const std::string & user, const std::string & pass);
238 // set http authentication for the service
239 void setAuth(const std::string & user, const std::string & pass);
240 //ouput the soap message without invoking the service
241 std::string getSoapMessage();
242 std::string getXMLResponse();
243 void setProxy(const std::string & host,int port=80);
244 //enable logging
245 void setVerbose(bool f);
246 // prints the output along with typenames like
247 // name:value.
248 //if false only value is printed
249 void printTypeNames(bool f);
250 //get the error message
251 std::string errors();
252 //if this returns false something went wrong
253 bool status()const;
254
255 //get SOAP fault related things
256 std::string getFaultCode() const;
257 std::string getFaultSubCode() const;
258 std::string getFaultString() const;
259 std::string getFaultActor() const;
260
261 // Control XML Tree Generation and Xpath search fine tuning
262 void setProcessEnvAndBody( bool p_processEnvAndBody);
263 bool getProcessEnvAndBody( void) const;
264
265 void setLazyRelativeMatch( bool p_lazyRelativeMatch);
266 bool getLazyRelativeMatch( void) const;
267
268 void setBuildXmlTree( bool p_buildXmlTree);
269 bool getBuildXmlTree( void) const;
270 void buildXmlTree( XmlPullParser &p_xmlPullParser, XmlNode_t &p_xmlNode,
271 bool p_notScannedEventAvail = false);
272
273 private:
274 //private stuff
275
276 bool init(WsdlParser* parser);
277 //creaate xml request
278 void serialize();
279 void serializeType(Schema::Type typeId,
280 const std::string &tag,
281 const SchemaParser * sParser,
282 int minimum,
283 int maximum,
284 std::vector<std::string> parents,
285 const std::string nsp="",
286 bool isRoot = false);
287
288 void serializeParam(int n,const std::string & tag,
289 const SchemaParser * sParser,
290 const std::string nsp="",
291 bool isRoot = false);
292 void serializeContentModel(ContentModel *cm,
293 const SchemaParser *sParser,
294 std::vector<std::string> parents);
299 void post(long timeout=0, std::string username="", std::string passwd="");
300 void processResults();
301 void processFault(XmlPullParser* xpp);
302 void processHeader(XmlPullParser *xpp);
303 void processBody(const Message* m,XmlPullParser* xpp);
304 void parseWsdl(const std::string & url, const std::string & schemaPath = "");
305 void serializeHeader();
306 bool isSoapArray (const ComplexType * ct,const SchemaParser * sParser);
307 //reset state information
308 void reset();
309 void getOperationDetails(const Operation* op);
310 std::string getPrefix(const std::string& nsp);
311 std::string getAsStringFromXPath(const std::string & xpath, size_t p_index, std::vector<std::string>* arr = 0);
312 bool isSubTreeNil();
313 WsdlParser * wParser_;
314 std::string strResults_;
315 WsdlParser * ourParser_;
316 XmlSerializer * xmlStream_;
317 Soap* soap_;
318 bool soapheaders_;
319 int hPartId_;
320 std::string hnsp_;
321 std::ostringstream * soapstr_;
322 std::ostringstream logger_;
323 bool status_;
324 bool serializeMode_;
325 bool verbose_;
326 bool dontPost_;
327 int oHeaders_;
328 std::map<std::string,const Operation*> opMap_;
329 const Operation* op_;
330 Soap::Encoding use_;//literal or encoded
331 std::string encodingStyle_; // this is usually the soap encoding style
332 Soap::Style style_;//rpc or doc
333 std::string nsp_; // namespace for the operation
334 std::string location_;
335 std::string username_,password_,host_;
336 int port_;
337 std::string action_;//SOAPAction header
338 std::vector<Parameter> elems_;//the simple types
339 size_t n_;//a counter to iterate through the element params
340 int iHeaders_; //number of soap header inputs
341 std::vector<std::pair<std::string,TypeContainer*> > outputs_;
342 std::vector<const XSDType* > avoidrecurse_;
343 WsdlPull::MessageType messageType_;
344
345 std::vector<std::string> prefixes_;
346 bool bAuth;
347 std::string sAuthUser;
348 std::string sAuthPass;
349
350 std::string sFaultCode;
351 std::string sFaultSubCode;
352 std::string sFaultString;
353 std::string sFaultActor;
354 void* ctx;//for connection purposes
355
356 bool m_buildXmlTree;
357 bool m_xmlTreeProduced;
358 XmlDoc_t m_xmlDoc;
359};
360
361inline
362Parameter::Parameter(Schema::Type t,std::string n,int m,int x,const SchemaParser* s,
363 const std::vector<std::string>& parents)
364 :type_(t),
365 tag_(n),
366 min_(m),
367 max_(x),
368 n_(0),
369 sParser_(s),
370 parents_(parents)
371
372{
373}
374
375inline
376std::string
378{
379 return logger_.str();
380}
381
382inline
383bool
384WsdlInvoker::setWSDLUri(const std::string &url,const std::string & schemaPath)
385{
386 parseWsdl(url,schemaPath);
387 return status_;
388}
389
390inline
391bool
393{
394 return status_;
395}
396
397inline
398void
399WsdlInvoker::setLocation(const std::string & url)
400{
401 location_ = url;
402}
403
404inline
405void
407{
408 verbose_ = f;
409}
410
411inline
412int
414{
415 return iHeaders_;
416}
417
418inline
419std::string
421{
422 return sFaultCode;
423}
424
425inline
426std::string
428{
429 return sFaultSubCode;
430}
431
432inline
433std::string
435{
436 return sFaultString;
437}
438
439inline
440std::string
442{
443 return sFaultActor;
444}
445
446
447template<typename T>
448inline T
449WsdlInvoker::getValue(const std::string & xpath, size_t p_index)
450{
451
452 T val;
453 std::string v = getAsStringFromXPath(xpath, p_index);
454 std::istringstream iss(v);
455 iss>>val;
456 return val;
457}
458
459template<>
460inline std::string
461WsdlInvoker::getValue<std::string>(const std::string & xpath, size_t p_index)
462{
463
464 return getAsStringFromXPath(xpath, p_index);
465
466}
467
468template <typename T>
469inline std::vector<T>
470WsdlInvoker::getValues(const std::string & xpath)
471{
472 std::vector<std::string> arr ;
473 std::vector<T> arrT;
474 getAsStringFromXPath(xpath, 0, &arr);
475 T val;
476 for (size_t s = 0 ;s<arr.size();s++){
477
478
479 std::istringstream iss(arr[s]);
480 iss>>val;
481 arrT.push_back(val);
482 }
483 return arrT;
484}
485
486//specialization for string
487template<>
488inline
489std::vector<std::string>
490WsdlInvoker::getValues<std::string>(const std::string & xpath)
491{
492 std::vector<std::string> arr ;
493 getAsStringFromXPath(xpath, 0, &arr);
494 return arr;
495}
496
497
498}
499#endif
bool setValue(const std::vector< std::string > &parents, void *val)
sets the param value for an operation by name of the parameter
void * getValue(const std::string &param, Schema::Type &t)
std::string getFaultActor() const
void setLocation(const std::string &url)
std::string getFaultCode() const
std::string errors()
std::string getFaultSubCode() const
bool setWSDLUri(const std::string &url, const std::string &schemaPath="")
std::vector< T > getValues(const std::string &xpath)
sets the param value for an operation by name of the parameter
std::string getFaultString() const
void setVerbose(bool f)
int nInputHeaders() const
Schema::Type type_
Definition WsdlInvoker.h:38
Parameter(Schema::Type, std::string, int m, int x, const SchemaParser *s, const std::vector< std::string > &parents)
unsigned int min_
Definition WsdlInvoker.h:40
std::vector< std::string > data_
Definition WsdlInvoker.h:43
unsigned int max_
Definition WsdlInvoker.h:41
std::vector< std::string > parents_
Definition WsdlInvoker.h:46
const SchemaParser * sParser_
Definition WsdlInvoker.h:45
#define WSDLPULL_EXPORT