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