generate full WSDL, to be tested
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 6 Aug 2010 21:55:44 +0000 (21:55 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 6 Aug 2010 21:55:44 +0000 (21:55 +0000)
git-svn-id: https://silmor.de/svn/softmagic/pack/trunk@586 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

woc/proc/processor.cpp
woc/proc/processor.h
woc/soap/schemaout.cpp
woc/soap/soapout.cpp
woc/soap/soapout.h
woc/soap/wob-header.xsd

index 4daa1da..cea51a7 100644 (file)
@@ -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
  ******************************************************************************/
index ec35a91..0566d00 100644 (file)
@@ -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<WocTable> m_tables;
                QList<WocClass> 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);
 };
 
 
index 6f37677..8706779 100644 (file)
@@ -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()
index 1aa845d..47e446f 100644 (file)
@@ -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;i<vars.size();i++){
-               QString tp=trn.inputType(vars[i]);
-               if(trn.isAttributeType(tp)){
-                       QDomElement at=m_doc.createElement("xs:attribute");
-                       at.setAttribute("name",vars[i]);
-                       at.setAttribute("use","optional");
-                       tel.appendChild(at);
-               }else{
-                       QDomElement el=m_doc.createElement("xs:element");
-                       el.setAttribute("name",vars[i]);
-                       el.setAttribute("minOccurs","0");
-                       if(trn.isListType(tp))
-                               el.setAttribute("maxOccurs","unbounded");
-                       wel.appendChild(el);
-               }
-       }
-       m_root.appendChild(tel);
-       //create type: rsp
-       tel=m_doc.createElement("xs:complexType");
-       tel.setAttribute("name",trn.name()+"-Response");
-       wel=m_doc.createElement("xs:sequence");
-       tel.appendChild(wel);
-       vars=trn.outputNames();
-       for(int i=0;i<vars.size();i++){
-               QString tp=trn.outputType(vars[i]);
-               if(trn.isAttributeType(tp)){
-                       QDomElement at=m_doc.createElement("xs:attribute");
-                       at.setAttribute("name",vars[i]);
-                       at.setAttribute("use","optional");
-                       tel.appendChild(at);
-               }else{
-                       QDomElement el=m_doc.createElement("xs:element");
-                       el.setAttribute("name",vars[i]);
-                       el.setAttribute("minOccurs","0");
-                       if(trn.isListType(tp))
-                               el.setAttribute("maxOccurs","unbounded");
-                       wel.appendChild(el);
-               }
+       WocProcessor *woc=WocProcessor::instance();
+       //create messages
+       QDomElement msg,prt,el;
+       msg=m_doc.createElement("ws:message");
+       msg.setAttribute("name","WobRequest-"+trn.name());
+       prt=m_doc.createElement("ws:part");
+       prt.setAttribute("name","WobRequest-"+trn.name());
+       prt.setAttribute("type","WobRequest-"+trn.name());
+       msg.appendChild(prt);
+       m_root.appendChild(msg);
+       msg=m_doc.createElement("ws:message");
+       msg.setAttribute("name","WobResponse-"+trn.name());
+       prt=m_doc.createElement("ws:part");
+       prt.setAttribute("name","WobResponse-"+trn.name());
+       prt.setAttribute("type","WobResponse-"+trn.name());
+       msg.appendChild(prt);
+       m_root.appendChild(msg);
+       //create port
+       msg=m_doc.createElement("ws:operation");
+       msg.setAttribute("name",trn.name());
+       prt=m_doc.createElement("ws:input");
+       prt.setAttribute("name","WobRequest-"+trn.name());
+       prt.setAttribute("message","WobRequest-"+trn.name());
+       msg.appendChild(prt);
+       prt=m_doc.createElement("ws:output");
+       prt.setAttribute("name","WobResponse-"+trn.name());
+       prt.setAttribute("message","WobResponse-"+trn.name());
+       msg.appendChild(prt);
+       m_port.appendChild(msg);
+       //create binding
+       msg=m_doc.createElement("ws:operation");
+       msg.setAttribute("name",trn.name());
+       prt=m_doc.createElement("soap:operation");
+       prt.setAttribute("style","document");
+       prt.setAttribute("soapAction",woc->xmlProjectNamespace()+"/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& )
index 2018661..0ca420f 100644 (file)
@@ -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
index 77acf6f..95174db 100644 (file)
@@ -16,4 +16,8 @@
     <xs:attribute name="username" type="xs:string"/>
     <xs:attribute name="password" type="xs:string"/>
   </xs:complexType>
+  
+  <!-- fake header for no authentication -->
+  <xs:element name="NoAuth" type="NoAuth" />
+  <xs:complexType name="NoAuth" />
 </xs:schema>
\ No newline at end of file