<?vsp 
--  
--  $Id: complex-rpc.vsp,v 1.2 2006/08/15 19:30:34 source Exp $
--  
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--  
--  Copyright (C) 1998-2006 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/complex/rpc');

  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'});

  declare stru1 DB.DBA.BaseStruct;
  declare soapstr DB.DBA.SOAPStruct;
  declare soapstrf DB.DBA.SOAPStructFault;
  declare stru2 DB.DBA.ExtendedStruct;
  declare stru3 DB.DBA.MoreExtendedStruct;

  stru1 := new DB.DBA.BaseStruct ();
  soapstr := new DB.DBA.SOAPStruct ();
  soapstrf := new DB.DBA.SOAPStructFault ();


  soapstr.varString := 'String';
  soapstr.varInt := 256;
  soapstr.varFloat := 3.1415;

  soapstrf.soapStruct := soapstr;

  stru2 := new DB.DBA.ExtendedStruct ();
  stru3 := new DB.DBA.MoreExtendedStruct ();

  stru1."floatMessage" := 3.1415;
  stru1."shortMessage" := 4096;

  stru2."stringMessage" := 'string1';
  stru2."intMessage" := 1;
  stru2."anotherIntMessage" := 0;
  stru2."floatMessage" := 3.1415;
  stru2."shortMessage" := 4096;

  stru3."booleanMessage" := soap_boolean (1);
  stru3."stringMessage" := 'string1';
  stru3."intMessage" := 1;
  stru3."anotherIntMessage" := 0;
  stru3."floatMessage" := 3.1415;
  stru3."shortMessage" := 4096;

  if (op = 1)
    {

      resp :=
	soap_client (url=>url, operation=>'echoBaseStructFault',
	    parameters=>vector(vector ('param', 'http://soapinterop.org/types:BaseStruct'), stru1),
	    style=>2,
	    soap_action=>'""',
	    target_namespace=>'http://soapinterop.org/wsdl'
	    );
    }
  else
    if (op = 2)
    {
      resp :=
	soap_client (url=>url, operation=>'echoSOAPStructFault',
	    parameters=>vector(vector ('param', 'http://soapinterop.org/types:SOAPStructFault'), soapstrf),
	    style=>2,
	    soap_action=>'""',
	    target_namespace=>'http://soapinterop.org/wsdl'
	    );
    }
  else
    if (op = 3)
    {
      resp :=
	soap_client (url=>url, operation=>'echoExtendedStructFault',
	    parameters=>vector (vector ('param', 'http://soapinterop.org/types:ExtendedStruct'), stru2),
	    style=>2,
	    soap_action=>'""',
	    target_namespace=>'http://soapinterop.org/wsdl'
	    );
    }
  else
    if (op = 4)
    {
      resp :=
	soap_client (url=>url, operation=>'echoMultipleFaults1',
	    parameters=> vector ('whichFault', wf,
	       vector ('param1' , 'http://soapinterop.org/types:SOAPStruct'), soapstr,
	       vector ('param2' , 'http://soapinterop.org/types:BaseStruct'), stru1
	       ),
	    style=>2,
	    soap_action=>'""',
	    target_namespace=>'http://soapinterop.org/wsdl'
	    );
    }
  else
    if (op = 5)
    {
      resp :=
	soap_client (url=>url, operation=>'echoMultipleFaults2',
	    parameters=>vector ('whichFault', wf,
	       vector ('param1' , 'http://soapinterop.org/types:BaseStruct'), stru1,
	       vector ('param2' , 'http://soapinterop.org/types:ExtendedStruct'), stru2,
	       vector ('param3' , 'http://soapinterop.org/types:MoreExtendedStruct'), stru3
	      ),
	    style=>2,
	    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 Complex RPC</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 ?>>echoBaseStructFault</option>
        <option value="2" <?= case {?'op'} when '2' then 'selected' else '' end ?>>echoSOAPStructFault</option>
        <option value="3" <?= case {?'op'} when '3' then 'selected' else '' end ?>>echoExtendedStructFault</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>
      </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];
  dbg_obj_print (outp);
  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>
