<?vsp 
--  
--  $Id: echoDocument.vsp,v 1.4 2008/04/11 09:09:57 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 _caller, _out_str, _soap_url, _err2, opl1, opl2, opl_home varchar;
  declare state, msg, st, p0, temp_url,_content varchar;
  declare _in, _out, _err any;
  declare meta any;
  declare urls any;

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

  -- If hosted in DAV we have a problem with Content param. 
  if (internal_type(_content) = 185)
  {
     -- When hosted in dav we set the 'Content' value to empty, because string_session will crate problems
     for (declare i int,i:=0;i<length(params);i:=i+2)
     if (params[i] = 'Content' and internal_type(params[i+1]) <> 185)
       _content := params[i+1];
  }

  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')
    {
       _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/"';

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

          st := sprintf ('
		  select soap_call (''%s'',
		      ''%s'',
		      ''http://soapinterop/'',
		      ''echoDocument'',
		      vector ( vector (''x'', ''http://soapinterop.org/xsd:x_Document''),
		      vector ( composite (), vector (''ID'', ''%s''), ''%s'' )),
		      11, NULL, NULL, ''%s'', 3)',
		  _soap_url[1],_soap_url[2], {?'IDNbr'}, _content, 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>
    <LINK rel="stylesheet" type="text/css" href="../demo.css">
    <TITLE><?=_caller?> Test</TITLE>
    <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>
  <P><H2><B>echoDocument</B> from <?=_caller?></H2>
  <P>
  <TABLE WIDTH="100%" CLASS="tableentry" BORDER="0">
  <TR><TD ALIGN="left">
  <FORM method="POST" action="echoDocument.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 'Document' element:
	<P>Content:&nbsp;&nbsp;<INPUT size=50 value="Here is some example content." name="Content">
	<P>ID number:&nbsp;&nbsp;<INPUT value=42679 name="IDNbr">
    <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 border="1" class="tableresult">
    <TR><TD>
    <P><b><?=_out_str[0][0]?></b>
    <P><?=_out_str[0][1]?> = <b><?=_out_str[0][2]?></b>
    <P>Content: = <b><?=_out_str[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    }   ?>
  </FORM>
</TD></TR>
</TABLE>
</BODY>
</HTML>
