Forwarding to the mailing-list...
-------- Original-Nachricht -------- Betreff: Re: [basex-talk] How to retrieve HTTP request parameters and use them in XQuery with BaseX Datum: Thu, 30 Dec 2010 13:59:57 +0000 Von: software developer computer.software.developer@gmail.com An: Andreas Weiler andreas.weiler@uni-konstanz.de
Well, then the problem changes to 'how to pass dynamic parameters from an HTTP client to the java class in question - java class is running on a different machine' - that bridge was to be the HTTP request parameters - what else can serve to pass dynamic parameters to the xquery? I invoke BaseX via jax-rx and xquery is stored on server-side (cannot put that in the URL itself) - xquery is invoked using run param to jax-rx invocation.
Your solution has xquery passing the param to the java class, in my case an external HTTP client is to send the parameters...so, how would the java class receive the HTTP request param or alternatively, how would the xquery receive request param directly via jax-rx?
On Thu, Dec 30, 2010 at 1:18 PM, Andreas Weiler <andreas.weiler@uni-konstanz.de mailto:andreas.weiler@uni-konstanz.de> wrote:
Hi,
passing parameters to xquery dynamically can be done with the xquery java bindings. So the parameter comes directly from your java class.
Hi,
Am 30.12.2010 13:59, schrieb software developer:
Well, then the problem changes to 'how to pass dynamic parameters from an HTTP client to the java class in question - java class is running on a different machine' - that bridge was to be the HTTP request parameters
- what else can serve to pass dynamic parameters to the xquery? I
invoke BaseX via jax-rx and xquery is stored on server-side (cannot put that in the URL itself) - xquery is invoked using run param to jax-rx invocation.
Your solution has xquery passing the param to the java class, in my case an external HTTP client is to send the parameters...so, how would the java class receive the HTTP request param or alternatively, how would the xquery receive request param directly via jax-rx?
Currently you can bind values to external variables via JAX-RX (at least in BaseX), using the 'var' parameter.
Assuming your query is
declare variable $x as xs:integer external; declare variable $y as xs:integer external; $x * $y
then the easiest way is to append the parameter
&var=$x=21%01$y=2
to your JAX-RX URI, thus binding 21 to $x and 2 to $y.
Note that you have to glue multiple bindings together with the 'SOH' ASCII char, '\1' in Java and %01 in the URL encoding.
[1] is a working example.
If you also want to specify the type of the bound value, this can be done by appending it to the binding, separated by another '=':
&var=$x=14=xs:integer%01$y=3=xs:integer
See [2] for an example.
Please be aware that the syntax might change with any new minor version in the future.
I hope this helps, Cheers Leo __________
[1] http://localhost:8984/basex/jax-rx?wrap=no&query=declare+variable+$x+as+...
[2] http://localhost:8984/basex/jax-rx?wrap=no&query=declare+variable+$x+ext...
Hi,
The parameters are not bound to variables when a query is invoked via the run parameter.
For example, I store my query in myquery.xq on the server side; if the query contains current-time()
invocation of the URL http://localhost:8984/basex/jax-rx?wrap=no&run=myquery.xq&var=$x=21%... results in display of current date-time
but if the query contains declare variable $x as xs:integer external; declare variable $y as xs:integer external; $x*$y
I get the error Stopped at line 1, column 34 in myquery.xq: [XQDY0002] No value defined for "$x as xs:integer".
The parameters are correctly bound to variables when a query is invoked via the query parameter named query as you described, but that is not what I am after. Is this a bug? Is there a workaround?
Hi,
this feature isnt enabled for the run command yet. We put that on our todo-list and get it done as fast as possible. You could also have a look into our language bindings (for other ways then REST) [1], here you can also bind variables to queries. If your query is not to large, i guess the network traffic for sending the query for each request should not be too much.
Kind regards, Andreas
[1] http://www.inf.uni-konstanz.de/dbis/basex/bindings
Am 31.12.10 16:18, schrieb software developer:
Hi,
The parameters are not bound to variables when a query is invoked via the run parameter.
For example, I store my query in myquery.xq on the server side; if the query contains current-time()
invocation of the URL http://localhost:8984/basex/jax-rx?wrap=no&run=myquery.xq&var=$x=21%... http://localhost:8984/basex/jax-rx?wrap=no&run=myquery.xq&var=$x=21%01$y=2
results in display of current date-time
but if the query contains declare variable $x as xs:integer external; declare variable $y as xs:integer external; $x*$y
I get the error Stopped at line 1, column 34 in myquery.xq: [XQDY0002] No value defined for "$x as xs:integer".
The parameters are correctly bound to variables when a query is invoked via the query parameter named query as you described, but that is not what I am after. Is this a bug? Is there a workaround?
basex-talk@mailman.uni-konstanz.de