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 #include "xmlpull/wsdlpull_export.h"
00029 
00030 
00031 namespace WsdlPull{
00032 
00033  struct Parameter
00034  {
00035    Parameter(Schema::Type ,std::string,int m,int x,const SchemaParser* s,
00036              const std::vector<std::string>& parents);
00037    Schema::Type type_;
00038    std::string tag_;
00039    unsigned int min_;
00040    unsigned int max_;
00041    int n_;
00042    std::vector<std::string> data_;
00043    bool str_;
00044    const SchemaParser* sParser_;
00045    std::vector<std::string> parents_;
00046 
00047  };
00048 
00049 class WSDLPULL_EXPORT WsdlInvoker
00050 {
00051  public:
00059   WsdlInvoker(const std::string &url);
00060   WsdlInvoker();
00061   ~WsdlInvoker();
00063 
00066   bool setWSDLUri(const std::string &url);
00073   // allready parsed wsdl
00074   bool init(WsdlParser* parser);
00075 
00076   int getOperations(std::vector<std::string> & operations);
00077   std::string getOpDocumentaion(const std::string & n);
00083   bool setOperation(const std::string & operation,
00084                     WsdlPull::MessageType mType = WsdlPull::Input);
00088   std::string getServiceEndPoint(const std::string & opname) ;
00090 
00091 
00094   
00105   bool setValue(const std::string & param,void* val);
00106   bool setValue(const std::string & param,void** values,unsigned int occur);
00107   bool setValue(const std::string & param,std::string val);
00108   bool setValue(const std::string & param,std::vector<std::string> values);//multiple occurrences
00109   bool setValue(const std::vector<std::string> & parents,void* val);
00115   bool invoke(long timeout = 0);
00124   void* getValue(const std::string & param,Schema::Type & t); 
00125   
00127   
00130   
00145   int getNextInput(std::string & param ,Schema::Type & type,int & minimum,int & maximum);
00146   int getNextInput(std::string & param ,Schema::Type & type,int & minimum,int & maximum,
00147                    std::vector<std::string>& parents);
00153   int getNextHeaderInput(std::string & param ,Schema::Type & type,int & minimum,int & maximum);
00154   int getNextHeaderInput(std::string & param ,Schema::Type & type,int & minimum,int & maximum,
00155                          std::vector<std::string>& parents);
00159   int nInputHeaders()const;
00160   
00168   bool setInputValue(const int param,void* val);
00169   bool setInputValue(const int id,void** values,unsigned int occur);
00170 
00178   bool setInputValue(const int param,std::string val);
00179   bool setInputValue(const int param,std::vector<std::string> values);//multiple occurrences
00180 
00186   bool getNextOutput(std::string  & name,TypeContainer * & tc);
00187   
00192   TypeContainer* getOutput(const std::string  & name);
00193   
00199    bool getNextHeaderOutput(std::string & name,TypeContainer*& tc);
00200 
00202    // change location of the service
00203   void setLocation(const std::string  & url);
00204   // set credentials for the service
00205   void setCredentials(const std::string & user, const std::string & pass);
00206   void setProxy(const std::string & host,int  port=80);
00207   //enable logging
00208   void setVerbose(bool f);
00209   // prints the output along with typenames like
00210   // name:value.
00211   //if false only value is printed
00212   void printTypeNames(bool f);
00213   //get the error message
00214   std::string errors();
00215   //if this returns false something went wrong
00216   bool status()const;
00217 
00218 
00219  private:
00220   //private stuff 
00221 
00222   //creaate xml request
00223   void serialize();
00224   void serializeType(Schema::Type typeId,
00225                      const std::string &tag,
00226                      const SchemaParser * sParser,
00227                      int minimum,
00228                      int maximum,
00229                      std::vector<std::string> parents);
00230   void serializeParam(int n,const std::string & tag,
00231                       const SchemaParser * sParser);
00232   void serializeContentModel(ContentModel *cm,
00233                              const SchemaParser *sParser,
00234                              std::vector<std::string> parents);
00239   void post(long timeout=0, std::string username="", std::string passwd="");
00240   void processResults();
00241   void processFault(XmlPullParser* xpp);
00242   void processHeader(XmlPullParser *xpp);
00243   void processBody(const Message* m,XmlPullParser* xpp);
00244   void parseWsdl(const std::string & url);
00245   void serializeHeader();
00246   bool isSoapArray (const ComplexType * ct,const SchemaParser * sParser);
00247   //reset state information
00248   void reset();
00249   void getOperationDetails(const Operation* op);
00250 
00251   WsdlParser * wParser_;
00252   WsdlParser * ourParser_;
00253   XmlSerializer * xmlStream_;
00254   Soap* soap_;
00255   const Message* hMessage_;//message corresponding to soap header
00256   int hPartId_;
00257   std::ostringstream * soapstr_;
00258   std::ostringstream logger_;
00259   bool status_;
00260   bool serializeMode_;
00261   bool verbose_;
00262   int oHeaders_;
00263   std::map<std::string,const Operation*> opMap_;
00264   const Operation* op_;
00265   Soap::Encoding use_;//literal or encoded
00266   std::string encodingStyle_; // this is usually the soap encoding style
00267   Soap::Style style_;//rpc or doc
00268   std::string nsp_; // namespace for the operation
00269   std::string location_;
00270   std::string username_,password_,host_;
00271   int port_;
00272   std::string action_;//SOAPAction header
00273   std::vector<Parameter> elems_;//the simple types
00274   std::vector<Parameter> attribs_;//input attributes
00275   size_t n_;//a counter to iterate through the params
00276   int iHeaders_; //number of soap header inputs
00277   std::vector<std::pair<std::string,TypeContainer*> > outputs_;
00278   WsdlPull::MessageType messageType_;
00279 
00280 };
00281 
00282 inline
00283 Parameter::Parameter(Schema::Type t,std::string n,int m,int x,const SchemaParser* s,
00284                      const std::vector<std::string>& parents)
00285   :type_(t),
00286      tag_(n),
00287      min_(m),
00288      max_(x),
00289      n_(0),
00290      sParser_(s),
00291      parents_(parents)
00292      
00293 {
00294 }
00295 
00296 inline
00297 std::string 
00298 WsdlInvoker::errors()
00299 {
00300   return logger_.str();
00301 }
00302 
00303 inline
00304 bool
00305 WsdlInvoker::setWSDLUri(const std::string &url)
00306 {
00307   parseWsdl(url);
00308   return status_;
00309 }
00310 
00311 inline
00312 bool
00313 WsdlInvoker::status()const
00314 {
00315   return status_;
00316 }
00317 
00318 inline 
00319 void
00320 WsdlInvoker::setLocation(const std::string  & url)
00321 {
00322   location_ = url;
00323 }
00324 
00325 inline
00326 void
00327 WsdlInvoker::setVerbose(bool f)
00328 {
00329   verbose_ = f;
00330 }
00331 
00332 inline
00333 int
00334 WsdlInvoker::nInputHeaders()const
00335 {
00336   return iHeaders_;
00337 }
00338 }
00339 #endif
00340 

Generated on Wed Apr 12 18:51:55 2006 for wsdlpull by  doxygen 1.3.9.1