Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

WsdlInvoker.h

Go to the documentation of this file.
00001 /* 
00002  * wsdlpull - A C++ parser  for WSDL  (Web services description language)
00003  * Copyright (C) 2005-2007 Vivek Krishna
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public
00016  * License along with this library; if not, write to the Free
00017  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018  */
00019 
00020 //An api to examine and invoke the web service in a protocol independent fashion
00021 
00022 #ifndef _WSDLINVOKERH
00023 #define _WSDLINVOKERH
00024 
00025 #include "xmlpull/XmlSerializer.h"
00026 #include "wsdlparser/WsdlParser.h"
00027 #include "wsdlparser/Soap.h"
00028 
00029 #ifndef WSDLPULL_EXPORT
00030 #if (defined _MSC_VER) && (defined _MT)
00031 #define WSDLPULL_EXPORT __declspec (dllimport)
00032 #else
00033 #define WSDLPULL_EXPORT 
00034 #endif
00035 #endif
00036 
00037 namespace WsdlPull{
00038 
00039  struct Parameter
00040  {
00041    Parameter(Schema::Type ,std::string,int m,int x,const SchemaParser* s);
00042    Schema::Type type_;
00043    std::string tag_;
00044    unsigned int min_;
00045    unsigned int max_;
00046    int n_;
00047    std::vector<std::string> data_;
00048    bool str_;
00049    const SchemaParser* sParser_;
00050  };
00051 
00052 class WSDLPULL_EXPORT WsdlInvoker
00053 {
00054  public:
00062   WsdlInvoker(const std::string &url);
00063   WsdlInvoker();
00064   ~WsdlInvoker();
00066 
00069   bool setWSDLUri(const std::string &url);
00076   // allready parsed wsdl
00077   bool init(WsdlParser* parser);
00078 
00079   int getOperations(std::vector<std::string> & operations);
00080   std::string getOpDocumentaion(const std::string & n);
00086   bool setOperation(const std::string & operation);
00088 
00091   
00102   bool setValue(const std::string & param,void* val);
00103   bool setValue(const std::string & param,void** values,unsigned int occur);
00104   bool setValue(const std::string & param,std::string val);
00105   bool setValue(const std::string & param,std::vector<std::string> values);//multiple occurrences
00111   bool invoke(long timeout = 0);
00120   void* getValue(const std::string & param,Schema::Type & t); 
00121   
00123   
00126   
00140   int getNextInput(std::string & param ,Schema::Type & type,int & minimum,int & maximum);
00146   int getNextHeaderInput(std::string & param ,Schema::Type & type,int & minimum,int & maximum);
00150   int nInputHeaders()const;
00151   
00159   bool setInputValue(const int param,void* val);
00160   bool setInputValue(const int id,void** values,unsigned int occur);
00161 
00169   bool setInputValue(const int param,std::string val);
00170   bool setInputValue(const int param,std::vector<std::string> values);//multiple occurrences
00171 
00177   bool getNextOutput(std::string  & name,TypeContainer * & tc);
00178   
00183   TypeContainer* getOutput(const std::string  & name);
00184   
00190    bool getNextHeaderOutput(std::string & name,TypeContainer*& tc);
00191 
00193   
00194   //enable logging
00195   void setVerbose(bool f);
00196   // prints the output along with typenames like
00197   // name:value.
00198   //if false only value is printed
00199   void printTypeNames(bool f);
00200   //get the error message
00201   std::string errors();
00202   //if this returns false something went wrong
00203   bool status()const;
00204 
00205 
00206  private:
00207   //private stuff 
00208 
00209   //creaate xml request
00210   void serialize();
00211   void serializeType(Schema::Type typeId,
00212                      const std::string &tag,
00213                      const SchemaParser * sParser,
00214                      int minimum,
00215                      int maximum);
00216   void serializeParam(int n,const std::string & tag,
00217                       const SchemaParser * sParser);
00218   void serializeContentModel(ContentModel *cm,
00219                              const SchemaParser *sParser);
00224   void post(long timeout=0);
00225   void processResults();
00226   void processFault(XmlPullParser* xpp);
00227   void processHeader(XmlPullParser *xpp);
00228   void parseWsdl(const std::string & url);
00229   void serializeHeader();
00230   bool isSoapArray (const ComplexType * ct,const SchemaParser * sParser);
00231   //reset state information
00232   void reset();
00233 
00234   WsdlParser * wParser_;
00235   WsdlParser * ourParser_;
00236   XmlSerializer * xmlStream_;
00237   Soap* soap_;
00238   const Message* hMessage_;//message corresponding to soap header
00239   int hPartId_;
00240   std::ostringstream * soapstr_;
00241   std::ostringstream logger_;
00242   bool status_;
00243   bool serializeMode_;
00244   bool verbose_;
00245   int oHeaders_;
00246   std::map<std::string,const Operation*> opMap_;
00247   const Operation* op_;
00248   Soap::Encoding use_;//literal or encoded
00249   Soap::Style style_;//rpc or doc
00250   std::string nsp_; // namespace for the operation
00251   std::string location_;
00252   std::string action_;//SOAPAction header
00253   std::vector<Parameter> elems_;//the simple types
00254   std::vector<Parameter> attribs_;//input attributes
00255   size_t n_;//a counter to iterate through the params
00256   int iHeaders_; //number of soap header inputs
00257 
00258   std::vector<std::pair<std::string,TypeContainer*> > outputs_;
00259 };
00260 
00261 inline
00262 Parameter::Parameter(Schema::Type t,std::string n,int m,int x,const SchemaParser* s)
00263   :type_(t),
00264      tag_(n),
00265      min_(m),
00266      max_(x),
00267      n_(0),
00268      sParser_(s)
00269      
00270 {
00271 }
00272 
00273 inline
00274 std::string 
00275 WsdlInvoker::errors()
00276 {
00277   return logger_.str();
00278 }
00279 
00280 inline
00281 bool
00282 WsdlInvoker::setWSDLUri(const std::string &url)
00283 {
00284   parseWsdl(url);
00285   return status_;
00286 }
00287 
00288 inline
00289 bool
00290 WsdlInvoker::status()const
00291 {
00292   return status_;
00293 }
00294 
00295 inline
00296 void
00297 WsdlInvoker::setVerbose(bool f)
00298 {
00299   verbose_ = f;
00300 }
00301 
00302 inline
00303 int
00304 WsdlInvoker::nInputHeaders()const
00305 {
00306   return iHeaders_;
00307 }
00308 }
00309 #endif

Generated on Mon Feb 6 23:02:42 2006 for wsdlpull by  doxygen 1.3.9.1