XMLA/SOAP command from a bash shell

孤人 提交于 2019-12-04 05:16:19

问题


I need to call the management API from icCube from withing a bash shell. What is the easiest way for sending a SOAP command like :

    <?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
     <soap:Body>
       <Execute xmlns="urn:schemas-microsoft-com:xml-analysis">
         <Command>
           <Statement xsi:type="xsd:string">'"$command"'</Statement>
         </Command>
       </Execute>
     </soap:Body>
    </soap:Envelope>

On top, how to handle Basic Authentication ( user / pwd ) ?


回答1:


Perl sample available in documentation : http://www.iccube.com/support/documentation/user_guide/using/cube_management.php (in the end of document).

Curl basic auth handled using '--user' argument

Bash sample:

  #!/bin/bash

  URL="http://localhost:8282/icCube/xmla"
  COMMAND="LIST_SCHEMA"

  echo ${COMMAND}

  curl --header "Content-Type: text/xml;charset=UTF-8" \
  --header "SOAPAction:urn:schemas-microsoft-com:xml-analysis#Execute" \
  --user admin:admin --data @- ${URL} <<EOF
  <?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
    <Execute xmlns="urn:schemas-microsoft-com:xml-analysis">
      <Command>
          <Statement xsi:type="xsd:string">${COMMAND}</Statement>
      </Command>
    </Execute>
      </soap:Body>
  </soap:Envelope>
  EOF

Note: Make sure there isn't any whitespace after the closing EOF or the API will return a SOAP syntax error.



来源:https://stackoverflow.com/questions/33165435/xmla-soap-command-from-a-bash-shell

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