Ambika,


Here's a trick, though it's cleaner to use something like XQuery unit that can 
actually test using HTTP requests.



"declared" variables are lazily evaluated, and won't throw an error if they are 
missing, until they are actually accessed. So you can prevent the access of an 
external variable by checking for an HTTP field first. If called using XCC 
there will be no HTTP field, so the external parameter will be used.



xquery version "1.0-ml";

declare variable $p external;

let $p-http := xdmp:get-request-field("p", "")

let $p-actual := if ($p-http ne "") then "p as http" else ($p)

return $p-actual


Test from a browser or http client with:    http://localhost:9301/test.xqy?p=x
test from cq with:   xdmp:invoke("/test.xqy", (xs:QName("p"), "z"))

Damon

________________________________
From: [email protected] 
[[email protected]] On Behalf Of ambika arumugam 
[[email protected]]
Sent: Friday, March 18, 2011 3:08 AM
To: General MarkLogic Developer Discussion
Subject: [MarkLogic Dev General] Handling request parameter in both xcc and 
http connection

Hi all,
I have a xquery file which has xdmp:get-request-field to get one of  its 
parameters when it is accessed via the HTTP server, the same xquery file is 
access by a xdbc server for testing so i am using

 declare variable $keyword as xs:string as external

to retrieve the value of parameter from the xdbc connection to pass on to the 
xquery.
I would like this xquery file to handle both the request depending on the 
requirement.
Using  the xcc connection in the java environment I am using

Request requestURL = session.newModuleInvoke("datefile.xqy" );
                  requestURL.setNewStringVariable("node-string", "filename");
                  ResultSequence sequence = session.submitRequest(requestURL);

and in the xquery I am using

declare variable $node-string as xs:string as external;
and then using the variable $node-string

I want to make the xquery in such a way that it accepts and handles both the 
requests without any issues

Regards
Ambika
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to