[XQZone General] interfacing servlet from xqy file

David Sewell dsewell at virginia.edu
Tue Aug 9 13:02:34 PDT 2005

On Tue, 9 Aug 2005, Ciano.William wrote:

> How can I send a parameter (say, name="Bob") to a servlet from a .xqy
> file using the xdmp:http-post() method ?  Does someone have a code
> example ?

Here's a simple example. Suppose I have a CGI script that basically just
echoes the text it receives; it is in a Perl script called "echo.pl"
that looks like so:

	use CGI qw(param header p);
	my $stuff = param("stuff");
	print header("text/plain");
	print "You sent me this text: $stuff\n";

It simply returns the contents of the HTTP parameter named 'stuff' with
a small text wrapper. I can call it from an .xqy script called


	let $stuff := xdmp:get-request-field("stuff")
	let $cgi-url := "http://rock.ei.virginia.edu/cgi-bin/echo.pl"
	let $param := "stuff"
	return xdmp:http-post($cgi-url,
	   <options xmlns="xdmp:http"><data>{concat($param, "=",

which looks for an incoming HTTP parameter called "stuff" and
then passes it along to the URI contained in the variable $cgi-url.

The result should be two nodes, a <response> element containing the HTTP
header and then whatever the CGI program returned. For a live example,



David Sewell, Editorial and Technical Manager
Electronic Imprint, The University of Virginia Press
PO Box 400318, Charlottesville, VA 22904-4318 USA
Courier: 310 Old Ivy Way, Suite 302, Charlottesville VA 22903
Email: dsewell at virginia.edu   Tel: +1 434 924 9973
Web: http://www.ei.virginia.edu/

More information about the General mailing list