Possible to store query on the server side, but payload (XML data) in HTTP post, using jax-rx?
Monday, 11 April 2011 · 11 messages · last reply 9 May 2011
CD
Computer Software Developer11 Apr 2011 17:14 #
Hi,
Using the run parameter in a jax-rx request, one can specify a query contained in a file stored on the server side.
Using HTTP Post, one can specify the xquery and the payload in the HTTP request as XML.
If the XML is generated on the client side to be stored on the server using HTTP post, can one execute an updating xquery stored on the server side to store this generated XML on the server?
In other words, (how) can one run xqueries stored on the server side with an XML payload submitted using the HTTP post?
Thanks.
CG
Christian Grün11 Apr 2011 18:11 #
Hi,
Quoted text · Computer Software Developer · 2 lines
> In other words, (how) can one run xqueries stored on the server side > with an XML payload submitted using the HTTP post?
That's not possible. Instead, you'll either have to include your XML snippet in the XQuery Update expression, or store it in a database and access it via a second query (which won't be an atomic transaction).
Christian
CD
Computer Software Developer21 Apr 2011 16:53 #
Quoted text · Christian Grün · 3 lines
On 11/04/2011 17:11, Christian Grün wrote: > Instead, you'll either have to include your XML > snippet in the XQuery Update expression
And I hoped to achieve that (including XML snippet in the XQuery Update expression) via a jax-rx variable in a query parameter (the equivalent in an HTTP Post, actually), which would then be accessed in the updating xquery stored on the server side via a variable. Is it possible that way?
Looking at the schema required for the HTTP post, it appears that the element named query, which is supposed to contain the xquery, can be replaced instead with the element named run. As an example, I had hoped this would work (XML in xmlSnippet variable):
<?xml version="1.0" encoding="iso-8859-1"?><run
xmlns="http://jax-rx.sourceforge.net"><text>updateDetails.xq</text><parameter
name="output" value="media-type=application/xml"/><parameter
name="output" value="encoding=iso-8859-1"/><parameter name="output"
value="omit-xml-declaration=no"/><variable name="databaseName"
value="MyData"/><variable name="xmlSnippet"
value="<xml><data/></xml>"/></run>In the example above, can the updateDetails.xq not retrieve the XML submitted via the variable xmlSnippet?
CG
Christian Grün21 Apr 2011 17:00 #
This is how your XQuery snippet could look like:
<query xmlns="http://jax-rx.sourceforge.net">
<text><![CDATA[
insert node <snippet>to be inserted</snippet>
into /updating/target
]]></text>
</query>Hope this helps,
Christian
Quoted text · Computer Software Developer · 29 lines
On Thu, Apr 21, 2011 at 4:53 PM, Computer Software Developer <computer.software.developer at gmail.com> wrote: > On 11/04/2011 17:11, Christian Grün wrote: >> Instead, you'll either have to include your XML >> snippet in the XQuery Update expression > > And I hoped to achieve that (including XML snippet in the XQuery Update > expression) via a jax-rx variable in a query parameter (the equivalent > in an HTTP Post, actually), which would then be accessed in the updating > xquery stored on the server side via a variable. Is it possible that way? > > Looking at the schema required for the HTTP post, it appears that the > element named query, which is supposed to contain the xquery, can be > replaced instead with the element named run. As an example, I > had hoped this would work (XML in xmlSnippet variable): > > > <?xml version="1.0" encoding="iso-8859-1"?><run > xmlns="http://jax-rx.sourceforge.net"><text>updateDetails.xq</text><parameter > name="output" value="media-type=application/xml"/><parameter > name="output" value="encoding=iso-8859-1"/><parameter name="output" > value="omit-xml-declaration=no"/><variable name="databaseName" > value="MyData"/><variable name="xmlSnippet" > value="<xml><data/></xml>"/></run> > > In the example above, can the updateDetails.xq not retrieve the XML > submitted via the variable xmlSnippet? > >
CD
Computer Software Developer21 Apr 2011 17:00 #
Quoted text · Christian Grün · 13 lines
On 21/04/2011 16:00, Christian Grün wrote: > This is how your XQuery snippet could look like: > > <query xmlns="http://jax-rx.sourceforge.net"> > <text><![CDATA[ > insert node <snippet>to be inserted</snippet> > into /updating/target > ]]></text> > </query> > > Hope this helps, > Christian >
Correct, I understood that, but want to use run instead of query - any possibility at all (assuming the value I mentioned in my example in earlier email is encapsulated in CDATA section)?
CG
Christian Grün21 Apr 2011 17:05 #
…not in the current version of JAX-RX, sorry. You are invited to add a feature request at
https://github.com/BaseXdb/jax-rx
C.
Quoted text · Computer Software Developer · 19 lines
On Thu, Apr 21, 2011 at 5:00 PM, Computer Software Developer <computer.software.developer at gmail.com> wrote: > On 21/04/2011 16:00, Christian Grün wrote: >> This is how your XQuery snippet could look like: >> >> <query xmlns="http://jax-rx.sourceforge.net"> >> <text><![CDATA[ >> insert node <snippet>to be inserted</snippet> >> into /updating/target >> ]]></text> >> </query> >> >> Hope this helps, >> Christian >> > Correct, I understood that, but want to use run instead of query - any > possibility at all (assuming the value I mentioned in my example in > earlier email is encapsulated in CDATA section)? >
CD
Quoted text · Christian Grün · 44 lines
On 21/04/2011 16:00, Christian Grün wrote: > This is how your XQuery snippet could look like: > > <query xmlns="http://jax-rx.sourceforge.net"> > <text><![CDATA[ > insert node <snippet>to be inserted</snippet> > into /updating/target > ]]></text> > </query> > > Hope this helps, > Christian > > > > On Thu, Apr 21, 2011 at 4:53 PM, Computer Software Developer > <computer.software.developer at gmail.com> wrote: >> On 11/04/2011 17:11, Christian Grün wrote: >>> Instead, you'll either have to include your XML >>> snippet in the XQuery Update expression >> >> And I hoped to achieve that (including XML snippet in the XQuery Update >> expression) via a jax-rx variable in a query parameter (the equivalent >> in an HTTP Post, actually), which would then be accessed in the updating >> xquery stored on the server side via a variable. Is it possible that way? >> >> Looking at the schema required for the HTTP post, it appears that the >> element named query, which is supposed to contain the xquery, can be >> replaced instead with the element named run. As an example, I >> had hoped this would work (XML in xmlSnippet variable): >> >> >> <?xml version="1.0" encoding="iso-8859-1"?><run >> xmlns="http://jax-rx.sourceforge.net"><text>updateDetails.xq</text><parameter >> name="output" value="media-type=application/xml"/><parameter >> name="output" value="encoding=iso-8859-1"/><parameter name="output" >> value="omit-xml-declaration=no"/><variable name="databaseName" >> value="MyData"/><variable name="xmlSnippet" >> value="<xml><data/></xml>"/></run> >> >> In the example above, can the updateDetails.xq not retrieve the XML >> submitted via the variable xmlSnippet? >> >>
Hi,
Will it be possible for you to provide a working example of using XPath to select nodes-to-be-inserted instead of <snippet>to be
inserted</snippet> in your example query above?
CG
Christian Grün28 Apr 2011 13:33 #
Quoted text · Computer Software Developer · 3 lines
> Will it be possible for you to provide a working example of using XPath > to select nodes-to-be-inserted instead of <snippet>to be > inserted</snippet> in your example query above?
Version 1:
insert node (<node1/>, <node2/>)
into /updating/target
Version 2:
let $x := (<node1/>, <node2/>)
return insert node $x into /updating/targetHope this helps,
Christian
CD
Computer Software Developer3 May 2011 14:50 #
Quoted text · Christian Grün · 15 lines
On 28/04/2011 12:33, Christian Grün wrote: >> Will it be possible for you to provide a working example of using XPath >> to select nodes-to-be-inserted instead of <snippet>to be >> inserted</snippet> in your example query above? > > Version 1: > insert node (<node1/>, <node2/>) > into /updating/target > > Version 2: > let $x := (<node1/>, <node2/>) > return insert node $x into /updating/target > > Hope this helps, > Christian
Hi,
I am still stuck on this one ('cos I generate xquery from within XSLT and it is proving to be hard to embed the XML instance in the xquery so generated).
I can probably serialize the XML, pass it as a string parameter to the xquery on the server side and then create XML back from that string in the xquery - how to do this last step (parse a document from incoming serialized XML)?
Thanks.
CD
Quoted text · Christian Grün · 14 lines
On 21/04/2011 16:00, Christian Grün wrote: > This is how your XQuery snippet could look like: > > <query xmlns="http://jax-rx.sourceforge.net"> > <text><![CDATA[ > insert node <snippet>to be inserted</snippet> > into /updating/target > ]]></text> > </query> > > Hope this helps, > Christian > >
Will it work if I were to use serialized text instead of CDATA section, as in:
<query xmlns="http://jax-rx.sourceforge.net">
<text>insert node <snippet>to be inserted</snippet>
into /updating/target</text>
</query>will it work for the replace scenario as well, as in:
<?xml version="1.0" encoding="iso-8859-1"?><jaxrx:query
xmlns:jaxrx="http://jax-rx.sourceforge.net"><text>
xquery version "1.0";
declare namespace fn="http://www.w3.org/2005/xpath-functions";
let $dataSet := 'Experimental'
let $databaseName := 'MyData'
let $applicationID := '1'
let $finalURL := fn:concat($databaseName, "/",$dataSet)
let $applicationsModified := '<?xml version="1.0"
encoding="iso-8859-1"?>
<APPLICATION>
<APPLICATION_ID>1</APPLICATION_ID>
<DATA/>
</APPLICATION>'
for $all in fn:collection($finalURL)
for $anApp in $all/APPLICATION[APPLICATION_ID=$applicationID]
return
(
replace node $anApp with $applicationsModified
)
</text></jaxrx:query>If it wouldn't work, what would be the reason/s?
I am presently getting HTTP 500:
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /basex/jax-rx. Reason:
<pre> No enum const class
org.jaxrx.core.QueryParameter.JAXRX:QUERY</pre></p><h3>Caused by:</h3><pre>java.lang.IllegalArgumentException: No enum const class org.jaxrx.core.QueryParameter.JAXRX:QUERY
.at java.lang.Enum.valueOf(Enum.java:196)
.at org.jaxrx.core.QueryParameter.valueOf(QueryParameter.java:1) .at org.jaxrx.resource.AResource.getParameters(AResource.java:165) .at org.jaxrx.resource.AResource.postQuery(AResource.java:281) .at org.jaxrx.resource.JaxRxResource.postQuery(JaxRxResource.java:1) .at org.jaxrx.resource.JaxRxResource.postQuery(JaxRxResource.java:109) .at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source) .at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
CD
Computer Software Developer9 May 2011 17:12 #
Quoted text · Christian Grün · 67 lines
On 09/05/2011 10:33, Computer Software Developer wrote: > On 21/04/2011 16:00, Christian Grün wrote: >> This is how your XQuery snippet could look like: >> >> <query xmlns="http://jax-rx.sourceforge.net"> >> <text><![CDATA[ >> insert node <snippet>to be inserted</snippet> >> into /updating/target >> ]]></text> >> </query> >> >> Hope this helps, >> Christian >> >> > Will it work if I were to use serialized text instead of CDATA section, > as in: > <query xmlns="http://jax-rx.sourceforge.net"> > <text>insert node <snippet>to be inserted</snippet> > into /updating/target</text> > </query> > > will it work for the replace scenario as well, as in: > <?xml version="1.0" encoding="iso-8859-1"?><jaxrx:query > xmlns:jaxrx="http://jax-rx.sourceforge.net"><text> > xquery version "1.0"; > > declare namespace fn="http://www.w3.org/2005/xpath-functions"; > > let $dataSet := 'Experimental' > let $databaseName := 'MyData' > let $applicationID := '1' > > let $finalURL := fn:concat($databaseName, "/",$dataSet) > let $applicationsModified := '<?xml version="1.0" > encoding="iso-8859-1"?> > <APPLICATION> > <APPLICATION_ID>1</APPLICATION_ID> > <DATA/> > </APPLICATION>' > > for $all in fn:collection($finalURL) > for $anApp in $all/APPLICATION[APPLICATION_ID=$applicationID] > return > ( > replace node $anApp with $applicationsModified > ) > </text></jaxrx:query> > > If it wouldn't work, what would be the reason/s? > > I am presently getting HTTP 500: > <body><h2>HTTP ERROR 500</h2> > <p>Problem accessing /basex/jax-rx. Reason: > <pre> No enum const class > org.jaxrx.core.QueryParameter.JAXRX:QUERY</pre></p><h3>Caused > by:</h3><pre>java.lang.IllegalArgumentException: No enum const class > org.jaxrx.core.QueryParameter.JAXRX:QUERY > .at java.lang.Enum.valueOf(Enum.java:196) > .at org.jaxrx.core.QueryParameter.valueOf(QueryParameter.java:1) > .at org.jaxrx.resource.AResource.getParameters(AResource.java:165) > .at org.jaxrx.resource.AResource.postQuery(AResource.java:281) > .at org.jaxrx.resource.JaxRxResource.postQuery(JaxRxResource.java:1) > .at org.jaxrx.resource.JaxRxResource.postQuery(JaxRxResource.java:109) > .at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source) > .at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
The reason for the error is that query is declared to be in jaxrx namespace, which should not be an error (or should it be, i.e., the way I use it?), but I do not get this exception if I specify query without a namespace.
Written for BaseX 6.6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery