00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <sstream>
00023 #include "wsdlparser/Soap.h"
00024
00025
00026 using namespace std;
00027
00028 namespace WsdlPull {
00029
00030
00031
00032
00033
00034
00035
00036 #include <iomanip>
00037
00038 const std::string Soap::httpTransport = "http://schemas.xmlsoap.org/soap/http";
00039 const std::string Soap::httpBinding = "http://schemas.xmlsoap.org/wsdl/http/";
00040 const std::string Soap::soapEncUri11 = "http://schemas.xmlsoap.org/soap/encoding/";
00041 const std::string Soap::soapEnvUri11 = "http://schemas.xmlsoap.org/soap/envelope/";
00042 const std::string Soap::soapEncUri12 = "http://www.w3.org/2003/05/soap-encoding";
00043 const std::string Soap::soapEnvUri12 = "http://www.w3.org/2003/05/soap-envelope";
00044 const std::string Soap::soapBindingUri11 ="http://schemas.xmlsoap.org/wsdl/soap/";
00045 const std::string Soap::soapBindingUri12= "http://schemas.xmlsoap.org/wsdl/soap12/";
00046
00047 Soap::Soap(const std::string & schemaPath, SoapVersion a_soapVersion)
00048 :startId(0),
00049 mySchemaParser(0),
00050 mySchemaValidator(0),
00051 wParser_(0),
00052 idCounter(0),
00053 schemaPath_(schemaPath),
00054 soapVersion_(a_soapVersion)
00055 {
00056 header_.clear();
00057 body_.clear();
00058 location_.clear();
00059 ops_.clear();
00060 idTable.clear();
00061
00062 if (a_soapVersion == SOAP12)
00063 sNamespace = Soap::soapBindingUri12;
00064 else
00065 sNamespace = Soap::soapBindingUri11;
00066 }
00067
00068
00069 Soap::~Soap()
00070 {
00071 if (mySchemaParser)
00072 delete mySchemaParser;
00073 if (mySchemaValidator)
00074 delete mySchemaValidator;
00075 }
00076
00077 std::string
00078 Soap::getExtensibilitySchema(void)const
00079 {
00080
00081
00082 if (WsdlPull::WsdlParser::useLocalSchema_ == false) {
00083 return sNamespace;
00084 }
00085
00086 string path=schemaPath_;
00087 path+="soap.xsd";
00088 return path;
00089 }
00090
00091 std::string
00092 Soap::getEncodingSchema(void)const
00093 {
00094
00095 if (WsdlPull::WsdlParser::useLocalSchema_ == false) {
00096
00097 switch(getSoapVersion()) {
00098
00099 case SOAP12:
00100 return soapEncUri12;
00101 break;
00102
00103 case SOAP11:
00104 default:
00105 return soapEncUri11;
00106 break;
00107 }
00108 }
00109
00110 string path=schemaPath_;
00111 path+="soap-encoding.xsd";
00112 return path;
00113 }
00114
00115 std::string
00116 Soap::getEncodingUri(void)const
00117 {
00118 switch(getSoapVersion()) {
00119 case SOAP12:
00120 return soapEncUri12;
00121 break;
00122
00123 case SOAP11:
00124 default:
00125 return soapEncUri11;
00126 break;
00127 }
00128 }
00129
00130 std::string
00131 Soap::getEnvelopeUri(void)const
00132 {
00133 switch(getSoapVersion()) {
00134 case SOAP12:
00135 return soapEnvUri12;
00136 break;
00137
00138 case SOAP11:
00139 default:
00140 return soapEnvUri11;
00141 break;
00142 }
00143 }
00144
00145 int
00146 Soap::handleElement(int parent, XmlPullParser * xParser)
00147 {
00148 if (mySchemaParser == 0) {
00149 error("Could not parse soap extensibility elements");
00150 return 0;
00151 }
00152 string elemName = xParser->getName();
00153 int elemId = 0;
00154 Qname q(elemName);
00155 const Element* e= mySchemaParser->getElement(q);
00156 if (e == 0) {
00157
00158 error("Unknown element");
00159 return 0;
00160 }
00161 TypeContainer * t = new TypeContainer(e->getType(), mySchemaParser);
00162
00163 try{
00164
00165 mySchemaValidator->validate(xParser,e->getType(), t);
00166 }
00167 catch (SchemaParserException spe) {
00168
00169 error(spe.description + "Encountered error while validating {"+sNamespace +"}:"+elemName);
00170 }
00171 if (elemName == "binding")
00172 elemId = processBinding(t);
00173
00174 else if (elemName == "operation")
00175 elemId = processOp(parent, t);
00176
00177 else if (elemName == "body")
00178 elemId = processBody(parent, t);
00179
00180 else if (elemName == "header")
00181 elemId = processHeader(parent, t);
00182
00183 else if (elemName == "fault")
00184 elemId = processFault(parent, t);
00185
00186 else if (elemName == "address")
00187 elemId = processAddress(parent, t);
00188 delete t;
00189 return elemId;
00190 }
00191
00192
00193 int
00194 Soap::handleAttribute(int parent, string att,
00195 XmlPullParser * xParser)
00196 {
00197 return 0;
00198 }
00199
00200
00201 int Soap::processBinding(TypeContainer * t)
00202 {
00203 TypeContainer * temp = 0;
00204 if ((temp = t->getAttributeContainer("transport")) != 0)
00205 {
00206 string tp = *((string *) (temp->getValue()));
00207 if (tp == httpTransport)
00208 transport_ = HTTP;
00209
00210 else
00211 transport_ = NONE;
00212 }
00213
00214 else
00215 transport_ = HTTP;
00216
00217
00218
00219
00220 if ((temp = t->getAttributeContainer("style")) != 0)
00221 {
00222 string style = *((string *) (temp->getValue()));
00223 if (style == "rpc")
00224 style_ = RPC;
00225
00226 else
00227 style_ = DOC;
00228 }
00229
00230 else
00231 style_ = DOC;
00232 Qname binding("binding");
00233 IDTableIndex idi;
00234 idi.typeId=(mySchemaParser->getElement(binding))->getType();
00235 idi.index=0;
00236 idTable.push_back(idi);
00237 idCounter++;
00238 return startId + idCounter - 1;
00239 }
00240
00241
00242 int
00243 Soap::processOp(int parent, TypeContainer * t)
00244 {
00245 TypeContainer * temp = 0;
00246 SoapOperationBinding sopb;
00247
00248 if ((temp = t->getAttributeContainer("soapAction")) != 0)
00249 {
00250 string * s = (string *) (temp->getValue());
00251 if(s)
00252 sopb.soapAction = *s;
00253 }
00254
00255 if ((temp = t->getAttributeContainer("style")) != 0)
00256 {
00257 string style = *((string *) (temp->getValue()));
00258 if (style == "rpc")
00259 sopb.style = RPC;
00260
00261 else
00262 sopb.style = DOC;
00263 }
00264 else
00265 sopb.style = style_;
00266 sopb.wsdlOpId = parent;
00267
00268 ops_.push_back(sopb);
00269
00270 Qname oprn("operation");
00271 IDTableIndex idi;
00272 idi.typeId=(mySchemaParser->getElement(oprn))->getType();
00273 idi.index=ops_.size()-1;
00274 idTable.push_back(idi);
00275 idCounter++;
00276 return startId + idCounter - 1;
00277 }
00278
00279
00280 int
00281 Soap::processBody(int parent, TypeContainer * t)
00282 {
00283 TypeContainer * temp = 0;
00284 string use;
00285 SoapMessageBinding smb;
00286
00287 if ((temp = t->getAttributeContainer("use")) != 0)
00288 {
00289 use = *((string *) (temp->getValue()));
00290 if (use == "literal")
00291 smb.use = LITERAL;
00292 else
00293 smb.use = ENCODED;
00294 }
00295 else
00296 smb.use = LITERAL;
00297
00298 if ((temp = t->getAttributeContainer("namespace")) != 0)
00299 {
00300 string * s = (string *) (temp->getValue());
00301 smb.urn = *s;
00302 }
00303 else{
00304
00305 smb.urn="";
00306 }
00307
00308 if ((temp = t->getAttributeContainer("encodingStyle")) != 0)
00309 {
00310 string * s = (string *) (temp->getValue());
00311 smb.encodingStyle = *s;
00312 }
00313 else{
00314
00315 smb.encodingStyle="";
00316 }
00317
00318 body_.push_back(smb);
00319
00320 Qname body("body");
00321 IDTableIndex idi;
00322 idi.typeId=(mySchemaParser->getElement(body))->getType();
00323 idi.index=body_.size()-1;
00324 idTable.push_back(idi);
00325 idCounter++;
00326 return startId + idCounter - 1;
00327 }
00328
00329
00330 int
00331 Soap::processFault(int parent, TypeContainer *)
00332 {
00333
00334 return startId + idCounter - 1;
00335 }
00336
00337
00338 int
00339 Soap::processAddress(int parent, TypeContainer * t)
00340 {
00341 TypeContainer * temp = 0;
00342 string location;
00343
00344 if ((temp = t->getAttributeContainer("location")) != 0)
00345 {
00346 string * s = (string *) (temp->getValue());
00347 if(s)
00348 location_.push_back(*s);
00349 }
00350 Qname address("address");
00351
00352 IDTableIndex idi;
00353 idi.typeId=(mySchemaParser->getElement(address))->getType();
00354 idi.index=location_.size()-1;
00355 idTable.push_back(idi);
00356 idCounter++;
00357 return startId + idCounter - 1;
00358 }
00359
00360
00361 int
00362 Soap::processHeader(int parent, TypeContainer * t)
00363 {
00364 TypeContainer * temp = 0;
00365 Qname msg;
00366 std::string ns, part;
00367 Qname header("header");
00368 int partType;
00369 SoapHeaderBinding shb;
00370 if ((temp = t->getAttributeContainer("message")) != 0) {
00371
00372 msg = *((Qname *) (temp->getValue()));
00373 }
00374 if ((temp = t->getAttributeContainer("namespace")) != 0) {
00375
00376 ns = *((string *) (temp->getValue()));
00377 }
00378 const Message *m = wParser_->getMessage(msg);
00379 if (m == 0) {
00380 error("Unkown message " + msg.getLocalName());
00381 return 0;
00382 }
00383 if ((temp = t->getAttributeContainer("parts")) != 0) {
00384
00385 part = *((string *) (temp->getValue()));
00386
00387 }
00388 else if ((temp = t->getAttributeContainer("part")) != 0) {
00389
00390 part = *((string *) (temp->getValue()));
00391 }
00392 partType = m->getPartType(part);
00393
00394 if (partType == 0)
00395 error("Unkown part type :"+ part);
00396
00397 shb.partId_= m->getPartIndex(part);
00398 shb.message_ = m;
00399 shb.urn = ns;
00400 header_.push_back(shb);
00401
00402 IDTableIndex idi;
00403 idi.typeId=(mySchemaParser->getElement(header))->getType();
00404 idi.index=header_.size()-1;
00405 idTable.push_back(idi);
00406
00407 idCounter++;
00408 return startId + idCounter - 1;
00409 }
00410
00411
00412 void
00413 Soap::getSoapOperationInfo(int elemId, string & action, Soap::Style &style)
00414 {
00415 if (elemId - startId >= idCounter ||
00416 elemId < startId )
00417 return;
00418 int opId = idTable[elemId - startId].index;
00419 action = ops_[opId].soapAction;
00420 style = ops_[opId].style;
00421 }
00422
00423 void
00424 Soap::getSoapBodyInfo(int elemId, string &ns, Soap::Encoding &use, std::string &encodingStyle)
00425 {
00426 if (elemId - startId >= idCounter ||
00427 elemId < startId )
00428 return;
00429 int bodyId = idTable[elemId - startId].index;
00430 ns = body_[bodyId].urn;
00431 use = body_[bodyId].use;
00432 encodingStyle = body_[bodyId].encodingStyle;
00433 }
00434
00435 void
00436 Soap::getSoapHeaderInfo(int elemId, string &ns, int &partId, const Message* & m)
00437 {
00438 if (elemId - startId >= idCounter ||
00439 elemId < startId )
00440 return;
00441 int headerId = idTable[elemId - startId].index;
00442 ns = header_[headerId].urn;
00443 partId = header_[headerId].partId_;
00444 m = header_[headerId].message_;
00445 }
00446
00447 bool
00448 Soap::getServiceLocation(int elemId, std::string &location)
00449 {
00450 if (elemId - startId >= idCounter ||
00451 elemId < startId )
00452 return false;
00453 int locId = idTable[elemId - startId].index;
00454 location = location_[locId];
00455 if(!location.empty())
00456 return true;
00457 else
00458 return false;
00459 }
00460
00461 bool
00462 Soap::isSoapBody(int elemId)
00463 {
00464 Qname body("body");
00465 if (elemId - startId >= idCounter||
00466 elemId < startId )
00467
00468 return false;
00469
00470 if (idTable[elemId - startId].typeId ==
00471 (mySchemaParser->getElement(body))->getType())
00472 return true;
00473 else
00474 return false;
00475 }
00476
00477
00478 bool
00479 Soap::isSoapHeader(int elemId)
00480 {
00481 Qname header("header");
00482 if (elemId - startId >= idCounter||
00483 elemId < startId )
00484 return false;
00485 if (idTable[elemId - startId].typeId ==
00486 (mySchemaParser->getElement(header))->getType())
00487 return true;
00488
00489 else
00490 return false;
00491 }
00492
00493
00494 void
00495 Soap::error(std::string s)
00496 {
00497 wParser_->logger()<< "Soap Processing" << XmlUtils::dbsp << s << endl;
00498 }
00499
00500 void
00501 Soap::setSchemaPath(const std::string & schemaPath)
00502 {
00503 schemaPath_ = schemaPath;
00504 }
00505
00506 }