<?vsp 
--  
--  $Id$
--  
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--  
--  Copyright (C) 1998-2024 OpenLink Software
--  
--  This project is free software; you can redistribute it and/or modify it
--  under the terms of the GNU General Public License as published by the
--  Free Software Foundation; only version 2 of the License, dated June 1991.
--  
--  This program is distributed in the hope that it will be useful, but
--  WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
--  General Public License for more details.
--  
--  You should have received a copy of the GNU General Public License along
--  with this program; if not, write to the Free Software Foundation, Inc.,
--  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--  
--  

  declare resp, inp, outp varchar;
  declare url varchar;
  declare op, err, wf varchar;

  declare _host varchar;
  _host := 'htp://' || http_request_header(lines, 'Host', null, 'localhost:' || server_http_port());
  url := get_keyword ('url' , params, _host || '/r4/groupH/simple/doc');

  op := {?'op'}; resp := null; err := '';

  declare exit handler for sqlstate '*' {
    err := __SQL_MESSAGE;
    goto err;
  };

  if (isstring (op)) op := atoi (op);
  if (isstring ({?'wf'})) wf := atoi ({?'wf'});

  if (op = 1)
    {
      resp :=
	soap_client (url=>url, operation=>'echoEmptyFault',
	    parameters=>vector(vector ('echoEmptyFault', 'http://soapinterop.org/types/requestresponse:echoEmptyFaultRequest'), vector()),
	    style=>3,
	    soap_action=>'""',
	    target_namespace=>'http://soapinterop.org/wsdl'
	    );
    }
  else
    if (op = 2)
    {
      resp :=
	soap_client (url=>url, operation=>'echoStringFault',
	    parameters=>vector(vector ('param', 'http://soapinterop.org/types/requestresponse:echoStringFaultRequest'), 'Hello World!'),
	    style=>3,
	    soap_action=>'""',
	    target_namespace=>'http://soapinterop.org/wsdl'
	    );
    }
  else
    if (op = 3)
    {
      resp :=
	soap_client (url=>url, operation=>'echoIntArrayFault',
	    parameters=>vector (vector ('param', 'http://soapinterop.org/types/requestresponse:echoIntArrayFaultRequest'),
	    vector (1,2,3)),
	    style=>3,
	    soap_action=>'""',
	    target_namespace=>'http://soapinterop.org/wsdl'
	    );
    }
  else
    if (op = 4)
    {
      resp :=
	soap_client (url=>url, operation=>'echoMultipleFaults1',
	    parameters=> vector (vector ('param','http://soapinterop.org/types/requestresponse:echoMultipleFaults1Request'), soap_box_structure (
	      'whichFault', wf, 'param1', 'Hello World!', 'param2' , vector (1.11,2.22,3.33))
	      )
	      ,
	    style=>3,
	    soap_action=>'""',
	    target_namespace=>'http://soapinterop.org/wsdl'
	    );
    }
  else
    if (op = 5)
    {
      resp :=
	soap_client (url=>url, operation=>'echoMultipleFaults2',
	    parameters=>vector (
	      vector ('param','http://soapinterop.org/types/requestresponse:echoMultipleFaults2Request'),
	    soap_box_structure ('whichFault', wf, 'param1', 'Hello World!', 'param2' , 1.245, 'param3', vector ('abc', 'def'))),
	    style=>3,
	    soap_action=>'""',
	    target_namespace=>'http://soapinterop.org/wsdl'
	    );
    }
  else
    if (op = 6)
    {
      resp :=
	soap_client (url=>url, operation=>'echoMultipleFaults3',
	    parameters=>vector ( vector ('param','http://soapinterop.org/types/requestresponse:echoMultipleFaults3Request'),
	      soap_box_structure('whichFault', wf, 'param1', 'Hello World!', 'param2' , 'second param')),
	    style=>3,
	    soap_action=>'""',
	    target_namespace=>'http://soapinterop.org/wsdl'
	    );
    }
  else
    if (op = 7)
    {
      resp :=
	soap_client (url=>url, operation=>'echoMultipleFaults4',
	    parameters=>vector ( vector ('param','http://soapinterop.org/types/requestresponse:echoMultipleFaults4Request'),

	    soap_box_structure (  'whichFault', wf, 'param1', 44, 'param2', vector (composite (),'',1))),
	    style=>3,
	    soap_action=>'""',
	    target_namespace=>'http://soapinterop.org/wsdl'
	    );
    }

err:;


?>
<html>
 <HEAD>
 <link rel="stylesheet" type="text/css" href="../demo.css" />
  <STYLE>
  .filelist {
    font-family: Tahoma, sans-serif;
    background-color: #eeeeee;
    color: Black;
    border: 1px #dddddd solid;
  }
  </STYLE>
  </HEAD>
 <body>
  <H4>Virtuoso SOAP client, Interop Round 4 Group H Simple DOC/Literal</H4>
  <p><?=err?></p>
  <form method=post action="<?=http_path()?>">
  <table class="tableentry">
  <tr>
    <td>Enter a Group H Simple RPC endpoint URL</td>
    <td><input type="text" name="url" value="<?=url?>" size="70%" /></td>
  </tr>
  <tr>
    <td>Choose Method to invoke</td>
    <td>
      <select name="op">
        <option value="1" <?= case {?'op'} when '1' then 'selected' else '' end ?>>echoEmptyFault</option>
        <option value="2" <?= case {?'op'} when '2' then 'selected' else '' end ?>>echoStringFault</option>
        <option value="3" <?= case {?'op'} when '3' then 'selected' else '' end ?>>echoIntArrayFault</option>
        <option value="4" <?= case {?'op'} when '4' then 'selected' else '' end ?>>echoMultipleFaults1</option>
        <option value="5" <?= case {?'op'} when '5' then 'selected' else '' end ?>>echoMultipleFaults2</option>
        <option value="6" <?= case {?'op'} when '6' then 'selected' else '' end ?>>echoMultipleFaults3</option>
        <option value="7" <?= case {?'op'} when '7' then 'selected' else '' end ?>>echoMultipleFaults4</option>
      </select>
    </td>
  </tr>
  <tr>
    <td>whichFail</td>
    <td>
      <select name="wf">
        <option value="1" <?= case {?'wf'} when '1' then 'selected' else '' end ?> >1</option>
        <option value="2" <?= case {?'wf'} when '2' then 'selected' else '' end ?> >2</option>
        <option value="3" <?= case {?'wf'} when '3' then 'selected' else '' end ?> >3</option>
      </select>
    </td>
  </tr>
  <tr>
    <td>Start Call</td>
    <td><input type="submit" name="exec" value="Execute"></td>
  </tr>
  </table>
  </form>
<?vsp
  if (resp is not null) {
  declare inx, oux, atts any;
  inp := resp[1];
  outp := resp[2];
  atts := resp[4];
  inx := xslt (TUTORIAL_XSL_DIR () || '/tutorial/services/raw.xsl', xml_tree_doc (inp), vector ('body', 0));
  oux := xslt (TUTORIAL_XSL_DIR () || '/tutorial/services/raw.xsl', xml_tree_doc (outp), vector ('body', 0));
?>
  <table>
  <tr>
    <td>
    Request
    </td>
  </tr>
  <tr>
    <td>
    <div class="filelist">
    <?vsp http_value (inx, null); ?>
    </div>
    </td>
  </tr>
  <tr>
  <tr>
    <td>
    Response
    </td>
  </tr>
    <td>
    <div class="filelist">
    <?vsp http_value (oux, null); ?>
    </div>
    </td>
  </tr>
<?vsp
      if (isarray (atts) and length (atts) > 1)
	{
          declare atta any;
          declare i, l int;
          l := length (atts); i := 1;
	  while (i < l)
	    {
	      atta := atts [i];
    ?>
       <tr>
	 <td>
	<table class="tableresult">
	  <tr> <td>Id</td> <td><?=atta[0] ?></td> </tr>
	  <tr> <td>Type</td> <td><?=atta[1] ?> </td> </tr>
	  <tr> <td>Content</td> <td><?=atta[2] ?> </td> </tr>
	</table>
	</td>
	</tr>
    <?vsp
	      i := i + 1;
	    }
      }
--    else if (not isarray (atts))
--      http ('<tr><td>Result is not DIME encoded</td></tr>');
?>
  </table>
<?vsp
  }
?>
 </body>
</html>
