<?vsp 
--  
--  $Id: echoPerson.vsp,v 1.3.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 _caller, _out_str, _soap_url, _err2, opl1, opl2, opl_home varchar;
  declare state, msg, st, p0, temp_url varchar;
  declare _in, _out, _err any;
  declare meta any;
  declare urls any;

  _caller := {?'caller'};
  _in := {?'in'};
  _out := {?'out'};
  opl_home := {?'opl_home'};

  if (_caller= 'Compound1')
    {
       opl1 := concat (opl_home, '/r3/Compound1');
       opl2 := concat ('OpenLink Software (', opl1, ')');
       urls := vector (
	       vector (opl1, opl2),
	       vector ('http://mssoapinterop.org/stkv3/wsdl/Compound1.wsdl','Microsoft (http://mssoapinterop.org/stkv3/wsdl/Compound1.wsdl)'),
	       vector ('http://www.soapclient.com/interop/compound1.wsdl','SQLData (http://www.soapclient.com/interop/compound1.wsdl)'),
	       vector ('http://mssoapinterop.org/asmx/wsdl/compound1.asmx','ASP.NET (http://mssoapinterop.org/asmx/wsdl/compound1.wsdl)')
		 );
    }

  _out_str := '';
  p0 := '"http://soapinterop.org/"';

  if ({?'step'} = '1')
    {
       declare t_pol integer;

       if ({?'IsMale'} = 'on')
         t_pol := 1;
       else
         t_pol := 0;

       _soap_url := {?'soap_svc_url'};
       if (_soap_url = '')
         _soap_url := {?'other_uri'};

       if (strstr (_soap_url, 'stkv3') > 0 or (strstr (_soap_url, 'asmx') > 0) or (strstr (_soap_url, 'xmlbus') > 0))
	 p0 := '"http://soapinterop/echoPerson"';

       temp_url := _soap_url;
       _soap_url := WS.WS.PARSE_URI (_soap_url);

          st := sprintf ('
		  select soap_call (''%s'',
		      ''%s'',
		      ''http://soapinterop/'',
		      ''echoPersone'',
		      vector ( vector (''x'', ''http://soapinterop.org/xsd:x_Person''),
		      vector (composite (), vector (
		      ''Name'', ''%s'',
		      ''Male'', soap_boolean (%i)),
		      ''Age'', cast (''%s'' as double precision),
		      ''ID'', cast (''%s'' as float))),
		      11, NULL, NULL, ''%s'', 3)',
		  _soap_url[1],_soap_url[2], {?'Name'}, t_pol, {?'Age'}, {?'IDNbr'}, p0);
       state := '00000';
       exec (st, state, msg, vector (), 1000, meta, _out_str);

       if (state = '00000')
	 {
	    _out_str := _out_str[0];
	    _out_str := _out_str[0];
	    _in := _out_str[1];
	    _out := _out_str[2];
	    _err := _out_str[3];
            if (_err <> 0) goto next;
	    _out_str := _out_str[0];
	 }
       else
	 {
           _err2 := 'Yes';
           _out_str := 'Error (see error message)';
	   _in := msg;
	 }
    }
next:
?>
<HTML>
  <HEAD>
    <TITLE><?=_caller?> Test</TITLE>
    <LINK rel="stylesheet" type="text/css" href="../demo.css">
    <META http-equiv=Content-Type content="text/html; charset=windows-1252">
    <META name="AUTHOR" content="OpenLink Software">
    <META name="DESCRIPTION" content="<?=_caller?> Test">
  </HEAD>
<BODY>
<TABLE WIDTH="100%" CLASS="ctrlmain" BORDER="0" CELLPADDING="0" CELLSPACING="0">
  <TR CLASS="ctrlmain"><TD ALIGN="left">
  <FORM method="POST" action="echoPerson.vsp">
  <P><H2><B>echoPerson</B> from <?=_caller?></H2>
    <P>This operation sends and receives a XML document containing a single element of type 'Person'.
    <P>Select the SOAP service endpoint URL you wish to use:<BR/>
<TABLE CLASS="tableentry" BORDER="0">
  <TR><TD ALIGN="left">
  <FORM method="POST" action="echoPerson.vsp">
<?vsp
    declare idx, len integer;
    declare ch varchar;

    idx := 0;
    len := length (urls);

    while (idx < len)
      {
        ch  := '';
	if (temp_url = urls[idx][0] or idx = 0) ch := 'checked';
?>
        <P><INPUT TYPE="radio" name="soap_svc_url" value="<?=urls[idx][0]?>" <?=ch?>><?=urls[idx][1]?>
<?vsp
         idx := idx + 1;
      }
?>
    <P><INPUT TYPE="radio" name="soap_svc_url" value="">Other
    <INPUT size=50 value="" name="other_uri">
	<P>Enter the values for the 'Person' element:
	<P>Name:&nbsp;&nbsp;<INPUT size=50 value="Jack Benny" name="Name">
	<P>Age:&nbsp;&nbsp;<INPUT size=5 value=39 name="Age">
	<P>ID number:&nbsp;&nbsp;<INPUT value=42679 name="IDNbr">
	<P><INPUT type=checkbox name=IsMale>&nbsp;&nbsp;Gender is 'Male'
    <P><INPUT type="submit" value="Call">
       <INPUT type="hidden" name="caller" value="<?=_caller?>">
       <INPUT type="hidden" name="opl_home" value="<?=opl_home?>">
       <INPUT type="hidden" name="step" value="1">
    </TABLE>
<?vsp  if (_err <> 0)
         {
?>
    	   <H2>Error:</H2>
	   <b><?=_err[2]?></b>
<?vsp
	   goto buff;
	 }
?>

<?vsp  if (_out_str <> '')
         {
	   if (_err2 = 'Yes')
	     {
?>
    <P>Return value:
    <P><?=_out_str?>
<?vsp
	     }
	   else
	     {
?>
    <P><H2>Return value:</H2>
    <TABLE class="tableresult" border="1">
    <TR>
    <TD>
    <P><?=_out_str[0][3]?>    = <b><?=_out_str[0][4]?></b>
    <P><?=_out_str[0][1]?>    = <b><?=_out_str[0][2]?></b>
    <P><?=_out_str[1][0][0]?> = <b><?=_out_str[1][1]?></b>
    <P><?=_out_str[2][0][0]?> = <b><?=_out_str[2][1]?></b>
<?vsp
	     }
	 }
buff:
       if (_in is not NULL)
         {
?>
    <P>Request message buffer:
    <P><TEXTAREA name=buffer_request rows=15 cols=80><?=_in?></TEXTAREA>
<?vsp    }
       if (_out is not NULL)
         {
?>
    <P>Response message buffer:
    <P><TEXTAREA name=buffer_response rows=15 cols=80><?=_out?></TEXTAREA></P>
<?vsp    }   ?>
  </TD>
  </TR>
  </TABLE>
  </FORM>
</BODY>
</HTML>
