wsdlpull 1.23
Loading...
Searching...
No Matches
Soap.cpp
Go to the documentation of this file.
1/*
2 * wsdlpull - A C++ parser for WSDL (Web services description language)
3 * Copyright (C) 2005-2007 Vivek Krishna
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 *
20 */
21
22#include <sstream>
23#include "wsdlparser/Soap.h"
24
25
26using namespace std;
27
28namespace WsdlPull {
29/*
30 TODO
31 1.When the use is "encoded" the part must reference the an
32 abstract type using the "type" attribute .
33 2.Only Soap encoding style is supported
34*/
35
36#include <iomanip>
37
38const std::string Soap::httpTransport = "http://schemas.xmlsoap.org/soap/http";
39const std::string Soap::httpBinding = "http://schemas.xmlsoap.org/wsdl/http/";
40const std::string Soap::soapEncUri11 = "http://schemas.xmlsoap.org/soap/encoding/";
41const std::string Soap::soapEnvUri11 = "http://schemas.xmlsoap.org/soap/envelope/";
42const std::string Soap::soapEncUri12 = "http://www.w3.org/2003/05/soap-encoding";
43const std::string Soap::soapEnvUri12 = "http://www.w3.org/2003/05/soap-envelope";
44const std::string Soap::soapBindingUri11 ="http://schemas.xmlsoap.org/wsdl/soap/";
45const std::string Soap::soapBindingUri12= "http://schemas.xmlsoap.org/wsdl/soap12/wsdl11soap12.xsd";
46
47
48Soap::Soap(const std::string & schemaPath, SoapVersion a_soapVersion)
49 :startId(0),
50 mySchemaParser(0),
51 mySchemaValidator(0),
52 wParser_(0),
53 idCounter(0),
54 schemaPath_(schemaPath),
55 soapVersion_(a_soapVersion)
56{
57 header_.clear();
58 body_.clear();
59 location_.clear();
60 ops_.clear();
61 idTable.clear();
62
63 if (a_soapVersion == SOAP12)
64 sNamespace = Soap::soapBindingUri12;
65 else
66 sNamespace = Soap::soapBindingUri11;
67}
68
69
71{
72 if (mySchemaParser)
73 delete mySchemaParser;
74 if (mySchemaValidator)
75 delete mySchemaValidator;
76}
77
78std::string
80{
81
82
84 return sNamespace;
85 }
86
87 string path=schemaPath_;
88 path+="soap.xsd";
89 return path;
90}
91
92std::string
94{
95
97
98 switch(getSoapVersion()) {
99
100 case SOAP12:
101 return soapEncUri12;
102 break;
103
104 case SOAP11:
105 default:
106 return soapEncUri11;
107 break;
108 }
109 }
110
111 string path=schemaPath_;
112 path+="soap-encoding.xsd";
113 return path;
114}
115
116std::string
118{
119 switch(getSoapVersion()) {
120 case SOAP12:
121 return soapEncUri12;
122 break;
123
124 case SOAP11:
125 default:
126 return soapEncUri11;
127 break;
128 }
129}
130
131std::string
133{
134 switch(getSoapVersion()) {
135 case SOAP12:
136 return soapEnvUri12;
137 break;
138
139 case SOAP11:
140 default:
141 return soapEnvUri11;
142 break;
143 }
144}
145
146int
147Soap::handleElement(int parent, XmlPullParser * xParser)
148{
149 if (mySchemaParser == 0) {
150 error("Could not parse soap extensibility elements");
151 return 0;
152 }
153 string elemName = xParser->getName();
154 int elemId = 0;
155 Qname q(elemName);
156 const Element* e= mySchemaParser->getElement(q);
157 if (e == 0) {
158
159 error("Unknown element");
160 return 0;
161 }
162 TypeContainer * t = new TypeContainer(e->getType(), mySchemaParser);
163
164 try{
165
166 mySchemaValidator->validate(xParser,e->getType(), t);
167 }
168 catch (SchemaParserException spe) {
169
170 error(spe.description + "Encountered error while validating {"+sNamespace +"}:"+elemName);
171 }
172 if (elemName == "binding")
173 elemId = processBinding(t);
174
175 else if (elemName == "operation")
176 elemId = processOp(parent, t);
177
178 else if (elemName == "body")
179 elemId = processBody(parent, t);
180
181 else if (elemName == "header")
182 elemId = processHeader(parent, t);
183
184 else if (elemName == "fault")
185 elemId = processFault(parent, t);
186
187 else if (elemName == "address")
188 elemId = processAddress(parent, t);
189
190 delete t;
191 return elemId;
192}
193
194
195int
196Soap::handleAttribute(int parent, string att,
197 XmlPullParser * xParser)
198{
199 return 0;
200}
201
202
203int Soap::processBinding(TypeContainer * t)
204{
205 TypeContainer * temp = 0;
206 if ((temp = t->getAttributeContainer("transport")) != 0)
207 {
208 string tp = *((string *) (temp->getValue()));
209 if (tp == httpTransport)
210 transport_ = HTTP;
211
212 else
213 transport_ = NONE;
214 }
215
216 else
217 transport_ = HTTP;
218
219 /*
220 * Assume default transport as HTTP
221 */
222 if ((temp = t->getAttributeContainer("style")) != 0)
223 {
224 string style = *((string *) (temp->getValue()));
225 if (style == "rpc")
226 style_ = RPC;
227
228 else
229 style_ = DOC;
230 }
231
232 else
233 style_ = DOC;
234 Qname binding("binding");
235 IDTableIndex idi;
236 idi.typeId=(mySchemaParser->getElement(binding))->getType();
237 idi.index=0;
238 idTable.push_back(idi);
239 idCounter++;
240 return startId + idCounter - 1;
241}
242
243
244int
245Soap::processOp(int parent, TypeContainer * t)
246{
247 TypeContainer * temp = 0;
248 SoapOperationBinding sopb;
249
250 if ((temp = t->getAttributeContainer("soapAction")) != 0)
251 {
252 string * s = (string *) (temp->getValue());
253 if(s)
254 sopb.soapAction = *s;
255 }
256
257 if ((temp = t->getAttributeContainer("style")) != 0)
258 {
259 string style = *((string *) (temp->getValue()));
260 if (style == "rpc")
261 sopb.style = RPC;
262
263 else
264 sopb.style = DOC;
265 }
266 else //Use the binding element's style attribute
267 sopb.style = style_;
268 sopb.wsdlOpId = parent;
269
270 ops_.push_back(sopb);
271
272 Qname oprn("operation");
273 IDTableIndex idi;
274 idi.typeId=(mySchemaParser->getElement(oprn))->getType();
275 idi.index=ops_.size()-1;
276 idTable.push_back(idi);
277 idCounter++;
278 return startId + idCounter - 1;
279}
280
281
282int
283Soap::processBody(int parent, TypeContainer * t)
284{
285 TypeContainer * temp = 0;
286 string use;
287 SoapMessageBinding smb;
288
289 if ((temp = t->getAttributeContainer("use")) != 0)
290 {
291 use = *((string *) (temp->getValue()));
292 if (use == "literal")
293 smb.use = LITERAL;
294 else
295 smb.use = ENCODED;
296 }
297 else
298 smb.use = LITERAL;
299
300 if ((temp = t->getAttributeContainer("namespace")) != 0)
301 {
302 string * s = (string *) (temp->getValue());
303 smb.urn = *s;
304 }
305 else{
306
307 smb.urn="";
308 }
309
310 if ((temp = t->getAttributeContainer("encodingStyle")) != 0)
311 {
312 string * s = (string *) (temp->getValue());
313 smb.encodingStyle = *s;
314 }
315 else{
316
317 smb.encodingStyle="";
318 }
319
320 body_.push_back(smb);
321
322 Qname body("body");
323 IDTableIndex idi;
324 idi.typeId=(mySchemaParser->getElement(body))->getType();
325 idi.index=body_.size()-1;
326 idTable.push_back(idi);
327 idCounter++;
328 return startId + idCounter - 1;
329}
330
331
332int
333Soap::processFault(int parent, TypeContainer *)
334{
335 //TODO
336 return startId + idCounter - 1;
337}
338
339
340int
341Soap::processAddress(int parent, TypeContainer * t)
342{
343 TypeContainer * temp = 0;
344 string location;
345
346 if ((temp = t->getAttributeContainer("location")) != 0)
347 {
348 string * s = (string *) (temp->getValue());
349 if(s)
350 location_.push_back(*s);
351 }
352 Qname address("address");
353
354 IDTableIndex idi;
355 idi.typeId=(mySchemaParser->getElement(address))->getType();
356 idi.index=location_.size()-1;
357 idTable.push_back(idi);
358 idCounter++;
359 return startId + idCounter - 1;
360}
361
362
363int
364Soap::processHeader(int parent, TypeContainer * t)
365{
366 TypeContainer * temp = 0;
367 Qname msg;
368 std::string ns, part;
369 Qname header("header");
370 int partType;
371 SoapHeaderBinding shb;
372 if ((temp = t->getAttributeContainer("message")) != 0) {
373
374 msg = *((Qname *) (temp->getValue()));
375 }
376 if ((temp = t->getAttributeContainer("namespace")) != 0) {
377
378 ns = *((string *) (temp->getValue()));
379 }
380 const Message *m = wParser_->getMessage(msg);
381 if (m == 0) {
382 error("Unkown message " + msg.getLocalName());
383 return 0;
384 }
385 if ((temp = t->getAttributeContainer("parts")) != 0) {
386
387 part = *((string *) (temp->getValue())); //this is actually NMTOKENS
388 //Multiple parts not supported
389 }
390 else if ((temp = t->getAttributeContainer("part")) != 0) {
391 //some wsdls use 'part' instead of 'parts'
392 part = *((string *) (temp->getValue()));
393 }
394 partType = m->getPartType(part);
395
396 if (partType == 0)
397 error("Unkown part type :"+ part);
398
399 shb.partId_= m->getPartIndex(part);
400 shb.message_ = m;
401 shb.urn = ns;
402 header_.push_back(shb);
403
404 IDTableIndex idi;
405 idi.typeId=(mySchemaParser->getElement(header))->getType();
406 idi.index=header_.size()-1;
407 idTable.push_back(idi);
408
409 idCounter++;
410 return startId + idCounter - 1;
411}
412
413
414void
415Soap::getSoapOperationInfo(int elemId, string & action, Soap::Style &style)
416{
417 if (elemId - startId >= idCounter ||
418 elemId < startId ) //invalid elem Id
419 return;
420 int opId = idTable[elemId - startId].index;
421 action = ops_[opId].soapAction;
422 style = ops_[opId].style;
423}
424
425void
426Soap::getSoapBodyInfo(int elemId, string &ns, Soap::Encoding &use, std::string &encodingStyle)
427{
428 if (elemId - startId >= idCounter ||
429 elemId < startId ) //invalid elem Id
430 return;
431 int bodyId = idTable[elemId - startId].index;
432 ns = body_[bodyId].urn;
433 use = body_[bodyId].use;
434 encodingStyle = body_[bodyId].encodingStyle;
435}
436
437void
438Soap::getSoapHeaderInfo(int elemId, string &ns, int &partId, const Message* & m)
439{
440 if (elemId - startId >= idCounter ||
441 elemId < startId ) //invalid elem Id
442 return;
443 int headerId = idTable[elemId - startId].index;
444 ns = header_[headerId].urn;
445 partId = header_[headerId].partId_;
446 m = header_[headerId].message_;
447}
448
449bool
450Soap::getServiceLocation(int elemId, std::string &location)
451{
452 if (elemId - startId >= idCounter ||
453 elemId < startId ) //invalid elem Id
454 return false;
455 int locId = idTable[elemId - startId].index;
456 location = location_[locId];
457 if(!location.empty())
458 return true;
459 else
460 return false;
461}
462
463bool
465{
466 Qname body("body");
467 if (elemId - startId >= idCounter||
468 elemId < startId )//invalid elem Id
469
470 return false;
471
472 if (idTable[elemId - startId].typeId ==
473 (mySchemaParser->getElement(body))->getType())
474 return true;
475 else
476 return false;
477}
478
479
480bool
482{
483 Qname header("header");
484 if (elemId - startId >= idCounter||
485 elemId < startId )//invalid elem Id
486 return false;
487 if (idTable[elemId - startId].typeId ==
488 (mySchemaParser->getElement(header))->getType())
489 return true;
490
491 else
492 return false;
493}
494
495
496void
497Soap::error(std::string s)
498{
499 wParser_->logger()<< "Soap Processing" << XmlUtils::dbsp << s << endl;
500}
501
502void
503Soap::setSchemaPath(const std::string & schemaPath)
504{
505 schemaPath_ = schemaPath;
506}
507
508}
Definition Qname.h:31
int getType() const
Definition Element.h:147
const Element * getElement(const Qname &element, bool checkImports=true) const
TypeContainer * validate(XmlPullParser *xpp, int typeId, TypeContainer *ipTc=0)
bool getServiceLocation(int elemId, std::string &location)
Definition Soap.cpp:450
void getSoapOperationInfo(int elemId, std::string &soapAction, Soap::Style &style)
Definition Soap.cpp:415
std::string getEncodingUri(void) const
Definition Soap.cpp:117
void getSoapBodyInfo(int elemId, std::string &ns, Soap::Encoding &use, std::string &encodingStyle)
Definition Soap.cpp:426
void getSoapHeaderInfo(int elemId, std::string &ns, int &partId, const Message *&m)
Definition Soap.cpp:438
bool isSoapHeader(int id)
Definition Soap.cpp:481
static const std::string soapEncUri12
Definition Soap.h:46
static const std::string soapBindingUri11
Definition Soap.h:48
static const std::string soapEncUri11
Definition Soap.h:44
int handleElement(int parent, XmlPullParser *)
Definition Soap.cpp:147
std::string getEnvelopeUri(void) const
Definition Soap.cpp:132
std::string getEncodingSchema(void) const
Definition Soap.cpp:93
Soap(const std::string &schemaPath="", SoapVersion a_soapVersion=SOAP11)
Definition Soap.cpp:48
int handleAttribute(int parent, std::string attName, XmlPullParser *)
Definition Soap.cpp:196
void setSchemaPath(const std::string &schemaPath)
Definition Soap.cpp:503
virtual ~Soap()
Definition Soap.cpp:70
static const std::string httpTransport
Definition Soap.h:42
bool isSoapBody(int id)
Definition Soap.cpp:464
std::string getExtensibilitySchema(void) const
Definition Soap.cpp:79
static const std::string soapBindingUri12
Definition Soap.h:49
static const std::string httpBinding
Definition Soap.h:43
SoapVersion getSoapVersion() const
Definition Soap.h:124
static const std::string soapEnvUri12
Definition Soap.h:47
static const std::string soapEnvUri11
Definition Soap.h:45
static bool useLocalSchema_
Definition WsdlParser.h:259
std::ostream & logger()
Definition WsdlParser.h:496
const Message * getMessage()
std::ostream & dbsp(std::ostream &str)
Definition XmlUtils.cpp:90