00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef HAVE_CONFIG_H
00021 #include <config.h>
00022 #endif
00023 #ifdef WITH_CURL
00024 #include <curl/curl.h>
00025 #endif
00026
00027 #include <iostream>
00028 using namespace std;
00029
00030 #include "wsdlparser/WsdlInvoker.h"
00031
00032
00033
00034 #ifdef WITH_CURL
00035 size_t storeResults(void * buf, size_t sz, size_t nmemb, void* userdata);
00036 #endif
00037
00038 namespace WsdlPull {
00039
00040 WsdlInvoker::WsdlInvoker()
00041 :wParser_(0),
00042 ourParser_(0),
00043 xmlStream_(0),
00044 soap_(0),
00045 soapheaders_(false),
00046 hPartId_(-1),
00047 soapstr_(0),
00048 status_(false),
00049 serializeMode_(false),
00050 verbose_(false),
00051 dontPost_(false),
00052 oHeaders_(0),
00053 op_(0),
00054 n_(0),
00055 iHeaders_(0),
00056 messageType_(WsdlPull::Input),
00057 bAuth(false),
00058 ctx(0)
00059 {
00060 }
00061
00062 WsdlInvoker::WsdlInvoker(std::istream &input, const std::string &schemaPath)
00063 :wParser_(0),
00064 ourParser_(0),
00065 xmlStream_(0),
00066 soap_(0),
00067 soapheaders_(false),
00068 hPartId_(-1),
00069 soapstr_(0),
00070 status_(false),
00071 serializeMode_(false),
00072 verbose_(false),
00073 dontPost_(false),
00074 op_(0),
00075 n_(0),
00076 iHeaders_(0),
00077 messageType_(WsdlPull::Input),
00078 bAuth(false),
00079 ctx(0)
00080 {
00081 try{
00082 wParser_ = new WsdlParser(input,logger_, schemaPath);
00083 ourParser_= wParser_;
00084 if (wParser_){
00085
00086 while (wParser_->getNextElement () != WsdlParser::END);
00087 if (wParser_->status()){
00088
00089 status_=true;
00090 init(wParser_);
00091 }
00092 }
00093 }
00094 catch (WsdlException we)
00095 {
00096 logger_<<"An exception occurred at "<<we.line
00097 <<":"<<we.col<<std::endl;
00098 logger_<<we.description<<std::endl;
00099 status_ =false;
00100 }
00101 catch (SchemaParserException spe)
00102 {
00103 logger_<<"An exception occurred at "<<spe.line
00104 <<":"<<spe.col<<std::endl;
00105 logger_<<spe.description<<std::endl;
00106 status_ =false;
00107 }
00108 catch (XmlPullParserException xpe)
00109 {
00110 logger_<<"An exception occurred at "<<xpe.line
00111 <<":"<<xpe.col<<std::endl;
00112 logger_<<xpe.description<<std::endl;
00113 status_= false;
00114 }
00115 }
00116
00117 WsdlInvoker::WsdlInvoker(const std::string & url, const std::string & schemaPath)
00118 :wParser_(0),
00119 ourParser_(0),
00120 xmlStream_(0),
00121 soap_(0),
00122 soapheaders_(false),
00123 hPartId_(-1),
00124 soapstr_(0),
00125 status_(false),
00126 serializeMode_(false),
00127 verbose_(false),
00128 dontPost_(false),
00129 op_(0),
00130 n_(0),
00131 iHeaders_(0),
00132 messageType_(WsdlPull::Input),
00133 bAuth(false),
00134 ctx(0)
00135 {
00136 parseWsdl(url, schemaPath);
00137 }
00138
00139
00140 void
00141 WsdlInvoker::parseWsdl(const std::string & url, const std::string & schemaPath)
00142 {
00143 try{
00144 wParser_ = new WsdlParser(url,logger_, schemaPath);
00145 ourParser_= wParser_;
00146 if (wParser_){
00147
00148 while (wParser_->getNextElement () != WsdlParser::END);
00149 if (wParser_->status()){
00150
00151 status_=true;
00152 init(wParser_);
00153 }
00154 }
00155 }
00156 catch (WsdlException we)
00157 {
00158 logger_<<"An exception occurred at "<<we.line
00159 <<":"<<we.col<<std::endl;
00160 logger_<<we.description<<std::endl;
00161 status_ =false;
00162 }
00163 catch (SchemaParserException spe)
00164 {
00165 logger_<<"An exception occurred at "<<spe.line
00166 <<":"<<spe.col<<std::endl;
00167 logger_<<spe.description<<std::endl;
00168 status_ =false;
00169 }
00170 catch (XmlPullParserException xpe)
00171 {
00172 logger_<<"An exception occurred at "<<xpe.line
00173 <<":"<<xpe.col<<std::endl;
00174 logger_<<xpe.description<<std::endl;
00175 status_= false;
00176 }
00177 }
00178
00179 bool
00180 WsdlInvoker::init(WsdlParser* parser)
00181 {
00182 try{
00183 wParser_ = parser;
00184 status_ = wParser_->status();
00185
00186 if (status_){
00187
00188 PortType::cPortTypeIterator p1,p2;
00189 wParser_->getPortTypes(p1,p2);
00190 int i=0;
00191
00192 while(p1!=p2){
00193
00194 Operation::cOpIterator op1,op2;
00195 (*p1)->getOperations(op1,op2);
00196 bool bn = (*p1)->binding(Soap::soapBindingUri11) || (*p1)->binding(Soap::soapBindingUri12) ;
00197
00198
00199 if (!bn){
00200 p1++;
00201 continue;
00202 }
00203
00204 while(op1!=op2){
00205
00206 opMap_[(*op1)->getName()]=*op1;
00207 op1++;
00208 i++;
00209 }
00210 p1++;
00211 }
00212 }
00213 }
00214 catch (WsdlException we)
00215 {
00216 logger_<<"A WSDL exception occurred at"<<we.line
00217 <<":"<<we.col<<std::endl;
00218 logger_<<we.description<<std::endl;
00219 status_ =false;
00220 }
00221 catch (SchemaParserException spe)
00222 {
00223 logger_<<"A Schema Parser exception occurred at "<<spe.line
00224 <<":"<<spe.col<<std::endl;
00225 logger_<<spe.description<<std::endl;
00226 status_ =false;
00227 }
00228 catch (XmlPullParserException xpe)
00229 {
00230 logger_<<"An Xml Parsing exception occurred at row:col "<<xpe.line
00231 <<":"<<xpe.col<<std::endl;
00232 logger_<<xpe.description<<std::endl;
00233 status_ =false;
00234 }
00235 return status_;
00236 }
00237
00238 int
00239 WsdlInvoker::getOperations(std::vector<std::string> & operations)
00240 {
00241 int i = 0;
00242 for(
00243 std::map<std::string,const Operation*>::iterator it =
00244 opMap_.begin();
00245 it != opMap_.end();
00246 it++,i++){
00247
00248 operations.push_back(it->first);
00249 }
00250 return i;
00251 }
00252
00253 std::string
00254 WsdlInvoker::getDocumentation()
00255 {
00256 std::stringstream result;
00257 result << wParser_->getDocumentation();
00258 return result.str();
00259 }
00260
00261 std::string
00262 WsdlInvoker::getOpDocumentation(const std::string & n)
00263 {
00264
00265 std::map<std::string,const Operation*>::iterator it =
00266 opMap_.find(n);
00267
00268 if (it != opMap_.end()){
00269
00270 return it->second->getDocumentation();
00271 }
00272 return "";
00273 }
00274
00275 bool
00276 WsdlInvoker::setOperation(const std::string & opname,
00277 WsdlPull::MessageType mType)
00278 {
00279 reset();
00280 messageType_ = mType;
00281 std::map<std::string,const Operation*>::iterator it =
00282 opMap_.find(opname);
00283
00284 if (it != opMap_.end()){
00285
00286 op_ = it->second;
00287
00288 getOperationDetails(op_);
00289 if (!status_)
00290 return false;
00291
00292 if (soapheaders_){
00293 serializeHeader();
00294 }
00295 serialize();
00296 n_ = iHeaders_;
00297 return status_;
00298 }
00299 else{
00300 return false;
00301 }
00302 }
00303
00304 std::string
00305 WsdlInvoker::getServiceEndPoint(const std::string & opname)
00306 {
00307
00308 reset();
00309 location_="";
00310 std::map<std::string,const Operation*>::iterator it =
00311 opMap_.find(opname);
00312
00313 if (it != opMap_.end()){
00314
00315 const Operation* op = it->second;
00316
00317 getOperationDetails(op);
00318 reset();
00319 }
00320 return location_;
00321 }
00322
00323 void
00324 WsdlInvoker::getOperationDetails(const Operation* op)
00325 {
00326
00327 const Binding * bnSoap = 0;
00328 bnSoap = op->portType()->binding(Soap::soapBindingUri11);
00329 if (bnSoap) {
00330
00331 soap_ = static_cast<Soap*> (wParser_->getExtensibilityHandler(Soap::soapBindingUri11));
00332 }else {
00333
00334 bnSoap = op->portType()->binding(Soap::soapBindingUri12);
00335 soap_ = static_cast<Soap*> (wParser_->getExtensibilityHandler(Soap::soapBindingUri12));
00336
00337 }
00338
00339
00340 soap_->getServiceLocation (bnSoap->getServiceExtId (),location_);
00341 style_ = soap_->getStyle();
00342
00343 if (location_.empty()){
00344
00345 logger_<<"No service location specified for SOAP binding "<<bnSoap->getName()<<std::endl;
00346 status_ = false;
00347 return;
00348 }
00349
00350 const int *bindings = 0;
00351 int opIndex = bnSoap->getOperationIndex(op->getName());
00352 bnSoap->getOpBinding (opIndex, bindings);
00353 int soapOpBindingId = bindings[0];
00354
00355 soap_->getSoapOperationInfo (soapOpBindingId, action_, style_);
00356
00357
00358 int nBindings=bnSoap->getInputBinding(opIndex,bindings);
00359
00360 for (int x=0;x<nBindings;x++){
00361 if (soap_->isSoapBody(bindings[x])){
00362
00363 soap_->getSoapBodyInfo(bindings[x],nsp_,use_,encodingStyle_);
00364 }
00365 if (soap_->isSoapHeader(bindings[x]))
00366 soapheaders_ = true;
00367
00368 }
00369
00370 if (nsp_.empty()){
00371
00372 nsp_ = wParser_->getNamespace();
00373 }
00374 }
00375
00376 void
00377 WsdlInvoker::serializeHeader()
00378 {
00379
00380
00381 std::string name;
00382
00383 int hPartId;
00384 const Message* hMessage;
00385
00386 const Binding * bnSoap = op_->portType()->binding(soap_->getNamespace());
00387 const int *bindings = 0;
00388 int opIndex = op_->portType()->getOperationIndex(op_->getName());
00389 int nBindings=bnSoap->getInputBinding(opIndex,bindings);
00390
00391 for (int x=0;x<nBindings;x++){
00392
00393 if (soap_->isSoapHeader(bindings[x])){
00394
00395 soap_->getSoapHeaderInfo(bindings[x],hnsp_,hPartId,hMessage);
00396
00397
00398 Schema::Type pType =Schema::XSD_INVALID;
00399 if (hMessage->getPartRefType(hPartId)==Part::Elem){
00400
00401 name = hMessage->getMessagePart(hPartId)->element()->getName();
00402 pType = (Schema::Type)hMessage->getMessagePart(hPartId)->element()->getType();
00403 }
00404 else {
00405
00406 name = hMessage->getPartName(hPartId);
00407 pType = (Schema::Type)hMessage->getMessagePart(hPartId)->type();
00408 }
00409 std::vector<std::string> parents;
00410 parents.push_back(name);
00411 serializeType(pType,
00412 name,
00413 wParser_->getSchemaParser(hMessage->getPartContentSchemaId(hPartId)),
00414 1,1,parents,hnsp_,true);
00415 }
00416 }
00417 iHeaders_ = elems_.size();
00418
00419 }
00420
00421
00422
00423
00424
00425
00426 void
00427 WsdlInvoker::serialize()
00428 {
00429 const Message * m = op_->getMessage(messageType_);
00430 if (!m)
00431 return;
00432
00433 for (int i = 0 ;i<m->getNumParts();i++){
00434
00435 Part::PartRefType prt = m->getPartRefType(i);
00436 const Part * p = m->getMessagePart(i);
00437 const SchemaParser * sParser = wParser_->getSchemaParser(p->schemaId());
00438 const std::string nsp = sParser->getNamespace();
00439
00440 std::vector<std::string> parents;
00441 if (prt == Part::Elem){
00442
00443 const Element * e = p->element();
00444 serializeType((Schema::Type)e->getType(),e->getName(),sParser,1,1,parents,nsp,true);
00445 }
00446 else{
00447
00448 serializeType((Schema::Type)p->type(),p->name(),sParser,1,1,parents,nsp,true);
00449 }
00450 }
00451 }
00452
00453 void
00454 WsdlInvoker::serializeType(Schema::Type typeId,
00455 const std::string &tag,
00456 const SchemaParser * sParser,
00457 int minimum,
00458 int maximum,
00459 std::vector<std::string> parents,
00460 const std::string nsp,
00461 bool isRoot)
00462 {
00463 std::string t = tag;
00464 if (t == "*")
00465 t = "item";
00466
00467
00468
00469
00470 const XSDType * pType = sParser->getType(typeId);
00471
00472 for (size_t z=0;z<avoidrecurse_.size();z++){
00473
00474 if (avoidrecurse_[z] == pType)
00475 return;
00476
00477 }
00478 avoidrecurse_.push_back(pType);
00479
00480 if ( pType== 0 ||
00481 pType->isSimple() ||
00482 pType->getContentModel() == Schema::Simple){
00483
00484 if (serializeMode_ == false){
00485
00486 parents.push_back(tag);
00487 Parameter p(typeId,t,minimum,maximum,sParser,parents);
00488 elems_.push_back(p);
00489
00490 #ifdef LOGGING
00491
00492 std::cout<<"Adding input type "<<tag<<XmlUtils::dbsp
00493 <<sParser->getTypeName(typeId)<<XmlUtils::dbsp;
00494 std::cout<<sParser->getNamespace()<<std::endl;
00495 #endif
00496 }
00497 else{
00498
00499 serializeParam(n_++,t,sParser,nsp,isRoot);
00500 }
00501 }
00502 else{
00503
00504 if (serializeMode_){
00505
00506 if (style_ == Soap::DOC ){
00507
00508
00509 if (sParser->getElementQualified()) {
00510
00511 xmlStream_->startTag("",t);
00512 if (isRoot)
00513 xmlStream_->attribute("","xmlns",nsp);
00514 }
00515 else {
00516
00517 if (isRoot) {
00518 xmlStream_->setPrefix(getPrefix(nsp),nsp);
00519 xmlStream_->startTag(nsp,t);
00520 }
00521 else {
00522 xmlStream_->startTag("",t);
00523 }
00524 }
00525 }
00526
00527 else{
00528
00529 xmlStream_->startTag("",t);
00530
00531
00532
00533 const ComplexType* ct = static_cast<const ComplexType*>(pType);
00534 if(isSoapArray(ct,sParser)){
00535
00536 std::string arrayName = ct->getName();
00537 arrayName = "ns:"+arrayName+"[1]";
00538 xmlStream_->attribute(soap_->getEncodingUri(),"arrayType",arrayName);
00539 }
00540 }
00541 }
00542 else {
00543
00544
00545
00546
00547
00548
00549
00550
00551 }
00552
00553
00554 const ComplexType * ct =
00555 static_cast<const ComplexType*>(pType);
00556
00557
00558 if (ct->getNumAttributes() > 0) {
00559
00560 for (int i = 0; i < ct->getNumAttributes(); i++) {
00561
00562 const Attribute*at = ct->getAttribute(i);
00563
00564
00565
00566 if (at->isRequired()){
00567
00568 if (serializeMode_ == false){
00569
00570 std::vector<std::string> attparents(parents);
00571 attparents.push_back(tag);
00572 attparents.push_back("#" + at->getName() + "#");
00573 Parameter p((Schema::Type)at->getType(),at->getName(),elems_.size(),0,sParser,
00574 attparents);
00575 elems_.push_back(p);
00576 }
00577 else{
00578
00579
00580 xmlStream_->attribute(sParser->getNamespace(),at->getName(),elems_[n_++].data_[0]);
00581 }
00582 }
00583 else
00584 continue;
00585 }
00586 }
00587
00588 if (ct->getContentModel() == Schema::Simple) {
00589
00590 if (serializeMode_ == false){
00591
00592 parents.push_back(tag);
00593 Parameter p((Schema::Type)ct->getContentType(),tag,minimum,maximum,sParser,parents);
00594 elems_.push_back(p);
00595 }
00596 else{
00597
00598 serializeParam(n_++,t,sParser,nsp,isRoot);
00599 }
00600 }
00601 else{
00602
00603 const XSDType * baseType=sParser->getType(ct->getBaseTypeId());
00604 if (baseType && !baseType->isSimple()){
00605
00606 const ComplexType * cType=static_cast<const ComplexType*>(baseType);
00607 ContentModel * bCm = cType->getContents();
00608 if (bCm){
00609
00610 parents.push_back(tag);
00611 serializeContentModel(bCm,sParser,parents);
00612 }
00613 }
00614 ContentModel* cm=ct->getContents();
00615 if(cm){
00616
00617 parents.push_back(tag);
00618 serializeContentModel(cm,sParser,parents);
00619 }
00620 }
00621
00622 if (serializeMode_){
00623
00624
00625
00626
00627
00628 if (style_ == Soap::DOC ){
00629
00630 if (sParser->getElementQualified()) {
00631
00632 xmlStream_->endTag("",t);
00633 }
00634 else {
00635
00636 if (isRoot) {
00637
00638 xmlStream_->endTag(nsp,t);
00639 }
00640 else {
00641 xmlStream_->endTag("",t);
00642 }
00643 }
00644 }
00645 else{
00646
00647 xmlStream_->endTag("",t);
00648
00649
00650 }
00651 }
00652 }
00653 avoidrecurse_.pop_back();
00654 }
00655
00656 void
00657 WsdlInvoker::serializeContentModel(ContentModel *cm,
00658 const SchemaParser *sParser,
00659 std::vector<std::string> parents)
00660 {
00661
00662 ContentModel::ContentsIterator cit_b=cm->begin();
00663 ContentModel::ContentsIterator cit_e=cm->end();
00664 ContentModel::ContentsIterator ci=cit_b;
00665
00666
00667 switch (cm->getCompositor())
00668 {
00669 case Schema::All:
00670 case Schema::Sequence:
00671 case Schema::Choice:
00672 {
00673
00674
00675
00676 for (ci=cit_b;ci!=cit_e;ci++){
00677
00678 if(ci->second==ContentModel::Particle &&
00679 ci->first.e->getMax() > 0){
00680
00681
00682 const SchemaParser* s1Parser = sParser;
00683 bool isRoot = false;
00684 std::string nsp;
00685 Schema::Type t=(Schema::Type)ci->first.e->getType();
00686
00687 if (!ci->first.e->getTypeNamespace().empty() &&
00688 sParser->isImported(ci->first.e->getTypeNamespace()) &&
00689 sParser->getNamespace() != ci->first.e->getTypeNamespace()) {
00690
00691
00692
00693 if ( !sParser->isBasicType(t)){
00694 t = (Schema::Type)sParser->getType(t)->getTypeId();
00695 sParser = sParser->getImportedSchemaParser(ci->first.e->getTypeNamespace());
00696 }
00697 if(ci->first.e->getNamespace() != s1Parser->getNamespace()){
00698 nsp = ci->first.e->getNamespace();
00699 isRoot = true ;
00700 }
00701
00702 }
00703
00704 serializeType(t,
00705 ci->first.e->getName(),
00706 sParser,
00707 ci->first.e->getMin(),
00708 ci->first.e->getMax(),
00709 parents,
00710 nsp,isRoot);
00711 sParser = s1Parser;
00712 }
00713 else if (ci->second==ContentModel::Container) {
00714
00715
00716 serializeContentModel(ci->first.c,
00717 sParser,
00718 parents);
00719
00720 }
00721 else if (ci->second==ContentModel::ParticleGroup){
00722
00723
00724 serializeContentModel(ci->first.g->getContents(),
00725 sParser,
00726 parents);
00727 }
00728 }
00729 break;
00730 }
00731 }
00732 }
00733
00734
00735 void
00736 WsdlInvoker::serializeParam(int n,const std::string & tag,
00737 const SchemaParser * sParser,
00738 const std::string nsp,
00739 bool isRoot)
00740 {
00741
00742 std::string t=tag;
00743 if (tag=="*")
00744 t="item";
00745
00746 for (int i = 0 ;i<elems_[n].n_;i++){
00747
00748 if (style_ == Soap::DOC){
00749
00750 if (!isRoot)
00751 xmlStream_->startTag("",t);
00752
00753 else {
00754
00755 if (!nsp.empty())
00756 xmlStream_->setPrefix(getPrefix(nsp),nsp);
00757
00758 xmlStream_->startTag(nsp,t);
00759
00760 }
00761 }
00762 else{
00763
00764 xmlStream_->startTag("",t);
00765
00766
00767 if (sParser->isBasicType(elems_[n].type_) &&
00768 use_ == Soap::ENCODED){
00769
00770 xmlStream_->attribute(Schema::SchemaInstaceUri,
00771 "type",
00772 "xsd:"+sParser->getTypeName(elems_[n].type_));
00773 }
00774 }
00775
00776 xmlStream_->text(elems_[n].data_[i]);
00777 if (style_ == Soap::DOC && isRoot)
00778 xmlStream_->endTag(nsp,t);
00779 else
00780 xmlStream_->endTag("",t);
00781
00782
00783 }
00784 }
00785
00786
00787 bool
00788 WsdlInvoker::setInputValue(const int param,void** values,unsigned int occurs)
00789 {
00790
00791 if (occurs < elems_[param].min_ ||
00792 occurs > elems_[param].max_)
00793 return false;
00794
00795 SchemaValidator *sv = new SchemaValidator (elems_[param].sParser_);
00796 for (unsigned int i = 0 ;i < occurs ;i++){
00797
00798 TypeContainer * tc = sv->validate(values[i],
00799 elems_[param].type_);
00800 if (!tc->isValueValid()){
00801
00802 return false;
00803 }
00804 std::ostringstream oss;
00805 tc->print(oss);
00806 elems_[param].data_.push_back(oss.str());
00807 delete tc;
00808 }
00809 delete sv;
00810
00811 elems_[param].n_ = occurs;
00812 return true;
00813 }
00814
00815 bool
00816 WsdlInvoker::setInputValue(const int param,std::vector<std::string> values)
00817 {
00818
00819
00820 if (values.size() < elems_[param].min_ ||
00821 values.size() > elems_[param].max_)
00822 return false;
00823
00824 SchemaValidator *sv = new SchemaValidator (elems_[param].sParser_);
00825
00826 for (size_t i = 0 ;i < values.size() ;i++){
00827
00828 TypeContainer * tc = sv->validate(values[i],
00829 elems_[param].type_);
00830 if (!tc->isValueValid()){
00831
00832 return false;
00833 }
00834 elems_[param].data_.push_back(values[i]);
00835 delete tc;
00836 }
00837 delete sv;
00838
00839 elems_[param].n_ = values.size();
00840 return true;
00841 }
00842
00843 bool
00844 WsdlInvoker::setInputValue(const int param,std::string val)
00845 {
00846
00847 const SchemaParser* sParser = elems_[param].sParser_;
00848 SchemaValidator *sv = new SchemaValidator (sParser);
00849 Schema::Type t = elems_[param].type_;
00850 const XSDType * pType = sParser->getType(t);
00851 if (pType && !pType->isSimple()){
00852
00853 if (pType->getContentModel() != Schema::Simple)
00854 return false;
00855
00856 const ComplexType * ct = static_cast<const ComplexType*>(pType);
00857 t = (Schema::Type)ct->getContentType();
00858 }
00859
00860 TypeContainer * tc = sv->validate(val,t);
00861 if (!(tc && tc->isValueValid())){
00862
00863 return false;
00864 }
00865 if (elems_[param].data_.size() == 0)
00866 elems_[param].data_.push_back(val);
00867 else
00868 elems_[param].data_[0]=val;
00869
00870 delete tc;
00871
00872 delete sv;
00873
00874 elems_[param].n_ = 1;
00875 return true;
00876 }
00877
00878
00879
00880 bool
00881 WsdlInvoker::setInputValue(const int param,void* val)
00882 {
00883
00884 const SchemaParser* sParser = elems_[param].sParser_;
00885 SchemaValidator *sv = new SchemaValidator (sParser);
00886 Schema::Type t = elems_[param].type_;
00887 const XSDType * pType = sParser->getType(t);
00888 if (pType && !pType->isSimple()){
00889
00890 if (pType->getContentModel() != Schema::Simple)
00891 return false;
00892
00893 const ComplexType * ct = static_cast<const ComplexType*>(pType);
00894 t = (Schema::Type)ct->getContentType();
00895 }
00896
00897 TypeContainer * tc = sv->validate(val,t);
00898 if (!(tc && tc->isValueValid())){
00899
00900 return false;
00901 }
00902 std::ostringstream oss;
00903 tc->print(oss);
00904 if (elems_[param].data_.size() == 0)
00905 elems_[param].data_.push_back(oss.str());
00906 else
00907 elems_[param].data_[0]=oss.str();
00908 delete tc;
00909 delete sv;
00910 elems_[param].n_ = 1;
00911 return true;
00912 }
00913
00914 bool
00915 WsdlInvoker::setValue(const std::string & param,void* val)
00916 {
00917 for (size_t s = 0;s<elems_.size();s++){
00918
00919 if (elems_[s].tag_ == param)
00920 return setInputValue(s,val);
00921 }
00922 return false;
00923 }
00924
00925 bool
00926 WsdlInvoker::setValue(const std::string & param,void** values,unsigned int occur)
00927 {
00928
00929 for (size_t s = 0;s<elems_.size();s++){
00930
00931 if (elems_[s].tag_ == param)
00932 return setInputValue(s,values,occur);
00933 }
00934 return false;
00935 }
00936
00937 bool
00938 WsdlInvoker::setValue(const std::string & param,std::string val)
00939 {
00940 for (size_t s = 0;s<elems_.size();s++){
00941
00942 if (elems_[s].tag_ == param)
00943 return setInputValue(s,val);
00944 }
00945 return false;
00946 }
00947
00948 bool
00949 WsdlInvoker::setValue(const std::string & param,std::vector<std::string> values)
00950 {
00951 for (size_t s = 0;s<elems_.size();s++){
00952
00953 if (elems_[s].tag_ == param)
00954 return setInputValue(s,values);
00955 }
00956 return false;
00957 }
00958
00959
00960 std::string
00961 WsdlInvoker::getSoapMessage(){
00962
00963 dontPost_ = true;
00964 invoke();
00965 dontPost_ = false;
00966 return soapstr_->str();
00967 }
00968
00969 std::string
00970 WsdlInvoker::getXMLResponse(){
00971
00972 return strResults_;
00973 }
00974
00975
00976 bool
00977 WsdlInvoker::invoke(long timeout,bool processResponse)
00978 {
00979
00980 try{
00981
00982 if (xmlStream_){
00983
00984 delete xmlStream_;
00985 }
00986 if (soapstr_){
00987
00988 delete soapstr_;
00989 }
00990 if (!strResults_.empty()){
00991 strResults_.clear();
00992 }
00993
00994
00995 for (size_t x = 0;x<outputs_.size();x++)
00996 delete outputs_[x].second;
00997
00998 outputs_.clear();
00999
01000 soapstr_ = new std::ostringstream();
01001 xmlStream_ = new XmlSerializer(*soapstr_);
01002
01003 serializeMode_ = true;
01004
01005 xmlStream_->startDocument("UTF-8",false);
01006 xmlStream_->setPrefix("SOAP-ENV",soap_->getEnvelopeUri());
01007 xmlStream_->setPrefix("SOAP-ENC",soap_->getEncodingUri());
01008 xmlStream_->setPrefix("xsd",Schema::SchemaUri);
01009 xmlStream_->setPrefix("xsi",Schema::SchemaInstaceUri);
01010 xmlStream_->setPrefix(getPrefix(nsp_),nsp_);
01011 xmlStream_->startTag(soap_->getEnvelopeUri(),"Envelope");
01012
01013 if (style_ == Soap::RPC) {
01014
01015 xmlStream_->attribute(soap_->getEnvelopeUri(),
01016 "encodingStyle",
01017 soap_->getEncodingUri());
01018 }
01019
01020 n_ = 0;
01021 if (soapheaders_){
01022 xmlStream_->startTag(soap_->getEnvelopeUri(),"Header");
01023 serializeHeader();
01024 xmlStream_->endTag(soap_->getEnvelopeUri(),"Header");
01025 }
01026
01027 xmlStream_->startTag(soap_->getEnvelopeUri(),"Body");
01028 if (style_ == Soap::RPC){
01029
01030 xmlStream_->startTag(nsp_,op_->getName());
01031 }
01032
01033 serialize();
01034 if (style_ == Soap::RPC){
01035 xmlStream_->endTag(nsp_,op_->getName());
01036 }
01037
01038 xmlStream_->endTag(soap_->getEnvelopeUri(),"Body");
01039 xmlStream_->endTag(soap_->getEnvelopeUri(),"Envelope");
01040 xmlStream_->flush();
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051 if (dontPost_)
01052 return true;
01053
01054 post(timeout);
01055 if (!strResults_.empty()){
01056
01057 if (processResponse)
01058 processResults();
01059
01060 if (status_)
01061 return true;
01062 }
01063 else{
01064
01065 if (!op_->getMessage(WsdlPull::Output))
01066 return true;
01067
01068 logger_<<"Couldnt connect to "<<location_;
01069 }
01070 return false;
01071 }
01072 catch (WsdlException we)
01073 {
01074 logger_<<"A WSDL exception occurred at"<<we.line
01075 <<":"<<we.col<<std::endl;
01076 logger_<<we.description<<std::endl;
01077 return false;
01078 }
01079 catch (SchemaParserException spe)
01080 {
01081 logger_<<"A Schema Parser exception occurred at "<<spe.line
01082 <<":"<<spe.col<<std::endl;
01083 logger_<<spe.description<<std::endl;
01084 return false;
01085 }
01086 catch (XmlPullParserException xpe)
01087 {
01088 logger_<<"An Xml Parsing exception occurred at row:col "<<xpe.line
01089 <<":"<<xpe.col<<std::endl;
01090 logger_<<xpe.description<<std::endl;
01091 return false;
01092 }
01093 }
01094
01095 int
01096 WsdlInvoker::getNextInput(std::string & param ,Schema::Type & type,int & minimum,int & maximum)
01097 {
01098 std::vector<std::string> parents;
01099 return getNextInput(param, type, minimum, maximum, parents);
01100 }
01101
01102 int
01103 WsdlInvoker::getNextInput(std::string & param ,Schema::Type & type,int & minimum,int & maximum,
01104 std::vector<std::string> & parents)
01105 {
01106 if (n_ < elems_.size()){
01107
01108 param = elems_[n_].tag_;
01109 type = elems_[n_].type_;
01110 minimum = elems_[n_].min_;
01111 parents = elems_[n_].parents_;
01112 maximum = elems_[n_].max_;
01113 return n_++;
01114 }
01115 else{
01116 return -1;
01117 }
01118 }
01119
01120 int
01121 WsdlInvoker::getNextHeaderInput(std::string & param ,Schema::Type & type,
01122 int & minimum,int & maximum)
01123 {
01124
01125 std::vector<std::string> parents;
01126 return getNextHeaderInput(param,type,minimum,maximum,parents);
01127 }
01128
01129 int
01130 WsdlInvoker::getNextHeaderInput(std::string & param ,Schema::Type & type,
01131 int & minimum,int & maximum,
01132 std::vector<std::string> & parents)
01133 {
01134 static int h = 0;
01135 if (h<iHeaders_){
01136 param = elems_[h].tag_;
01137 type = elems_[h].type_;
01138 minimum = elems_[h].min_;
01139 maximum = elems_[h].max_;
01140 parents = elems_[h].parents_;
01141 return h++;
01142 }
01143 else{
01144 h = 0;
01145 return -1;
01146 }
01147 }
01148
01149 void
01150 WsdlInvoker::processResults()
01151 {
01152 XmlPullParser* xpp = 0;
01153 try{
01154
01155 const Message* m = op_->getMessage(WsdlPull::Output);
01156 std::istringstream respstr(strResults_);
01157
01158 xpp = new XmlPullParser(respstr);
01159 xpp->setFeature (FEATURE_PROCESS_NAMESPACES, true);
01160 xpp->require (XmlPullParser::START_DOCUMENT, "", "");
01161
01162 while (status_ &&
01163 xpp->getEventType () != XmlPullParser::END_DOCUMENT) {
01164
01165 if (xpp->getEventType () == XmlPullParser::END_DOCUMENT)
01166 break;
01167
01168 if (xpp->getEventType () == XmlPullParser::END_TAG &&
01169 xpp->getName() == "Envelope" &&
01170 xpp->getNamespace() == soap_->getEnvelopeUri())
01171 break;
01172
01173
01174 xpp->nextTag();
01175 Qname elemName (xpp->getName ());
01176 elemName.setNamespace(xpp->getNamespace());
01177
01178 if (elemName.getNamespace() == soap_->getEnvelopeUri()){
01179
01180 if (elemName.getLocalName() == "Fault"){
01181 processFault(xpp);
01182 status_ = false;
01183 delete xpp;
01184 return;
01185 }
01186 else if (elemName.getLocalName() == "Header"){
01187
01188 processHeader(xpp);
01189 }
01190 else if (elemName.getLocalName() == "Body"){
01191
01192 xpp->nextTag();
01193 processBody(m,xpp);
01194 }
01195 }
01196 }
01197 delete xpp;
01198 n_ = oHeaders_;
01199 }
01200 catch (WsdlException we)
01201 {
01202
01203 logger_<<"A WSDL exception occurred while parsing the response at line "<<we.line
01204 <<":"<<we.col<<std::endl;
01205 logger_<<we.description<<std::endl;
01206 status_ =false;
01207 if (xpp) delete xpp;
01208 }
01209 catch (SchemaParserException spe)
01210 {
01211 logger_<<"A Schema Parser exception occurred while parsing the response at line "<<spe.line
01212 <<":"<<spe.col<<std::endl;
01213 logger_<<spe.description<<std::endl;
01214 status_ =false;
01215 if (xpp) delete xpp;
01216 }
01217 catch (XmlPullParserException xpe)
01218 {
01219 logger_<<"An Xml Parsing exception occurred while parsing the response at line "<<xpe.line
01220 <<":"<<xpe.col<<std::endl;
01221 logger_<<xpe.description<<std::endl;
01222 status_ =false;
01223 if (xpp) delete xpp;
01224 }
01225 return;
01226 }
01227
01228 WsdlInvoker::~WsdlInvoker()
01229 {
01230 reset();
01231 if (ourParser_){
01232 delete ourParser_;
01233 }
01234 if (xmlStream_){
01235
01236 delete xmlStream_;
01237 }
01238 if (soapstr_){
01239
01240 delete soapstr_;
01241 }
01242
01243 #ifdef WITH_CURL
01244 if(ctx) {
01245 curl_easy_cleanup(ctx) ;
01246 }
01247 #endif
01248 }
01249
01250 void
01251 WsdlInvoker::reset()
01252 {
01253 n_ = iHeaders_ = oHeaders_ = 0;
01254 elems_.clear();
01255
01256 for (size_t x = 0;x<outputs_.size();x++)
01257 delete outputs_[x].second;
01258
01259 outputs_.clear();
01260 serializeMode_ = false;
01261
01262
01263
01264 }
01265
01266 bool
01267 WsdlInvoker::getNextOutput(std::string & name,TypeContainer * & tc)
01268 {
01269 if (status_ && n_ < outputs_.size()){
01270
01271 name = outputs_[n_].first;
01272 tc = outputs_[n_].second;
01273 n_++;
01274 return true;
01275 }
01276 n_ = oHeaders_;
01277 return false;
01278 }
01279
01280
01281 TypeContainer*
01282 WsdlInvoker::getOutput(const std::string & name)
01283 {
01284 for (unsigned int i = 0 ;status_ && i <outputs_.size();i++){
01285
01286 if ( name == outputs_[i].first)
01287 return outputs_[i].second;
01288 }
01289 return 0;
01290 }
01291
01292 bool
01293 WsdlInvoker::getNextHeaderOutput(std::string & name,TypeContainer*& tc)
01294 {
01295 static int j = 0;
01296 if(j<oHeaders_){
01297 name = outputs_[j].first;
01298 tc = outputs_[j].second;
01299 j++;
01300 return true;
01301 }
01302 else{
01303 j = 0;
01304 return false;
01305 }
01306 }
01307
01308 void *
01309 WsdlInvoker::getValue(const std::string & name ,Schema::Type & t)
01310 {
01311 for (unsigned int i = 0 ;status_ && i <outputs_.size();i++){
01312
01313 if (outputs_[i].second!=0){
01314 outputs_[i].second->rewind();
01315 void * tmp= outputs_[i].second->getValue(name,t);
01316 if (tmp)
01317 return tmp;
01318 }
01319 }
01320 return 0;
01321 }
01322
01323
01324
01325 std::string
01326 WsdlInvoker::getAsStringFromXPath(const std::string & xpath,
01327 std::vector<std::string> * arr)
01328 {
01329
01330 if( status_ && !strResults_.empty()){
01331
01332 if( xpath.empty())
01333 return "";
01334
01335
01336 std::vector<std::string> tree;
01337 std::string element;
01338 bool l_SeenSlash = false;
01339 bool l_MatchFromRoot = false;
01340 bool l_MatchAllAfterCertainLevel = false;
01341 size_t l_MatchAllAfterLevel = 0;
01342
01343 for( size_t l_s = 0; l_s < xpath.size(); l_s++) {
01344
01345 if( xpath[ l_s] == '/') {
01346
01347 if( l_SeenSlash == false) {
01348
01349 l_SeenSlash = true;
01350
01351 if( element.empty() == false) {
01352 tree.push_back( element);
01353 element.clear();
01354 }
01355
01356 } else {
01357
01358
01359
01360 l_MatchAllAfterCertainLevel = true;
01361
01362
01363
01364 l_MatchAllAfterLevel = tree.size();
01365 l_SeenSlash = false;
01366 }
01367
01368 } else {
01369
01370
01371
01372 if( l_s == 1 && l_SeenSlash == true)
01373 l_MatchFromRoot = true;
01374
01375 l_SeenSlash = false;
01376 element.append( 1, xpath[ l_s]);
01377 }
01378 }
01379
01380
01381 if( element.empty() == false)
01382 tree.push_back( element);
01383
01384
01385
01386 std::istringstream respstr(strResults_);
01387
01388
01389 XmlPullParser* xpp = new XmlPullParser(respstr);
01390 xpp->setFeature (FEATURE_PROCESS_NAMESPACES, true);
01391 xpp->require (XmlPullParser::START_DOCUMENT, "", "");
01392
01393 size_t level = 0, levelxml = 0;
01394 size_t l_waitingForClosingTagAtLevel = 0;
01395 bool l_dirty = false;
01396
01397 ::std::string tmp, l_name;
01398
01399 while( xpp->getEventType() != XmlPullParser::END_DOCUMENT) {
01400
01401 if( xpp->getEventType() == XmlPullParser::START_TAG) {
01402
01403
01404
01405 l_name = xpp->getName();
01406
01407
01408 if( levelxml == 0 && (l_name == "Envelope" || l_name == "Body")) {
01409 xpp->nextToken();
01410 continue;
01411 }
01412
01413 levelxml++;
01414
01415 if( l_name == tree[ level] &&
01416 ( l_waitingForClosingTagAtLevel == 0 ||
01417 ( l_MatchAllAfterCertainLevel == true && level >= ( l_MatchAllAfterLevel - 1)))
01418 ) {
01419
01420
01421
01422
01423 if( l_MatchFromRoot == true) {
01424
01425 if( level == 0 && levelxml != 1) {
01426
01427 xpp->nextToken();
01428 continue;
01429 }
01430 }
01431
01432 level++;
01433
01434 if( level == tree.size()) {
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445 xpp->nextToken();
01446 tmp = xpp->getText();
01447 xpp->nextToken();
01448 while( xpp->getEventType() == XmlPullParser::ENTITY_REF ||
01449 xpp->getEventType() == XmlPullParser::TEXT){
01450
01451 tmp += xpp->getText();
01452 xpp->nextToken();
01453 }
01454
01455
01456 l_dirty = true;
01457
01458 } else if( level == ( tree.size() - 1) && tree[level][0] == '@') {
01459
01460
01461
01462
01463
01464
01465
01466 std::string attr = tree[ level].substr( 1);
01467 tmp = xpp->getAttributeValue( "", attr);
01468
01469
01470 l_dirty = true;
01471 }
01472
01473 if( l_dirty == true) {
01474 if( arr == NULL)
01475 return tmp;
01476
01477 arr->push_back( tmp);
01478 level--;
01479
01480 l_dirty = false;
01481 }
01482
01483 }
01484 else if( level > 0 && l_waitingForClosingTagAtLevel == 0) {
01485
01486 l_waitingForClosingTagAtLevel = levelxml;
01487 }
01488
01489 }
01490
01491
01492
01493
01494
01495
01496 if( xpp->getEventType() == XmlPullParser::END_TAG) {
01497
01498 if( levelxml == l_waitingForClosingTagAtLevel)
01499 l_waitingForClosingTagAtLevel = 0;
01500
01501
01502
01503 if( levelxml == 0) {
01504 xpp->nextToken();
01505 continue;
01506 }
01507
01508 levelxml--;
01509 }
01510
01511
01512
01513
01514 xpp->nextToken();
01515 }
01516
01517 }
01518 else {
01519
01520 WsdlException we("Attempted to extract response when web service invocation did not succeed");
01521 throw we;
01522 }
01523
01524 return "";
01525 }
01526
01527
01528 void
01529 WsdlInvoker::post(long timeout, std::string username, std::string passwd)
01530 {
01531 const std::string postData = soapstr_->str();
01532 if(verbose_){
01533
01534 std::ofstream ofs("request.log",std::ios::app);
01535 ofs<<postData;
01536 ofs<<std::endl;
01537 ofs.flush();
01538 }
01539
01540 #ifdef WITH_CURL
01541 CURLcode res;
01542 std::string strCurlBuffer = "";
01543 if (!ctx){
01544 ctx=curl_easy_init();
01545 }
01546
01547 if (!ctx)
01548 return ;
01549 curl_easy_setopt( ctx , CURLOPT_URL, location_.c_str()) ;
01550
01551 curl_easy_setopt( ctx , CURLOPT_NOPROGRESS , 1 ) ;
01552 if(timeout){
01553 curl_easy_setopt( ctx ,CURLOPT_TIMEOUT, timeout);
01554 curl_easy_setopt( ctx , CURLOPT_CONNECTTIMEOUT, timeout);
01555 }
01556
01557 if (verbose_) {
01558 curl_easy_setopt( ctx , CURLOPT_VERBOSE,1);
01559 curl_easy_setopt( ctx , CURLOPT_NOPROGRESS , 0 ) ;
01560 }
01561
01562 curl_easy_setopt( ctx , CURLOPT_POST , 1 );
01563 curl_easy_setopt( ctx , CURLOPT_POSTFIELDS , postData.c_str()) ;
01564 curl_slist* responseHeaders = NULL ;
01565 std::string tmp="SOAPAction: ";
01566 tmp.push_back('"');
01567 tmp+=action_;
01568 tmp.push_back('"');
01569 responseHeaders = curl_slist_append( responseHeaders , tmp.c_str());
01570 responseHeaders = curl_slist_append( responseHeaders ,"Content-Type: text/xml; charset=UTF-8");
01571 responseHeaders = curl_slist_append( responseHeaders ,"Accept: text/xml;");
01572 curl_easy_setopt( ctx , CURLOPT_HTTPHEADER , responseHeaders ) ;
01573 tmp = "wsdlpull";
01574 #ifdef HAVE_CONFIG_H
01575 tmp=tmp+"/"+VERSION;
01576 #endif
01577 curl_easy_setopt( ctx,CURLOPT_USERAGENT,tmp.c_str());
01578 curl_easy_setopt( ctx,CURLOPT_POSTFIELDSIZE,postData.length());
01579
01580 if (XmlUtils::getProxy()){
01581 curl_easy_setopt(ctx,CURLOPT_PROXY,XmlUtils::getProxyHost().c_str());
01582 tmp=XmlUtils::getProxyUser()+":"+XmlUtils::getProxyPass();
01583 curl_easy_setopt(ctx,CURLOPT_PROXYUSERPWD,tmp.c_str());
01584 }
01585 curl_easy_setopt(ctx, CURLOPT_WRITEDATA, &strCurlBuffer) ;
01586 curl_easy_setopt( ctx ,CURLOPT_WRITEFUNCTION,storeResults) ;
01587
01588 if (bAuth) {
01589 curl_easy_setopt(ctx, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
01590 std::string tmp = sAuthUser + ":" + sAuthPass;
01591 curl_easy_setopt(ctx, CURLOPT_USERPWD, tmp.c_str());
01592 }
01593 curl_easy_setopt(ctx, CURLOPT_COOKIEFILE, "");
01594
01595 res=curl_easy_perform(ctx);
01596
01597
01598 curl_slist_free_all( responseHeaders ) ;
01599 strResults_ = strCurlBuffer;
01600
01601 #elif _WIN32
01602
01603 char* sResults = 0;
01604 XmlUtils::winPost(location_,username,passwd,postData,action_,sResults);
01605 strResults_ = std::string(sResults);
01606 #endif
01607
01608 if(verbose_ && !strResults_.empty()){
01609
01610 std::ofstream ofs("response.log",std::ios::app);
01611 ofs<<strResults_;
01612 ofs<<std::endl;
01613 ofs.flush();
01614 }
01615
01616 }
01617
01618 void
01619 WsdlInvoker::printTypeNames(bool f)
01620 {
01621 TypeContainer::printTypeNames_ = false;
01622 }
01623
01624
01625 void
01626 WsdlInvoker::processFault(XmlPullParser* xpp)
01627 {
01628
01629 if (soap_->getSoapVersion() == Soap::SOAP12) {
01630
01631 while (!(xpp->getEventType() == XmlPullParser::END_TAG && xpp->getName() == "Fault")) {
01632
01633 if (xpp->getEventType() == XmlPullParser::START_TAG && xpp->getName() == "Code") {
01634 xpp->next();
01635
01636 while (!(xpp->getEventType() == XmlPullParser::END_TAG && xpp->getName() == "Code")) {
01637
01638 if (xpp->getEventType() == XmlPullParser::START_TAG && xpp->getName() == "Value") {
01639 xpp->next();
01640 sFaultCode = xpp->getText();
01641 logger_ << "SOAP Fault Code: " << sFaultCode << std::endl;
01642 }
01643
01644 if (xpp->getEventType() == XmlPullParser::START_TAG && xpp->getName() == "Subcode") {
01645 xpp->next();
01646
01647 if (xpp->getEventType() == XmlPullParser::START_TAG && xpp->getName() == "Value") {
01648 xpp->next();
01649 sFaultSubCode = xpp->getText();
01650 logger_ << "SOAP Fault SubCode: " << sFaultSubCode << std::endl;
01651 }
01652 }
01653 xpp->next();
01654 }
01655 }
01656
01657 if (xpp->getEventType() == XmlPullParser::START_TAG && xpp->getName() == "Reason") {
01658 xpp->next();
01659
01660 if (xpp->getEventType() == XmlPullParser::START_TAG && xpp->getName() == "Text") {
01661 xpp->next();
01662 sFaultString = xpp->getText();
01663 logger_ << "SOAP Fault String: " << sFaultString << std::endl;
01664 }
01665 }
01666 xpp->next();
01667 }
01668 } else {
01669
01670 while (!(xpp->getEventType () == XmlPullParser::END_TAG &&
01671 xpp->getName() == "Fault")) {
01672
01673 if (xpp->getEventType() == XmlPullParser::START_TAG &&
01674 xpp->getName() == "faultcode"){
01675
01676 xpp->next();
01677 sFaultCode = xpp->getText();
01678 logger_<<"SOAP Fault Code: "<<sFaultCode<<std::endl;
01679 }
01680
01681 if (xpp->getEventType() == XmlPullParser::START_TAG &&
01682 xpp->getName() == "faultstring"){
01683
01684 xpp->next();
01685 sFaultString = xpp->getText();
01686 logger_<<"SOAP Fault String: "<<sFaultString<<std::endl;
01687 }
01688 if (xpp->getEventType() == XmlPullParser::START_TAG &&
01689 xpp->getName() == "faultactor"){
01690
01691 xpp->next();
01692 sFaultActor = xpp->getText();
01693 logger_<<"SOAP Fault Actor: "<<sFaultActor<<std::endl;
01694 }
01695 xpp->next();
01696 }
01697 }
01698 }
01699
01700 void
01701 WsdlInvoker::processBody(const Message* m,
01702 XmlPullParser* xpp)
01703 {
01704
01705 if (xpp->getName() == "Fault") {
01706
01707 processFault(xpp);
01708 status_ = false;
01709 return;
01710 }
01711
01712 if (style_ == Soap::RPC && use_==Soap::ENCODED){
01713
01714 if (xpp->getName () == op_->getName()+"Response") {
01715
01716
01717 xpp->nextTag ();
01718
01719 do {
01720
01721
01722
01723 Qname typ(xpp->getAttributeValue(Schema::SchemaInstaceUri, "type"));
01724 typ.setNamespace(xpp->getNamespace(typ.getPrefix()));
01725 const SchemaParser * sParser = 0;
01726 int typeId = 0;
01727
01728 if (!(typ.getNamespace() == soap_->getEncodingUri() &&
01729 typ.getLocalName() == "Array"))
01730 sParser= wParser_->getSchemaParser(typ.getNamespace());
01731
01732 if (sParser){
01733
01734 typeId = (const_cast<SchemaParser*>(sParser))->getTypeId(typ);
01735 }
01736 else{
01737
01738
01739 const Part * p = m->getMessagePart(xpp->getName ());
01740 if (p){
01741
01742 sParser = wParser_->getSchemaParser(p->schemaId());
01743 typeId = p->type();
01744 }else {
01745
01746
01747 }
01748 }
01749 if (sParser && typeId !=0){
01750
01751 SchemaValidator * sv= new SchemaValidator(sParser);
01752 std::string tag = xpp->getName();
01753 TypeContainer * t = sv->validate (xpp, typeId);
01754 outputs_.push_back(std::pair<std::string,TypeContainer*>(tag,t));
01755 xpp->nextTag();
01756 delete sv;
01757 }
01758 else{
01759
01760 status_ = false;
01761 logger_<<"Unknown element "<<xpp->getName()<<std::endl;
01762 return;
01763 }
01764 } while (!(xpp->getName() == op_->getName()+"Response" &&
01765 xpp->getEventType() == XmlPullParser::END_TAG));
01766 }
01767 }
01768 else{
01769
01770 while (!(xpp->getName() == "Body" &&
01771 xpp->getNamespace() == soap_->getEnvelopeUri() &&
01772 xpp->getEventType() == XmlPullParser::END_TAG)) {
01773
01774 Qname elemName (xpp->getName ());
01775 elemName.setNamespace(xpp->getNamespace());
01776
01777
01778 const SchemaParser * sParser =
01779 wParser_->getSchemaParser(elemName.getNamespace());
01780 if (!sParser){
01781
01782 status_ = false;
01783 logger_<<"Unknown element "<<elemName<<std::endl;
01784 return;
01785 }
01786 SchemaValidator * sv= new SchemaValidator(sParser);
01787
01788 const Element * e = sParser->getElement (elemName);
01789 if(e){
01790 int typeId = e->getType () ;
01791 TypeContainer * t = sv->validate (xpp, typeId);
01792 std::pair<std::string,TypeContainer*> pr(elemName.getLocalName(),t);
01793 outputs_.push_back(pr);
01794 }
01795 else{
01796 status_ = false;
01797 std::cerr<<"Unknown element "<<elemName.getLocalName()<<std::endl;
01798 return;
01799 }
01800 delete sv;
01801 xpp->nextTag();
01802 }
01803 }
01804 status_ = true;
01805 }
01806
01807 void
01808 WsdlInvoker::processHeader(XmlPullParser *xpp)
01809 {
01810 Qname elem;
01811 const SchemaParser * sParser = 0;
01812 int type = Schema::XSD_INVALID;
01813 xpp->nextTag ();
01814 std::string tag = xpp->getName();
01815
01816 while (!(xpp->getEventType() == XmlPullParser::END_TAG &&
01817 xpp->getName() == "Header")){
01818
01819
01820
01821 if (xpp->getAttributeValue(Schema::SchemaInstaceUri, "type") != "" ) {
01822
01823 elem = Qname(xpp->getAttributeValue(Schema::SchemaInstaceUri, "type"));
01824 elem.setNamespace(xpp->getNamespace(elem.getPrefix()));
01825 sParser= wParser_->getSchemaParser(elem.getNamespace());
01826 type = (const_cast<SchemaParser*>(sParser))->getTypeId(elem);
01827 }
01828 else {
01829
01830 elem = Qname(xpp->getName());
01831 elem.setNamespace(xpp->getNamespace());
01832 sParser=wParser_->getSchemaParser(elem.getNamespace());
01833 const Element * e = sParser->getElement (elem);
01834 if(e){
01835 type = e->getType ();
01836 }
01837 }
01838 SchemaValidator * sv= new SchemaValidator(sParser);
01839 TypeContainer * t = sv->validate (xpp, type);
01840 outputs_.push_back(std::pair<std::string,TypeContainer*>(tag,t));
01841 oHeaders_++;
01842 xpp->nextTag();
01843 delete sv;
01844 }
01845 }
01846
01847 bool
01848 WsdlInvoker::isSoapArray (const ComplexType * ct,
01849 const SchemaParser * sParser)
01850 {
01851 const XSDType * baseType=sParser->getType(ct->getBaseTypeId());
01852 if (baseType) {
01853 if(baseType->getNamespace()==soap_->getEncodingUri() &&
01854 baseType->getName()=="Array")
01855 return true;
01856 }
01857 return false;
01858 }
01859
01860 void
01861 WsdlInvoker::setCredentials(const std::string & user, const std::string & pass)
01862 {
01863 username_ = user;
01864 password_ = pass;
01865 XmlUtils::setProxyUser(user);
01866 XmlUtils::setProxyPass(pass);
01867 XmlUtils::setProxy(true);
01868 }
01869
01870 void
01871 WsdlInvoker::setAuth(const std::string & user, const std::string & pass)
01872 {
01873 sAuthUser = user;
01874 sAuthPass = pass;
01875 bAuth = true;
01876 }
01877
01878 void
01879 WsdlInvoker::setProxy(const std::string & host,int port)
01880 {
01881 host_ = host;
01882 port_ = port;
01883 std::ostringstream oss;
01884 oss<<host<<":"<<port;
01885 XmlUtils::setProxyHost(oss.str());
01886 XmlUtils::setProxy(true);
01887 }
01888
01889 std::string
01890 WsdlInvoker::getPrefix(const std::string & nsp)
01891 {
01892
01893 unsigned int i = 0;
01894 char prefix='1';
01895 while (i<prefixes_.size()) {
01896 if (prefixes_[i] == nsp)
01897 break;
01898 i++;
01899 }
01900
01901 std::string tmp("ns");
01902 tmp.append(1,prefix+i);
01903 if (i == prefixes_.size())
01904 prefixes_.push_back(nsp);
01905
01906 return tmp;
01907
01908 }
01909
01910 }
01911
01912 #ifdef WITH_CURL
01913 size_t
01914 storeResults(void * buf,size_t sz,size_t nmemb,void* userdata)
01915 {
01916 char* sBuffer = (char*) buf;
01917 std::string* strCurlBuffer = (std::string*) userdata;
01918
01919 int result = 0;
01920 if (strCurlBuffer) {
01921 strCurlBuffer->append(sBuffer, sz * nmemb);
01922 result = sz * nmemb;
01923 }
01924
01925 return result;
01926 }
01927 #endif