Issue with expath HTTP request and response
Monday, 30 July 2012 · 8 messages · last reply 1 Aug 2012
SG
Seenivasan Gunabalan30 Jul 2012 17:06 #
Hi all,
I want to share my experience with HTTP module while posting to restxq.
Consider this example,
--------
import module namespace http='http://expath.org/ns/http-client'; let $req := <http:request method="GET"
href="http://localhost:8984/restxq/example"
status-only = "false" username = "admin"
password = "admin"
send-authorization="true"> </http:request>
let $resp := http:send-request($req)
return $resp
----------run the same query with status-only="false" and status-only="true".
the first one(status-only="false") gives exception while the second one(status-only="true") returns proper response header. This is making difficult to handle the response of some requests which MAY contain body data. suppose we want to return the content of the document, if exists, as response body or a standard 410 status. The request should obviously contain status-only = "false".
we also tried handling response with the one below, but the issue does
exists.
<rest:response>
<http:response status="410" reason="Gone">
</http:response>
</rest:response>I have tried with other http client like Firefox Poster plug-in and it is returning expected response. Is there anything wrong in the approach?
Thanks,
Seenivasan
CG
Christian Grün30 Jul 2012 19:29 #
Hi Seenivasan,
your example is running fine on my machine (no matter which value I choose for the status-only attribute).
Is there any reason why you don't directly access your RESTXQ functions? I know too less about your architecture, but, as a general guideline, it's not recommended to perform http/restxq/rest calls on the same machine (i.e., localhost), as you might run into deadlock issues. In particular, this will happen if your query will be managed by the same database context. You won't encounter any issues, however, if you have completely separated BaseX instances for your query and your web services.
Hope this helps,
Christian
Quoted text · Seenivasan Gunabalan · 47 lines
> Hi all, > > I want to share my experience with HTTP module while posting to > restxq. > > Consider this example, > > -------- > import module namespace http='http://expath.org/ns/http-client'; > let $req := <http:request method="GET" > href="http://localhost:8984/restxq/example" > status-only = "false" > username = "admin" > password = "admin" > send-authorization="true"> > </http:request> > > let $resp := http:send-request($req) > return $resp > ---------- > > run the same query with status-only="false" and status-only="true". > > the first one(status-only="false") gives exception while the second > one(status-only="true") returns proper response header. This is making > difficult to handle the response of some requests which MAY contain body > data. suppose we want to return the content of the document, if exists, as > response body or a standard 410 status. The request should obviously contain > status-only = "false". > > we also tried handling response with the one below, but the issue does > exists. > <rest:response> > <http:response status="410" reason="Gone"> > </http:response> > </rest:response> > > I have tried with other http client like Firefox Poster plug-in and it is > returning expected response. Is there anything wrong in the approach? > > > Thanks, > Seenivasan > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
SG
Seenivasan Gunabalan31 Jul 2012 12:02 #
Dear Christian,
Thanks for your kind reply. Since the issue still exists, I am providing more information about the issue, please find them below.
your example is running fine on my machine (no matter which value I choose for the status-only attribute).
I downloaded a fresh copy of basex and ran the request query that was in my previous email, yet facing the same issue.
As you explained, I expected the response described below no matter which is the value for status-only attribute.
<http:response xmlns:http="http://expath.org/ns/http-client"
status="404" message="Not Found">
<http:header name="Content-Length" value="48"/>
<http:header name="Server" value="Jetty(6.1.26)"/>
<http:body media-type="application/octet-stream"/>
</http:response>As I explained before, I am getting the above response when
"status-only='true'", But when "status-only = 'false'", an exception (experr:HC0001) is thrown rather
than getting the above response. Please kindly go through attached screen shots.
Is there any reason why you don't directly access your RESTXQ functions? I know too less about your architecture, but, as a general guideline, it's not recommended to perform http/restxq/rest calls on the same machine (i.e., localhost), as you might run into deadlock issues. In particular, this will happen if your query will be managed by the same database context. You won't encounter any issues, however, if you have completely separated BaseX instances for your query and your web services.
Actually, they are two separate applications in which one tests the another. They may/may not run in the same machine in the future. since it is in early development stage, we are in need to run both applications in the same machine. Thanks for your suggestion, we will maintain a separate BaseX instance from now.
Just as a curiosity, it would be very helpful, if you could provide me an link/reference to know more about why
it's not recommended to perform http/restxq/rest calls on
the same machine
?".
Thanks,
Seenivasan
Quoted text · Christian Grün · 66 lines
On 07/30/2012 07:29 PM, Christian Grün wrote: > Hi Seenivasan, > > your example is running fine on my machine (no matter which value I > choose for the status-only attribute). > > Is there any reason why you don't directly access your RESTXQ > functions? I know too less about your architecture, but, as a general > guideline, it's not recommended to perform http/restxq/rest calls on > the same machine (i.e., localhost), as you might run into deadlock > issues. In particular, this will happen if your query will be managed > by the same database context. You won't encounter any issues, however, > if you have completely separated BaseX instances for your query and > your web services. > > Hope this helps, > Christian > ___________________________ > >> Hi all, >> >> I want to share my experience with HTTP module while posting to >> restxq. >> >> Consider this example, >> >> -------- >> import module namespace http='http://expath.org/ns/http-client'; >> let $req := <http:request method="GET" >> href="http://localhost:8984/restxq/example" >> status-only = "false" >> username = "admin" >> password = "admin" >> send-authorization="true"> >> </http:request> >> >> let $resp := http:send-request($req) >> return $resp >> ---------- >> >> run the same query with status-only="false" and status-only="true". >> >> the first one(status-only="false") gives exception while the second >> one(status-only="true") returns proper response header. This is making >> difficult to handle the response of some requests which MAY contain body >> data. suppose we want to return the content of the document, if exists, as >> response body or a standard 410 status. The request should obviously contain >> status-only = "false". >> >> we also tried handling response with the one below, but the issue does >> exists. >> <rest:response> >> <http:response status="410" reason="Gone"> >> </http:response> >> </rest:response> >> >> I have tried with other http client like Firefox Poster plug-in and it is >> returning expected response. Is there anything wrong in the approach? >> >> >> Thanks, >> Seenivasan >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
CG
Christian Grün31 Jul 2012 17:32 #
Hi Seenivasan,
Quoted text · Seenivasan Gunabalan · 2 lines
> I downloaded a fresh copy of basex and ran the request query that was in my > previous email, yet facing the same issue. [...]
to help you, I still need some more concise information..
- did you download 7.3 or the latest snapshot?
- how did you start the http server?
- which os are you using?
Quoted text · Seenivasan Gunabalan · 2 lines
> Just as a curiosity, it would be very helpful, if you could provide me an > link/reference to know more about why
The main reason is the internal transaction architecture [1]: if a reading query sends a writing query to the same database context, this will lead to a deadlock, as the writing query can only be processed if no concurrent reading queries are running.
Just a short answer; hope this helps,
Christian
[1] http://docs.basex.org/wiki/Transaction_Management
SG
Seenivasan Gunabalan31 Jul 2012 18:07 #
Hi Christian,
Thanks for the link. I will go through it.
to help you, I still need some more concise information..
- did you download 7.3 or the latest snapshot?
i downloaded 7.3 and not the snapshot..
- how did you start the http server?
./basexhttp
- which os are you using?
Ubuntu 11.10
Java-7-openjdk-i386
Thanks and Regards,
Seenivasan
Quoted text · Christian Grün · 22 lines
On 07/31/2012 05:32 PM, Christian Grün wrote: > Hi Seenivasan, > >> I downloaded a fresh copy of basex and ran the request query that was in my >> previous email, yet facing the same issue. [...] > to help you, I still need some more concise information.. > - did you download 7.3 or the latest snapshot? > - how did you start the http server? > - which os are you using? > >> Just as a curiosity, it would be very helpful, if you could provide me an >> link/reference to know more about why > The main reason is the internal transaction architecture [1]: if a > reading query sends a writing query to the same database context, this > will lead to a deadlock, as the writing query can only be processed if > no concurrent reading queries are running. > > Just a short answer; hope this helps, > Christian > > [1] http://docs.basex.org/wiki/Transaction_Management >
CG
Christian Grün31 Jul 2012 20:39 #
Seenivasan,
got it.. So the problem was that the addressed query module
(http://.../restxq/example) did not exist in your scenario, right?
I've uploaded a new stable snapshot that includes a fix. It will return a header and the error message as second item instead of the error message:
http://files.basex.org/releases/latest/
Looking forward to your feedback,
Christian
___________________________
Christian Grün
Box 188, Uni KN
D-78457 Konstanz
www.christian-gruen.de
Quoted text · Seenivasan Gunabalan · 60 lines
On Tue, Jul 31, 2012 at 6:07 PM, Seenivasan Gunabalan <seenivasan.gunabalan at dedalus.eu> wrote: > Hi Christian, > Thanks for the link. I will go through it. > > > to help you, I still need some more concise information.. > > > - did you download 7.3 or the latest snapshot? > > i downloaded 7.3 and not the snapshot.. > > > > - how did you start the http server? > > ./basexhttp > > > > - which os are you using? > > Ubuntu 11.10 > Java-7-openjdk-i386 > > > Thanks and Regards, > Seenivasan > > > > On 07/31/2012 05:32 PM, Christian Grün wrote: >> >> Hi Seenivasan, >> >>> I downloaded a fresh copy of basex and ran the request query that was in >>> my >>> previous email, yet facing the same issue. [...] >> >> to help you, I still need some more concise information.. >> - did you download 7.3 or the latest snapshot? >> - how did you start the http server? >> - which os are you using? >> >>> Just as a curiosity, it would be very helpful, if you could provide me an >>> link/reference to know more about why >> >> The main reason is the internal transaction architecture [1]: if a >> reading query sends a writing query to the same database context, this >> will lead to a deadlock, as the writing query can only be processed if >> no concurrent reading queries are running. >> >> Just a short answer; hope this helps, >> Christian >> >> [1] http://docs.basex.org/wiki/Transaction_Management >> > >
SG
Seenivasan Gunabalan1 Aug 2012 11:05 #
It works (Y) as expected in the snapshot version
Thanks a lot! Christian.
Just to bring to your notice, in the basexhttp shell script (of snapshot version), we experienced the dos to UNIX file format change over and we fixed locally.
Thanks and Regards,
Seenivasan
Quoted text · Christian Grün · 78 lines
On 07/31/2012 08:39 PM, Christian Grün wrote: > Seenivasan, > > got it.. So the problem was that the addressed query module > (http://.../restxq/example) did not exist in your scenario, right? > > I've uploaded a new stable snapshot that includes a fix. It will > return a header and the error message as second item instead of the > error message: > > http://files.basex.org/releases/latest/ > > Looking forward to your feedback, > Christian > ___________________________ > > Christian Grün > Box 188, Uni KN > D-78457 Konstanz > www.christian-gruen.de > > > On Tue, Jul 31, 2012 at 6:07 PM, Seenivasan Gunabalan > <seenivasan.gunabalan at dedalus.eu> wrote: >> Hi Christian, >> Thanks for the link. I will go through it. >> >> >> to help you, I still need some more concise information.. >> >> >> - did you download 7.3 or the latest snapshot? >> >> i downloaded 7.3 and not the snapshot.. >> >> >> >> - how did you start the http server? >> >> ./basexhttp >> >> >> >> - which os are you using? >> >> Ubuntu 11.10 >> Java-7-openjdk-i386 >> >> >> Thanks and Regards, >> Seenivasan >> >> >> >> On 07/31/2012 05:32 PM, Christian Grün wrote: >>> Hi Seenivasan, >>> >>>> I downloaded a fresh copy of basex and ran the request query that was in >>>> my >>>> previous email, yet facing the same issue. [...] >>> to help you, I still need some more concise information.. >>> - did you download 7.3 or the latest snapshot? >>> - how did you start the http server? >>> - which os are you using? >>> >>>> Just as a curiosity, it would be very helpful, if you could provide me an >>>> link/reference to know more about why >>> The main reason is the internal transaction architecture [1]: if a >>> reading query sends a writing query to the same database context, this >>> will lead to a deadlock, as the writing query can only be processed if >>> no concurrent reading queries are running. >>> >>> Just a short answer; hope this helps, >>> Christian >>> >>> [1] http://docs.basex.org/wiki/Transaction_Management >>> >>
CG
Christian Grün1 Aug 2012 13:56 #
Quoted text · Seenivasan Gunabalan · 3 lines
> Just to bring to your notice, in the basexhttp shell script (of snapshot > version), we experienced the dos to UNIX file format change over and we > fixed locally.
Good to know; this will be fixed in the next snaapshot.
Christian
Written for BaseX 7.3. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery