<?vsp 
--  
--  $Id: dime-rpc.vsp,v 1.2.2.1 2012/03/08 12:55:14 source Exp $
--  
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--  
--  Copyright (C) 1998-2012 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 varchar;

  declare _host varchar;
  _host := 'htp://' || http_request_header(lines, 'Host', null, 'localhost:' || server_http_port());
  url := get_keyword ('url' , params, _host || '/r4/groupG/dime/rpc');

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

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

  if (isstring (op)) op := atoi (op);

  if (op = 1)
    {
      resp :=
	soap_client (url=>url, operation=>'EchoBase64AsAttachment',
	    parameters=>vector('In', encode_base64 ('1234567890')), style=>2,
	    soap_action=>'"http://soapinterop.org/attachments/"',
	    target_namespace=>'http://soapinterop.org/attachments/'
	    );
    }
  else if (op = 2)
    {
      resp :=
	soap_client (url=>url, operation=>'EchoAttachmentAsBase64',
	    parameters=>vector(
	      vector('In', 'base64Binary'),
	      vector (uuid(), 'application/octetstream' , '1234567890')), style=>10,
	    soap_action=>'"http://soapinterop.org/attachments/"',
	    target_namespace=>'http://soapinterop.org/attachments/'
	    );

    }
  else if (op = 3)
    {
      resp :=
	soap_client (url=>url, operation=>'EchoAttachmentAsString',
	    parameters=>vector(
	      vector('In', 'base64Binary'),
	      vector (uuid(), 'text/html; charset="utf-8"',
	                      '<html><body><p>Hello World</p></body></html>')), style=>10,
--	      vector (uuid(), 'text/plain; charset="utf-16"',
--	                      file_to_string ('utf16.txt'))), style=>10,
	    soap_action=>'"http://soapinterop.org/attachments/"',
	    target_namespace=>'http://soapinterop.org/attachments/'
	    );
    }
  else if (op = 4)
    {
      resp :=
	soap_client (url=>url, operation=>'EchoAttachments', parameters=>
	    vector(vector('In', 'http://soapinterop.org/attachments/xsd:ArrayOfBinary'),
	      vector (vector(uuid(), 'text/plain; charset="utf-8"', '123'), vector (uuid(), 'text/plain; charset="utf-8"', '345')) ), style=>10,
	    soap_action=>'"http://soapinterop.org/attachments/"',
	    target_namespace=>'http://soapinterop.org/attachments/');

    }
  else if (op = 6)
    {
      resp :=
	soap_client (url=>url, operation=>'EchoAttachment',
	    parameters=>vector(
	      vector('In', 'base64Binary'),
	      vector (uuid(), 'application/octetstream' , '1234567890')),
	    style=>10,
	    soap_action=>'"http://soapinterop.org/attachments/"',
	    target_namespace=>'http://soapinterop.org/attachments/');

    }
  else if (op = 5)
    {
      resp :=
	soap_client (url=>url, operation=>'EchoUnrefAttachments', parameters=>
	    vector(), style=>10,
	    soap_action=>'"http://soapinterop.org/attachments/"',
	    target_namespace=>'http://soapinterop.org/attachments/');
    }

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 G DIME/RPC</H4>
  <p><?=err?></p>
  <form method=post action="<?=http_path()?>">
  <table class="tableentry">
  <tr>
    <td>Enter a Group G DIME/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 ?>>EchoBase64AsAttachment</option>
        <option value="2" <?= case {?'op'} when '2' then 'selected' else '' end ?>>EchoAttachmentAsBase64</option>
        <option value="3" <?= case {?'op'} when '3' then 'selected' else '' end ?>>EchoAttachmentAsString</option>
        <option value="6" <?= case {?'op'} when '6' then 'selected' else '' end ?>>EchoAttachment</option>
        <option value="4" <?= case {?'op'} when '4' then 'selected' else '' end ?>>EchoAttachments</option>
        <option value="5" <?= case {?'op'} when '5' then 'selected' else '' end ?>>EchoUnrefAttachments</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>
