groovy-wslite markupbuilder weired namespacing issue in soap-client

为君一笑 提交于 2019-12-11 13:15:08

问题


please help, i have a problem with the markupbuilder with groovy.

WORKING SOAP REQUEST against endpoint MYENDPOINT and the action MYACTION:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:SPECIAL">
   <soapenv:Header>
      <urn:xsdInfo>
         <urn:schemaLocation>SCHEMALOCATION</urn:schemaLocation>
      </urn:xsdInfo>
      <urn:category>Data Tables</urn:category>
      <urn:userInfo>
         <urn:sessionId>XXXXX</urn:sessionId>
      </urn:userInfo>
   </soapenv:Header>
   <soapenv:Body>
      <urn:add>
         <urn:DataTables urn:table_name="testtable">
            <!--Zero or more repetitions:-->
            <urn:each_record>
               <urn:s1>Somedinputdata</urn:s1>
            </urn:each_record>
         </urn:DataTables>
      </urn:add>
   </soapenv:Body>
</soapenv:Envelope>

Trying to replicate this with the makrup builder which is a closure within the wslite SOAP-Client object, does not work (regarding to namespacing issue i think:

 def bmClient = new SOAPClient('MYENDPOINT')
    def response = bmClient.send(SOAPAction:'MYACTION') {
        header{
              xsdInfo('xmlns':'urn:soap.bigmachines.com'){
                  schemaLocation('SCHEMALOCATION')
              }  
              category('Data Tables')
              userInfo(){
                  sessionId('XXXXX')
              }
        }
        body{
              add('xmlns':'urn:SPECIAL'){
              // PROBLEM IS HERE: should be urn:table_name but then it says urn is not defined as namespace..
                 DataTables('table_name':'testtable'){
                    each_record(){
                       s1('something')            
                    }
                 }
            }
        }
    }
    return response.addResponse.status.message.text()
}catch(e){
    println 'Problem in addToDataTable Session ID: '+e.printStackTrace()
 }
}

currently it says:

wslite.soap.SOAPFaultException: soapenv:INIT-ERR - The element category, is required in the header.

although there is a category specified... I am just stuck here, somebody knows how to create

<urn:DataTables urn:table_name="testtable">

within the markup closure properly?

I think this is the problem, because i have another webservice running quity pretty on the same logic, but there is no in it...

Would be great if someone could help with that, i am working the second day on it...


回答1:


If you want to match the structure exactly, you should define the urn namespace on the envelope using envelopeAttributes, and use it on the nested items like so:

def response = bmClient.send(SOAPAction:'MYACTION') {
    envelopeAttributes ('xmlns:urn' : 'urn:SPECIAL')   // watch out for brackets here!
    header{
          'urn:xsdInfo'{
              'urn:schemaLocation'('SCHEMALOCATION')
          }  
          'urn:category'('Data Tables')
          'urn:userInfo' {
              'urn:sessionId'('XXXXX')
          }
    }
    body{
          'urn:add' {
             'urn:DataTables'('urn:table_name':'testtable'){
                'urn:each_record'{
                   'urn:s1'('something')            
                }
             }
        }
    }
}


来源:https://stackoverflow.com/questions/16395975/groovy-wslite-markupbuilder-weired-namespacing-issue-in-soap-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!