Problems with REST-Style Web API: {}

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems with REST-Style Web API: {}

Ulrike Schmidt
I have a problem with some XQueries I try to send with Perl to the
server. They work fine with the xquery search form
(http://localhost:8080/exist/xquery/xquery.xq), but not if I send them
with the Perl script.

The queries, that do not work, contain "{}" or "<>" like in:

  return <GlyphInfo>{ $glyph }{ $kanji }</GlyphInfo>

This gives the following error:

   400 unexpected token: null [at line 6, column 8]

I testet it on my local machine with a CVS download from 2005-10-14 and
also on a remote machine with eXist-1.0b2-build-1107.war
The results are the same except for one query where I get "500 Internal
Server Error" on the remote machine and have no problems on the local
machine.

This query has nothing remarkable except for a transform. I cannot find
anything in the logs in /opt/tomcat5/webapps/exist/WEB-INF/logs
How can I debug this one?

Thanks, Uli



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: Problems with REST-Style Web API: {}

Michael Beddow-2
Ulrike Schmidt wrote:

[...]

>   return <GlyphInfo>{ $glyph }{ $kanji }</GlyphInfo>

Try wrapping the body of your XQuery in a CDATA block. Note also that when
creating a query as a Perl string it's also necessary to escape any $ and @
characters that need to be passed to the XQuery engine as is. Unescaped
symbols, such as  $term1 below, of course trigger the usual variable
substitutions, whereas the escaped  \$para has become the XQuery variable
name $para by the time eXist gets to see it.

Here's one of mine:

my $QUERY0 = <<EOT;
<?xml version="1.0" encoding="UTF-8"?>
<query xmlns="http://exist.sourceforge.net/NS/exist"
    start="1" max="10000">
    <text><![CDATA[
        for \$para in /text/div/p[match-any(.,'$term1')]
        order by \$para/\@tstamp
        return
            <hit>{\$para}</hit>
    ]]></text>
</query>
EOT

This then gets dispatched like so

  my $ua = LWP::UserAgent->new();
  my $req = HTTP::Request->new(POST => $URL);
  $req->content_type('text/xml');
  $req->content($QUERY);
  my $result = $ua->request($req);


Michael Beddow




-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: Problems with REST-Style Web API: {}

Ulrike Schmidt
Michael Beddow wrote:

>Try wrapping the body of your XQuery in a CDATA block.
>
Thanks, that was the problem, and now I also found it as a note in the
documentation ...

> Note also that when
>creating a query as a Perl string it's also necessary to escape any $ and @
>characters that need to be passed to the XQuery engine as is.
>
To avoid this escaping I saved the XQueries in files and load those,
that works fine.

Uli



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open