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  struct Parameter
00030  {
00031    Parameter(Schema::Type ,std::string,int m,int x,const SchemaParser* s);
00032    Schema::Type type_;
00033    std::string tag_;
00034    unsigned int min_;
00035    unsigned int max_;
00036    int n_;
00037    std::vector<std::string> data_;
00038    bool str_;
00039    const SchemaParser* sParser_;
00040  };
00041 
00042 class WsdlInvoker 
00043 {
00044  public:
00052   WsdlInvoker(const std::string &url);
00053   WsdlInvoker();
00054   ~WsdlInvoker();
00056 
00059   bool setWSDLUri(const std::string &url);
00065   int getOperations(std::vector<std::string> & operations);
00066   std::string getOpDocumentaion(const std::string & n);
00072   bool setOperation(const std::string & operation);
00074 
00077   
00088   bool setValue(const std::string & param,void* val);
00089   bool setValue(const std::string & param,void** values,unsigned int occur);
00090   bool setValue(const std::string & param,std::string val);
00091   bool setValue(const std::string & param,std::vector<std::string> values);//multiple occurrences
00096   bool invoke();
00105   void* getValue(const std::string & param,Schema::Type & t); 
00106   
00108   
00111   
00125   int getNextInput(std::string & param ,Schema::Type & type,int & min,int & max);
00126   
00134   bool setInputValue(const int param,void* val);
00135   bool setInputValue(const int id,void** values,unsigned int occur);
00136 
00144   bool setInputValue(const int param,std::string val);
00145   bool setInputValue(const int param,std::vector<std::string> values);//multiple occurrences
00149   bool getNextOutput(std::string  & name,TypeContainer * & tc);
00154   TypeContainer* getOutput(const std::string  & name);
00155 
00157   
00158   //enable logging
00159   void setVerbose(bool f);
00160   
00161   //get the error message
00162   std::string errors();
00163   //if this returns false something went wrong
00164   bool status()const;
00165 
00166 
00167  private:
00168   //private stuff 
00169 
00170   //creaate xml request
00171   void serialize();
00172   void serializeType(Schema::Type typeId,
00173                      const std::string &tag,
00174                      const SchemaParser * sParser,
00175                      int min,
00176                      int max);
00177   void serializeParam(int n,const std::string & tag,
00178                       const SchemaParser * sParser);
00179   void serializeContentModel(ContentModel *cm,
00180                              const SchemaParser *sParser);
00181   //creaate xml request
00182   void post();//make http post
00183   void processResults();
00184   void parseWsdl(const std::string & url);
00185   //reset state information
00186   void reset();
00187 
00188   WsdlParser * wParser_;
00189   XmlSerializer * xmlStream_;
00190   std::ostringstream * soapstr_;
00191   std::ostringstream logger_;
00192   bool status_;
00193   bool serializeMode_;
00194   bool verbose_;
00195   std::map<std::string,const Operation*> opMap_;
00196   const Operation* op_;
00197   Soap::Encoding use_;//literal or encoded
00198   Soap::Style style_;//rpc or doc
00199   std::string nsp_; // namespace for the operation
00200   std::string location_;
00201   std::string action_;//SOAPAction header
00202   std::vector<Parameter> elems_;//the simple types
00203   std::vector<Parameter> attribs_;//input attributes
00204   size_t n_;//a counter to iterate through the params
00205   std::vector<std::pair<std::string,TypeContainer*> > outputs_;
00206 };
00207 
00208 inline
00209 Parameter::Parameter(Schema::Type t,std::string n,int m,int x,const SchemaParser* s)
00210   :type_(t),
00211      tag_(n),
00212      min_(m),
00213      max_(x),
00214      n_(0),
00215      sParser_(s)
00216      
00217 {
00218 }
00219 
00220 inline
00221 std::string 
00222 WsdlInvoker::errors()
00223 {
00224   return logger_.str();
00225 }
00226 
00227 inline
00228 bool
00229 WsdlInvoker::setWSDLUri(const std::string &url)
00230 {
00231   parseWsdl(url);
00232   return status_;
00233 }
00234 
00235 inline
00236 bool
00237 WsdlInvoker::status()const
00238 {
00239   return status_;
00240 }
00241 
00242 inline
00243 void
00244 WsdlInvoker::setVerbose(bool f)
00245 {
00246   verbose_ = f;
00247 }
00248 #endif

Generated on Sun Oct 16 10:11:52 2005 for wsdlpull by  doxygen 1.3.9.1