From 5a3597669dbbd17c99d2d9cdb8edc1327ed24a7d Mon Sep 17 00:00:00 2001 From: konrad Date: Fri, 6 Aug 2010 21:55:44 +0000 Subject: [PATCH] generate full WSDL, to be tested git-svn-id: https://silmor.de/svn/softmagic/pack/trunk@586 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- woc/proc/processor.cpp | 16 ++++ woc/proc/processor.h | 18 ++++ woc/soap/schemaout.cpp | 1 + woc/soap/soapout.cpp | 206 ++++++++++++++++++++++++++++++++++------------- woc/soap/soapout.h | 16 ++++- woc/soap/wob-header.xsd | 4 + 6 files changed, 203 insertions(+), 58 deletions(-) diff --git a/woc/proc/processor.cpp b/woc/proc/processor.cpp index 4daa1da..cea51a7 100644 --- a/woc/proc/processor.cpp +++ b/woc/proc/processor.cpp @@ -58,6 +58,7 @@ WocProcessor::WocProcessor() m_error=false; m_projname="WobProject"; m_encmode=WobEncoding; + m_auth=UnknownAuth; parseNamespaces(); inst=this; @@ -139,6 +140,12 @@ bool WocProcessor::processFile(QString fn) if(enc=="soap"||enc=="soap12")m_encmode=Soap12Encoding; else m_encmode=WobEncoding; if(m_xmlNS=="")m_xmlNS="ns:"+QUrl::toPercentEncoding(m_projname); + m_auth=str2AuthMode(el.attribute("auth","none")); + if(m_auth==UnknownAuth){ + errorFound(); + qDebug("Error: unknown authentication mode %s", el.attribute("auth").toAscii().data()); + return false; + } }else if(tn=="Include"){ if(!processFile(m_baseDir+"/"+m_wobDir+"/"+el.attribute("file"))) @@ -376,6 +383,15 @@ void WocProcessor::parseNamespaces() m_xmlXmlNS=getXmlNamespace(":/xml.xsd"); } +WocProcessor::AuthMode WocProcessor::str2AuthMode(QString s) +{ + if(s=="none")return NoAuth; + if(s=="session")return SessionAuth; + if(s=="basic")return BasicAuth; + return UnknownAuth; +} + + /****************************************************************************** * WocOutput ******************************************************************************/ diff --git a/woc/proc/processor.h b/woc/proc/processor.h index ec35a91..0566d00 100644 --- a/woc/proc/processor.h +++ b/woc/proc/processor.h @@ -126,6 +126,20 @@ class WocProcessor:public QObject /**returns the message encoding mode*/ MessageEncoding messageEncoding()const{return m_encmode;} + /**describes the authentication mode of the project*/ + enum AuthMode { + /**no authentication*/ + NoAuth=0, + /**session ID authentication*/ + SessionAuth=1, + /**basic user/password authentication*/ + BasicAuth=2, + /** \private helper value: unknown authentication type, signifies an error condition*/ + UnknownAuth=-1 + }; + /**returns the authentication mode*/ + AuthMode authMode()const{return m_auth;} + /**returns whether a table exists*/ bool hasTable(QString)const; /**returns the requested table*/ @@ -164,6 +178,7 @@ class WocProcessor:public QObject QStringList m_docstrings; bool m_error,m_dbUpd; MessageEncoding m_encmode; + AuthMode m_auth; QList m_tables; QList m_classes; @@ -176,6 +191,9 @@ class WocProcessor:public QObject /**helper: looks up some schema files and finds the corresponding namespaces*/ void parseNamespaces(); + + /**helper: converts Project/auth attribute to enum*/ + AuthMode str2AuthMode(QString); }; diff --git a/woc/soap/schemaout.cpp b/woc/soap/schemaout.cpp index 6f37677..8706779 100644 --- a/woc/soap/schemaout.cpp +++ b/woc/soap/schemaout.cpp @@ -21,6 +21,7 @@ WocSchemaOut::WocSchemaOut(QString dname,QString fname): WocOutput() { m_dir=WocProcessor::instance()->baseDir()+"/"+dname; m_name=fname; + initialize(); } WocSchemaOut::WocSchemaOut(const QDomElement& el): WocOutput() diff --git a/woc/soap/soapout.cpp b/woc/soap/soapout.cpp index 1aa845d..47e446f 100644 --- a/woc/soap/soapout.cpp +++ b/woc/soap/soapout.cpp @@ -20,6 +20,7 @@ WocSoapOut::WocSoapOut(const QDomElement& el): WocOutput() { WocProcessor*woc=WocProcessor::instance(); + m_auth=woc->authMode(); //parse XML config m_name=el.attribute("fileprefix"); m_dir=woc->baseDir()+"/"+el.attribute("sourceDir"); @@ -35,20 +36,110 @@ WocSoapOut::WocSoapOut(const QDomElement& el): WocOutput() } //make sure directory exists QDir().mkpath(m_dir); + //create schema stuff + m_schema=new WocSchemaOut(el.attribute("sourceDir"),m_name+".xsd"); + m_schema->addStaticSchemas(m_name+"_all.xsd"); //create document and root node m_doc.appendChild(m_doc.createComment("Automatically generated WSDL file for project "+woc->projectName()+"\nDO NOT CHANGE THIS FILE DIRECTLY!")); - m_root=m_doc.createElementNS(woc->xmlSchemaNamespace(),"ws:wsdl"); + m_root=m_doc.createElementNS("http://schemas.xmlsoap.org/wsdl/","ws:definitions"); m_root.setAttribute("targetNamespace",woc->xmlProjectNamespace()); m_root.setAttribute("xmlns",woc->xmlProjectNamespace()); + m_root.setAttribute("xmlns:xs",woc->xmlSchemaNamespace()); + m_root.setAttribute("xmlns:soap","http://schemas.xmlsoap.org/wsdl/soap/"); m_root.setAttribute("elementFormDefault","qualified"); + + schemaImport(); + headerMsg(); + mainElems(); +} + +void WocSoapOut::schemaImport() +{ + WocProcessor*woc=WocProcessor::instance(); + QDomElement wt=m_doc.createElement("ws:types"); + QDomElement sm=m_doc.createElement("xs:schema"); + QDomElement si; + si=m_doc.createElement("xs:import"); + si.setAttribute("namespace",woc->xmlProjectNamespace()); + si.setAttribute("schemaLocation",m_name+".xsd"); + sm.appendChild(si); + if(m_auth!=WocProcessor::NoAuth){ + si=m_doc.createElement("xs:import"); + si.setAttribute("namespace",woc->xmlPackNamespace()+"/Header"); + si.setAttribute("schemaLocation","wob-header.xsd"); + sm.appendChild(si); + } + wt.appendChild(sm); + m_root.appendChild(wt); +} + +void WocSoapOut::headerMsg() +{ + //skip if not authenticated + if(m_auth==WocProcessor::NoAuth)return; + //create header + QDomElement msg=m_doc.createElement("ws:message"); + msg.setAttribute("name","Wob-Header"); + QDomElement prt=m_doc.createElement("ws:part"); + QString msgname=authMode2str(); + prt.setAttribute("name",msgname); + prt.setAttribute("element",msgname); + msg.appendChild(prt); + m_root.appendChild(msg); +} + +QString WocSoapOut::authMode2str() +{ + switch(m_auth){ + case WocProcessor::SessionAuth:return "SessionAuth";break; + case WocProcessor::BasicAuth:return "BasicAuth";break; + case WocProcessor::NoAuth:return "NoAuth";break; + default: + qDebug("Warning: oops. Unknown authentication mode in SoapOutput while generating header."); + return "NoAuth"; + break; + } } +void WocSoapOut::mainElems() +{ + //create portType + m_port=m_doc.createElement("ws:portType"); + m_port.setAttribute("name","ProjectPort"); + //create binding + m_bind=m_doc.createElement("ws:binding"); + m_bind.setAttribute("name","ProjectBinding"); + m_bind.setAttribute("type","ProjectPort"); + QDomElement el=m_doc.createElement("soap:binding"); + el.setAttribute("style","document"); + el.setAttribute("transport","http://schemas.xmlsoap.org/soap/http"); + m_bind.appendChild(el); +} + +void WocSoapOut::serviceTag() +{ + QDomElement svc=m_doc.createElement("ws:service"); + svc.setAttribute("name","ProjectService"); + QDomElement prt=m_doc.createElement("ws:port"); + prt.setAttribute("name","ProjectPort"); + prt.setAttribute("binding","ProjectBinding"); + QDomElement adr=m_doc.createElement("soap:address"); + adr.setAttribute("location","http://example.org"); + prt.appendChild(adr); + svc.appendChild(prt); + m_root.appendChild(svc); +} + + void WocSoapOut::finalize() { //finish off + m_root.appendChild(m_port); + m_root.appendChild(m_bind); + serviceTag(); m_doc.appendChild(m_root); //write - MFile fd(m_dir+"/"+m_name); + MFile fd(m_dir+"/"+m_name+".wsdl"); fd.open(QIODevice::WriteOnly); fd.write(m_doc.toByteArray()); } @@ -56,62 +147,63 @@ void WocSoapOut::finalize() void WocSoapOut::newTransaction(const WocTransaction& trn) { m_root.appendChild(m_doc.createComment("Transaction "+trn.name())); - //create elements - QDomElement tel=m_doc.createElement("xs:element"); - tel.setAttribute("name","WobRequest-"+trn.name()); - tel.setAttribute("type",trn.name()+"-Request"); - m_root.appendChild(tel); - tel=m_doc.createElement("xs:element"); - tel.setAttribute("name","WobResponse-"+trn.name()); - tel.setAttribute("type",trn.name()+"-Response"); - m_root.appendChild(tel); - - //create type: req - tel=m_doc.createElement("xs:complexType"); - tel.setAttribute("name",trn.name()+"-Request"); - QDomElement wel=m_doc.createElement("xs:sequence"); - tel.appendChild(wel); - QStringList vars=trn.inputNames(); - for(int i=0;ixmlProjectNamespace()+"/Transaction/"+trn.name()); + msg.appendChild(prt); + prt=m_doc.createElement("ws:input"); + prt.setAttribute("name","WobRequest-"+trn.name()); + if(m_auth!=WocProcessor::NoAuth && trn.authMode()!=WocTransaction::Open){ + el=m_doc.createElement("soap:header"); + el.setAttribute("message","Wob-Header"); + el.setAttribute("use","literal"); + el.setAttribute("required","true"); + el.setAttribute("part",authMode2str()); + prt.appendChild(el); } - m_root.appendChild(tel); + el=m_doc.createElement("soap:body"); + el.setAttribute("use","literal"); + prt.appendChild(el); + msg.appendChild(prt); + prt=m_doc.createElement("ws:output"); + prt.setAttribute("name","WobResponse-"+trn.name()); + el=m_doc.createElement("soap:body"); + el.setAttribute("use","literal"); + prt.appendChild(el); + msg.appendChild(prt); + m_bind.appendChild(msg); } void WocSoapOut::newClass(const WocClass& ) diff --git a/woc/soap/soapout.h b/woc/soap/soapout.h index 2018661..0ca420f 100644 --- a/woc/soap/soapout.h +++ b/woc/soap/soapout.h @@ -34,7 +34,21 @@ class WocSoapOut:public WocOutput private: QString m_name,m_dir; QDomDocument m_doc; - QDomElement m_root; + QDomElement m_root,m_bind,m_port; + WocSchemaOut*m_schema; + WocProcessor::AuthMode m_auth; + + /**creates schema imports*/ + void schemaImport(); + /**creates header message*/ + void headerMsg(); + /**create main elements for port and binding*/ + void mainElems(); + /**create service*/ + void serviceTag(); + + /**return name of header element for authentication mode*/ + QString authMode2str(); }; #endif diff --git a/woc/soap/wob-header.xsd b/woc/soap/wob-header.xsd index 77acf6f..95174db 100644 --- a/woc/soap/wob-header.xsd +++ b/woc/soap/wob-header.xsd @@ -16,4 +16,8 @@ + + + + \ No newline at end of file -- 1.7.2.5