[MarkLogic Dev General] External variables and HTTP app server
Colin.Gerety at flatironssolutions.com
Colin.Gerety at flatironssolutions.com
Fri Jan 11 12:31:01 PST 2008
The design pattern I use (inherited from Ajay?) is to package these
parameters into an XML structure and then use the structure in the
module that does the real work. That insulates worker code from knowing
how the parameters were found.
My web code typically looks like:
import module "http://some.company.com/common" at "lib/util/common.xqy"
declare namespace com = "http:// some.company.com /common"
import module "http://some.company.com/realwork" at "action/realwork"
declare namespace work = "http:// some.company.com /work"
...
Let $defaults := (<param name="foo">foo value</param>,<param
name="bar">bar value</param>)
let $request-params := com:create-request-parameters("html-module.xqy",
defaults)
...
work:do-something($something-or-other, $something-else, $request-params)
...
The code invoked from xdbc can initialize the request-params however it
wants, but it would call the same work:do-something() function.
The function com:create-request-parameters("html-module.xqy", ()) knows
it was called from the web, but it doesn't just look at the form values,
it can also look at the session to determine the current user, documents
with user settings, documents with global defaults ...
Colin Gerety
Flatirons Solutions Corporation
(970) 980-5372 (cell)
Colin.Gerety at FlatironsSolutions.com
-----Original Message-----
From: general-bounces at developer.marklogic.com
[mailto:general-bounces at developer.marklogic.com] On Behalf Of Frank
Sanders
Sent: Friday, January 11, 2008 1:15 PM
To: General Mark Logic Developer Discussion
Subject: RE: [MarkLogic Dev General] External variables and HTTP app
server
David,
I'm sure someone will correct me if I'm wrong, but I don't
believe it's possible to pass an eternal variable in through an HTTP app
server directly.
That said you could write a very simple XQuery module to invoke
your module with the external variables. I'm going to assume that the
code you provided was in a module called my-mod.xqy and that the code
I'm providing below is in a module called my-invoker.xqy:
let $x := xdmp:get-request-field("x")
xdmp:invoke("my-mod.xqy", (xs:QName("x"), $x))
Then you can just access this module which will in turn invoke your code
and pass in the value of x in the query string. Just to be sure I'm
making myself clear:
my-invoker.xqy?x=test
Will result in your module being invoked, with the variable x set to
"test", which will then return "test".
Hopefully this will help.
-fs
-----Original Message-----
From: general-bounces at developer.marklogic.com
[mailto:general-bounces at developer.marklogic.com] On Behalf Of David
Sewell
Sent: Friday, January 11, 2008 1:02 PM
To: General XQZone Discussion
Subject: [MarkLogic Dev General] External variables and HTTP app server
Is there any way to pass an external variable to the main query when it
is running via an HTTP app server? I.e., making it possible to run
define variable $x as xs:string external
$x
without throwing an "undefined external variable error"?
(I know I can use HTTP request fields to pass "external variables". But
I have some code I'd like to be able to run without modification via
XDBC, which returns () for xdmp:get-request-field(), etc. So is there
any mechanism of passing a run-time external variable to the
server that works the same way under either HTTP or XDBC app servers?)
David
--
David Sewell, Editorial and Technical Manager
ROTUNDA, The University of Virginia Press
PO Box 801079, 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://rotunda.upress.virginia.edu/
_______________________________________________
General mailing list
General at developer.marklogic.com
http://xqzone.com/mailman/listinfo/general
_______________________________________________
General mailing list
General at developer.marklogic.com
http://xqzone.com/mailman/listinfo/general
More information about the General
mailing list