<?vsp 
--  
--  $Id$
--  
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--  
--  Copyright (C) 1998-2018 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/mime/doc');

  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(vector('EchoBase64AsAttachment',
		   'http://soapinterop.org/attachments/xsd:EchoBase64AsAttachment'),
		 vector(encode_base64('Hello DocLit'))),
	       style=>515, soap_action=>'"http://soapinterop.org/attachments/"');

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

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

    }
  else if (op = 4)
    {
      resp :=
		soap_client (url=>url, operation=>'EchoAttachments',
      parameters=>
      vector(vector('In', 'http://soapinterop.org/attachments/xsd:EchoAttachments'),
      vector (vector(uuid(), 'text/plain', '123'), vector (uuid(), 'text/plain; charset="utf-8"', '345'))
      ), style=>515,
      soap_action=>'"http://soapinterop.org/attachments/"'
    );

    }

err:;

dbg_obj_print ('url = ', url);

?>
<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 MIME/DocLit</H4>
  <p><?=err?></p>
  <form method=post action="<?=http_path()?>">
  <table class="tableentry">
  <tr>
    <td>Enter a Group G MIME/DocLit 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 ?>>EchoAttachment</option>
        <option value="4" <?= case {?'op'} when '4' then 'selected' else '' end ?>>EchoAttachments</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 MIME encoded</td></tr>');
?>
  </table>
<?vsp
  }
?>
 </body>
</html>
