Dear Christian,
my problem is fixed. My xquery sent not a json-string, but a string and within
a json-string:
>>>"{\"query\":\"Mensch\",\"top_k\":\"20\",\"autor\":\"hvk\",\"genre\":\"\"}"<<<
With data = json.loads(json.loads(data_string)) inside the python-code all is
going well.
So far with BaseX 9.1 I didn´t had any problems with the code, but BaseX 12.0
made the difference.
That´s the xquery code
let $search-results :=
if ($query) then
let $url := "http://localhost:5003/search"
let $request :=
<http:request
href="{$url}"
method="post">
<http:body
media-type="application/json">
{
serialize(
map {
"query": $query,
"top_k": $top_k,
"autor": $autor,
"genre": $genre
},
map {"method": "json"}
)
}
</http:body>
</http:request>
let $response := http:send-request($request)
let $response-body := $response
return
(
if ($response-body) then
<div>{$response-body}</div>
else
<p>Fehler bei der Suche: Keine Antwort erhalten.</p>
)
else
()
Best,
Günter
> Am 05.08.2025 um 18:49 schrieb Christian Grün <[email protected]>:
>
> Dear Günter,
>
> Difficult to tell again. What does the Flask server logs say about the
> rejected response?
>
> Best,
> Christian
>
> Von: Günter Dunz-Wolff <[email protected]>
> Gesendet: Dienstag, 5. August 2025 18:15
> An: Christian Grün <[email protected]>
> Cc: [email protected] <[email protected]>
> Betreff: Re: [basex-talk] Migration einer alten RESTXQ-Anwendung nach BaseX
> 12.0 - ClassNotFoundException für Servlets
>
> Dear Christian,
>
> thanks for asking. The problem has now been reduced to a persistent error
> that blocks communication between a basex xquery and a local Flask server.
> Error 500 is constantly displayed in the browser, while no error is displayed
> in the basex log. A curl query also works smoothly. The BaseX version 9.1
> I've been using so far has never had any problems with it. I've reduced the
> basex environment to an absolute minimum, just one file that makes an
> http:send request. Here's the small xquery code:
>
> xquery version "3.0";
>
> module namespace test = "http://example.com/test";
>
> import module namespace http = "http://expath.org/ns/http-client";
>
> declare
> %rest:path("test-flask")
> %rest:GET
> %output:method("xml")
> function test:call-flask() {
> let $url := "http://127.0.0.1:5003/search"
>
> (: Create the JSON payload as a string :)
> let $payload := serialize(
> map {
> "query": "Krieg",
> "autor": "hvk",
> "genre": "",
> "top_k": "5"
> },
> map {"method": "json"}
> )
>
> (: Create the request element. It does NOT contain a body. :)
> let $request :=
> <http:request href="{$url}" method="post">
> <http:body media-type="application/json"/>
> </http:request>
>
> (: Execute the request.
> Argument 1: the request element.
> Argument 2: is empty in this case, since the URL is in the request element.
> Argument 3: the body/payload.
> :)
> let $response := http:send-request($request, (), $payload)
>
> return
> <result>
> <status>{$response[2]/@status}</status>
> <body>{try { fn:parse-xml($response[1]) } catch * { $response[1] }}</body>
> </result>
> };
>
>
>
> As mentioned, BaseX v9.1 didn't cause any problems here. Here's an excerpt
> from the old code that produces the same problems in BaseX v12.0.
>
> let $search-results :=
> if ($query) then
> let $url := "http://localhost:5003/search"
> let $request :=
> <http:request
> href="{$url}"
> method="post">
> <http:body
> media-type="application/json">
> {
> serialize(
> map {
> "query": $query,
> "top_k": $top_k,
> "author": $author,
> "genre": $genre
> },
> map {"method": "json"}
> )
> }
> </http:body>
> </http:request>
>
> let $response := http:send-request($request)
> let $response-body := $response
>
> return
> (
> if ($response-body) then
> <div>{$response-body}</div>
> else
> <p>Search error: No answer found.</p>
> )
>
> else
> ()
>
>
> Any information is helpful. Thank you in advance.
> Günter
>
> Am 04.08.2025 um 17:13 schrieb Christian Grün <[email protected]>:
>
> Dear Günter,
>
> You may need to supply us with some more information to make this better
> reproducible:
>
> • Which distribution of BaseX do you use (ZIP, Windows installer, …)?
> • Did you write the systemd service on your own? What does it do?
> • Where did the instructions come from (Fügen Sie den Inhalt Ihrer web.xml
> bei)?
>
> Thanks in advance,
> Christian
> Von: Günter Dunz-Wolff <[email protected]>
> Gesendet: Montag, 4. August 2025 11:44
> An: [email protected] <[email protected]>
> Betreff: [basex-talk] Migration einer alten RESTXQ-Anwendung nach BaseX 12.0
> - ClassNotFoundException für Servlets
>
> "Ich migriere eine bestehende Anwendung von einer alten BaseX-Version auf
> BaseX 12.0."
> "Mein
> systemd
> -Dienst startet den Server, aber die Anwendung schlägt mit einem
> 503
> -Fehler fehl."
> "Das Log zeigt
> java.lang.ClassNotFoundException
> für
> org.basex.http.rest.RestServlet
> und
> org.basex.http.restxq.RestXqServlet
> ."
> Fügen Sie den Inhalt Ihrer
> web.xml
> bei.
> Frage: "Wie lauten die korrekten Klassennamen und die korrekte
> web.xml
> -Konfiguration, um REST und RESTXQ in BaseX 12.0 zu aktivieren?"