Thread: [Xsltforms-support] XSLTForms and REST
Brought to you by:
alain-couthures
From: Stephen C. <Ste...@ut...> - 2011-01-05 22:38:48
|
Hello All, I have been reading up on REST, there is quite a bit more to it than I first imagined. Its essential to be able to read and set header information in the client, such as to read the "Location" header in a POST response to extract a newly generated resource id. I'm wondering if anyone has looked at this in respect of XSLTForms? Cheers Steve Cameron |
From: Grégoire C. <gco...@gm...> - 2011-02-11 15:32:17
|
Le 05/01/2011 23:38, Stephen Cameron a écrit : > > Hello All, > > > > I have been reading up on REST, there is quite a bit more to it than I > first imagined. > > > > Its essential to be able to read and set header information in the > client, such as to read the "Location" header in a POST response to > extract a newly generated resource id. > > > > I'm wondering if anyone has looked at this in respect of XSLTForms? > Hi Stephen! I'm facing the same question! I would like to read the HTTP status code from XSLTForms. Have you succeeded in doing this? Thanks! Grégoire |
From: Efraim F. <efr...@gm...> - 2011-02-11 15:59:05
|
Hi, On 02/11/2011 08:06 AM, Grégoire COLBERT wrote: > Le 05/01/2011 23:38, Stephen Cameron a écrit : >> >> Hello All, >> >> I have been reading up on REST, there is quite a bit more to it than >> I first imagined. >> >> Its essential to be able to read and set header information in the >> client, such as to read the "Location" header in a POST response to >> extract a newly generated resource id. >> >> I'm wondering if anyone has looked at this in respect of XSLTForms? >> > > Hi Stephen! > > I'm facing the same question! I would like to read the HTTP status > code from XSLTForms. Have you succeeded in doing this? There are essentially 2 ways (that I know of) to set headers: One of them is to set a session cookie, which is passed back in the response header and automatically passed in the request header of subsequent HTTP requests. It's somewhat un-REST-like in the strict sense, but you can use a REST-like design on the server side and treat the information in it like any other header-based information. The advantage of them is that your client side web application doesn't have to pass internal variables between pages. The second is the xf:header element as a child of the xf:submission element. It does work in XSLTForms. To get response codes, the XForms spec says that you should be able to catch xf:submit-done or xf:submit-error and use the event() function to get the response codes and reasons, as described in http://www.w3.org/TR/xforms11/#submit . As far as I could tell, it doesn't work in XSLTForms. One way to work around the latter issue is to catch the error in your server side script before it returns and send back some XML describing the error/error code to the client, which can then handle xforms-submit-done differently if it receives the error code (the conditional xf:action/@if is helpful here). It's ugly, but it does work. Hope this helps, -- --- Efraim Feinstein Lead Developer Open Siddur Project http://opensiddur.net http://wiki.jewishliturgy.org |
From: Grégoire C. <gco...@gm...> - 2011-02-11 16:53:16
|
Hi! Le 11/02/2011 16:58, Efraim Feinstein a écrit : > To get response codes, the XForms spec says that you should be able to > catch xf:submit-done or xf:submit-error and use the event() function > to get the response codes and reasons, as described in > http://www.w3.org/TR/xforms11/#submit . As far as I could tell, it > doesn't work in XSLTForms. Very bad news! Alain, is this something that will be implemented someday? Is it difficult to read the HTTP status code from JavaScript? > One way to work around the latter issue is to catch the error in your > server side script before it returns and send back some XML describing > the error/error code to the client, which can then handle > xforms-submit-done differently if it receives the error code (the > conditional xf:action/@if is helpful here). It's ugly, but it does work. Well, using XML error codes is what I do at the moment. But as I got a better understanding of REST <http://library.dzone.com/sites/all/files/refcardz/rc129-010d-rest_1.pdf>, I want to make my server RESTful level 2 and this requires the use of HTTP status codes. Thank you for your answer Efraim! Best regards, Grégoire |
From: COUTHURES A. <ala...@ag...> - 2011-02-12 19:16:02
|
Grégoire, Efraim, I have extended excellent Kostis' implementation of event contexts to support response headers and response code for both xforms-submit-done and xforms-submit-error. Thank you for your feedbacks! -Alain Le 11/02/2011 17:52, Grégoire COLBERT a écrit : > Hi! > > Le 11/02/2011 16:58, Efraim Feinstein a écrit : >> To get response codes, the XForms spec says that you should be able >> to catch xf:submit-done or xf:submit-error and use the event() >> function to get the response codes and reasons, as described in >> http://www.w3.org/TR/xforms11/#submit . As far as I could tell, it >> doesn't work in XSLTForms. > > Very bad news! Alain, is this something that will be implemented > someday? Is it difficult to read the HTTP status code from JavaScript? > >> One way to work around the latter issue is to catch the error in your >> server side script before it returns and send back some XML >> describing the error/error code to the client, which can then handle >> xforms-submit-done differently if it receives the error code (the >> conditional xf:action/@if is helpful here). It's ugly, but it does work. > > Well, using XML error codes is what I do at the moment. But as I got a > better understanding of REST > <http://library.dzone.com/sites/all/files/refcardz/rc129-010d-rest_1.pdf>, > I want to make my server RESTful level 2 and this requires the use of > HTTP status codes. > > Thank you for your answer Efraim! > > Best regards, > Grégoire > > > ------------------------------------------------------------------------------ > The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE: > Pinpoint memory and threading errors before they happen. > Find and fix more than 250 security defects in the development cycle. > Locate bottlenecks in serial and parallel code that limit performance. > http://p.sf.net/sfu/intel-dev2devfeb > > > _______________________________________________ > Xsltforms-support mailing list > Xsl...@li... > https://lists.sourceforge.net/lists/listinfo/xsltforms-support |
From: Efraim F. <efr...@gm...> - 2011-02-12 23:04:50
|
On 02/12/2011 02:16 PM, COUTHURES Alain wrote: > Grégoire, Efraim, > > I have extended excellent Kostis' implementation of event contexts to > support response headers and response code for both xforms-submit-done > and xforms-submit-error. > In which branch? -- --- Efraim Feinstein Lead Developer Open Siddur Project http://opensiddur.net http://wiki.jewishliturgy.org |
From: Efraim F. <efr...@gm...> - 2011-02-13 03:30:40
|
xquery version "1.0"; (: demo of bug where an initially out-of-range selection goes in-range : but the UI still shows it's out of range :) declare default element namespace "http://www.w3.org/1999/xhtml"; declare namespace xf="http://www.w3.org/2002/xforms"; declare namespace ev="http://www.w3.org/2001/xml-events"; declare option exist:serialize "method=xhtml media-type=text/xml indent=yes omit-xml-declaration=no process-xsl-pi=no doctype-public=-//W3C//DTD XHTML 1.1//EN doctype-system=http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"; processing-instruction {'xml-stylesheet'}{'type="text/xsl" href="/xforms/xsltforms/xsltforms.xsl"'}, processing-instruction {'xsltforms-options'}{'debug="yes"'}, <html> <head> <title>Bug demo</title> <xf:model> <xf:instance id="test"> <result xmlns=""> <something>tosend</something> </result> </xf:instance> <xf:submission ref="instance('test')" id="submit" method="get" action="event-submit.xql" instance="test" replace="instance"> <xf:message ev:event="xforms-submit-error"> An error has happened! type: <xf:output value="event('response-status-code')"/> reason: <xf:output value="event('response-reason-phrase')"/> </xf:message> </xf:submission> </xf:model> </head> <body> <div> <xf:submit submission="submit"> <xf:label>Get an error</xf:label> </xf:submit> </div> </body> </html> |
From: Grégoire C. <gco...@gm...> - 2011-02-13 17:36:45
|
Hi! Le 13/02/2011 04:30, Efraim Feinstein a écrit : > Hi, > Never mind. I see that r480 has some new code in it for response > headers. I tried it with the attached code. I'm finding that it does > give the correct 404 error message when you press the button, but it > also returns a long error message in a popup dialog when the page is > first loaded. > > The text of the error is: > XSLTForms Exception > -------------------------- > (...) I get the same initialization error, but I don't get any output (the pop-up is not displayed and no JS error is raised). I use: <xf:action ev:event="xforms-submit-done"> <xf:message><xf:output value="event('response-status-code')"/></xf:message> </xf:action> This is based on the example at : http://www.w3.org/TR/xforms11/#submit-evt-submit-done Anyway, thank you Alain for your very quick answer! Best regards, Grégoire |
From: Grégoire C. <gco...@gm...> - 2011-02-23 16:52:46
|
Hi, I don't know what the "req.status = 0" case is for, but for sure I forgot about it! The fix should be: if ((req.status != 0 && req.status < 200) || req.status >= 300) { evcontext["error-type"] = "resource-error"; subm.issueSubmitException_(evcontext, req, null); xforms.closeAction(); return; } Hope this is right, now! :-) Regards, Grégoire Le 23/02/2011 17:43, Grégoire COLBERT a écrit : > Me again! > > I found where the problem comes from! Not from the > "xforms-submit-done" event, but from my 201 return code (XSLTForms rev > 484 only expects 200). > > *Fix:* in function "XFSubmission.prototype.submit", replace: > > if (req.status != 200 && req.status != 0) { > evcontext["error-type"] = "resource-error"; > subm.issueSubmitException_(evcontext, req, null); > xforms.closeAction(); > return; > } > > with : > > if (req.status < 200 || req.status >= 300) { > evcontext["error-type"] = "resource-error"; > subm.issueSubmitException_(evcontext, req, null); > xforms.closeAction(); > return; > } > > Just tested it and it works fine! Very cool! > > Cheers, > Grégoire > > > Le 23/02/2011 17:02, Grégoire COLBERT a écrit : >> Hi! >> >> Another problem I encountered (r484) is that it only works with >> "xforms-submit-error" and not with "xforms-submit-done". >> >> Non-working (but valid) example: >> >> <xf:action ev:event="*xforms-submit-done*" >> if="event('response-status-code') = 201"> >> <xf:message>Response is 201, good!</xf:message> >> </xf:action> >> >> Working (but non-valid) example: >> >> <xf:action ev:event="*xforms-submit-error*" >> if="event('response-status-code') = 201"> >> <xf:message>Response is 201, good!</xf:message> >> </xf:action> >> >> As you know, status-codes 2xx are not errors but successes. >> >> According to: >> http://www.w3.org/TR/xforms11/#submit-evt-submit-done >> this looks like a bug. >> >> Best regards, >> Grégoire >> >> PS : Efraim is right, the 'response-body' header does something strange. >> >> Le 22/02/2011 17:14, Efraim Feinstein a écrit : >>> Hi, >>> >>> I made a little more progress understanding the failures involving >>> responses/REST errors. I'm using dataisland branch r484. >>> >>> The attached code demonstrates that if you receive an error, it will >>> invoke the error handler and show the message. >>> >>> If, however the 'response-body' event is referenced (uncomment it in >>> the example), the event handler never occurs. That may be why >>> Grégoire and I were getting different results. >>> >>> Hope this helps, >>> -Efraim >>> >>> On 02/13/2011 10:49 AM, Grégoire COLBERT wrote: >>>> Hi! >>>> >>>> Le 13/02/2011 04:30, Efraim Feinstein a écrit : >>>>> Hi, >>>>> Never mind. I see that r480 has some new code in it for response >>>>> headers. I tried it with the attached code. I'm finding that it >>>>> does give the correct 404 error message when you press the button, >>>>> but it also returns a long error message in a popup dialog when >>>>> the page is first loaded. >>>>> >>>>> The text of the error is: >>>>> XSLTForms Exception >>>>> -------------------------- >>>>> (...) >>>> >>>> I get the same initialization error, but I don't get any output >>>> (the pop-up is not displayed and no JS error is raised). >>>> >>>> I use: >>>> >>>> <xf:action ev:event="xforms-submit-done"> >>>> <xf:message><xf:output >>>> value="event('response-status-code')"/></xf:message> >>>> </xf:action> >>>> >>>> This is based on the example at : >>>> http://www.w3.org/TR/xforms11/#submit-evt-submit-done >>>> >>>> Anyway, thank you Alain for your very quick answer! >>>> >>>> Best regards, >>>> Grégoire >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE: >>>> Pinpoint memory and threading errors before they happen. >>>> Find and fix more than 250 security defects in the development cycle. >>>> Locate bottlenecks in serial and parallel code that limit performance. >>>> http://p.sf.net/sfu/intel-dev2devfeb >>>> >>>> >>>> _______________________________________________ >>>> Xsltforms-support mailing list >>>> Xsl...@li... >>>> https://lists.sourceforge.net/lists/listinfo/xsltforms-support >>>> >>> >>> >>> -- >>> --- >>> Efraim Feinstein >>> Lead Developer >>> Open Siddur Project >>> http://opensiddur.net >>> http://wiki.jewishliturgy.org >>> >>> >>> ------------------------------------------------------------------------------ >>> Index, Search & Analyze Logs and other IT data in Real-Time with Splunk >>> Collect, index and harness all the fast moving IT data generated by your >>> applications, servers and devices whether physical, virtual or in the cloud. >>> Deliver compliance at lower cost and gain new business insights. >>> Free Software Download: http://p.sf.net/sfu/splunk-dev2dev >>> >>> >>> _______________________________________________ >>> Xsltforms-support mailing list >>> Xsl...@li... >>> https://lists.sourceforge.net/lists/listinfo/xsltforms-support >> > |
From: Efraim F. <efr...@gm...> - 2011-02-24 16:57:18
|
Hi Alain, I retried my test form on r485, and it is now working. Thanks! -- --- Efraim Feinstein Lead Developer Open Siddur Project http://opensiddur.net http://wiki.jewishliturgy.org |
From: Efraim F. <efr...@gm...> - 2011-02-22 16:14:37
Attachments:
do-error.xql
|
xquery version "1.0"; declare default element namespace "http://www.w3.org/1999/xhtml"; declare namespace xf="http://www.w3.org/2002/xforms"; declare namespace ev="http://www.w3.org/2001/xml-events"; declare option exist:serialize "method=xhtml media-type=text/xml indent=yes omit-xml-declaration=no process-xsl-pi=no doctype-public=-//W3C//DTD XHTML 1.1//EN doctype-system=http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"; processing-instruction {'xml-stylesheet'}{'type="text/xsl" href="/xforms/xsltforms/xsltforms.xsl"'}, processing-instruction {'xsltforms-options'}{'debug="yes"'}, <html> <head> <title>Make error</title> <xf:model> <xf:instance id="blank"> <blank xmlns=""/> </xf:instance> <xf:submission ref="instance('blank')" id="error-submit" method="get" action="do-error.xql" replace="none"> <xf:action ev:event="xforms-submit-error"> <xf:message> An error occurred. type: <xf:output value="event('error-type')"/> code: <xf:output value="event('response-status-code')"/> headers: <xf:output value="event('response-headers')"/> body: <!--xf:output value="event('response-body')"/--> </xf:message> </xf:action> </xf:submission> </xf:model> </head> <body> <div> <xf:submit submission="error-submit"> <xf:label>Error</xf:label> </xf:submit> </div> </body> </html> |
From: Grégoire C. <gco...@gm...> - 2011-02-23 16:02:32
|
Hi! Another problem I encountered (r484) is that it only works with "xforms-submit-error" and not with "xforms-submit-done". Non-working (but valid) example: <xf:action ev:event="*xforms-submit-done*" if="event('response-status-code') = 201"> <xf:message>Response is 201, good!</xf:message> </xf:action> Working (but non-valid) example: <xf:action ev:event="*xforms-submit-error*" if="event('response-status-code') = 201"> <xf:message>Response is 201, good!</xf:message> </xf:action> As you know, status-codes 2xx are not errors but successes. According to: http://www.w3.org/TR/xforms11/#submit-evt-submit-done this looks like a bug. Best regards, Grégoire PS : Efraim is right, the 'response-body' header does something strange. Le 22/02/2011 17:14, Efraim Feinstein a écrit : > Hi, > > I made a little more progress understanding the failures involving > responses/REST errors. I'm using dataisland branch r484. > > The attached code demonstrates that if you receive an error, it will > invoke the error handler and show the message. > > If, however the 'response-body' event is referenced (uncomment it in > the example), the event handler never occurs. That may be why Grégoire > and I were getting different results. > > Hope this helps, > -Efraim > > On 02/13/2011 10:49 AM, Grégoire COLBERT wrote: >> Hi! >> >> Le 13/02/2011 04:30, Efraim Feinstein a écrit : >>> Hi, >>> Never mind. I see that r480 has some new code in it for response >>> headers. I tried it with the attached code. I'm finding that it >>> does give the correct 404 error message when you press the button, >>> but it also returns a long error message in a popup dialog when the >>> page is first loaded. >>> >>> The text of the error is: >>> XSLTForms Exception >>> -------------------------- >>> (...) >> >> I get the same initialization error, but I don't get any output (the >> pop-up is not displayed and no JS error is raised). >> >> I use: >> >> <xf:action ev:event="xforms-submit-done"> >> <xf:message><xf:output >> value="event('response-status-code')"/></xf:message> >> </xf:action> >> >> This is based on the example at : >> http://www.w3.org/TR/xforms11/#submit-evt-submit-done >> >> Anyway, thank you Alain for your very quick answer! >> >> Best regards, >> Grégoire >> >> >> ------------------------------------------------------------------------------ >> The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE: >> Pinpoint memory and threading errors before they happen. >> Find and fix more than 250 security defects in the development cycle. >> Locate bottlenecks in serial and parallel code that limit performance. >> http://p.sf.net/sfu/intel-dev2devfeb >> >> >> _______________________________________________ >> Xsltforms-support mailing list >> Xsl...@li... >> https://lists.sourceforge.net/lists/listinfo/xsltforms-support >> > > > -- > --- > Efraim Feinstein > Lead Developer > Open Siddur Project > http://opensiddur.net > http://wiki.jewishliturgy.org > > > ------------------------------------------------------------------------------ > Index, Search & Analyze Logs and other IT data in Real-Time with Splunk > Collect, index and harness all the fast moving IT data generated by your > applications, servers and devices whether physical, virtual or in the cloud. > Deliver compliance at lower cost and gain new business insights. > Free Software Download: http://p.sf.net/sfu/splunk-dev2dev > > > _______________________________________________ > Xsltforms-support mailing list > Xsl...@li... > https://lists.sourceforge.net/lists/listinfo/xsltforms-support |
From: Grégoire C. <gco...@gm...> - 2011-02-23 16:43:58
|
Me again! I found where the problem comes from! Not from the "xforms-submit-done" event, but from my 201 return code (XSLTForms rev 484 only expects 200). *Fix:* in function "XFSubmission.prototype.submit", replace: if (req.status != 200 && req.status != 0) { evcontext["error-type"] = "resource-error"; subm.issueSubmitException_(evcontext, req, null); xforms.closeAction(); return; } with : if (req.status < 200 || req.status >= 300) { evcontext["error-type"] = "resource-error"; subm.issueSubmitException_(evcontext, req, null); xforms.closeAction(); return; } Just tested it and it works fine! Very cool! Cheers, Grégoire Le 23/02/2011 17:02, Grégoire COLBERT a écrit : > Hi! > > Another problem I encountered (r484) is that it only works with > "xforms-submit-error" and not with "xforms-submit-done". > > Non-working (but valid) example: > > <xf:action ev:event="*xforms-submit-done*" > if="event('response-status-code') = 201"> > <xf:message>Response is 201, good!</xf:message> > </xf:action> > > Working (but non-valid) example: > > <xf:action ev:event="*xforms-submit-error*" > if="event('response-status-code') = 201"> > <xf:message>Response is 201, good!</xf:message> > </xf:action> > > As you know, status-codes 2xx are not errors but successes. > > According to: > http://www.w3.org/TR/xforms11/#submit-evt-submit-done > this looks like a bug. > > Best regards, > Grégoire > > PS : Efraim is right, the 'response-body' header does something strange. > > Le 22/02/2011 17:14, Efraim Feinstein a écrit : >> Hi, >> >> I made a little more progress understanding the failures involving >> responses/REST errors. I'm using dataisland branch r484. >> >> The attached code demonstrates that if you receive an error, it will >> invoke the error handler and show the message. >> >> If, however the 'response-body' event is referenced (uncomment it in >> the example), the event handler never occurs. That may be why >> Grégoire and I were getting different results. >> >> Hope this helps, >> -Efraim >> >> On 02/13/2011 10:49 AM, Grégoire COLBERT wrote: >>> Hi! >>> >>> Le 13/02/2011 04:30, Efraim Feinstein a écrit : >>>> Hi, >>>> Never mind. I see that r480 has some new code in it for response >>>> headers. I tried it with the attached code. I'm finding that it >>>> does give the correct 404 error message when you press the button, >>>> but it also returns a long error message in a popup dialog when the >>>> page is first loaded. >>>> >>>> The text of the error is: >>>> XSLTForms Exception >>>> -------------------------- >>>> (...) >>> >>> I get the same initialization error, but I don't get any output (the >>> pop-up is not displayed and no JS error is raised). >>> >>> I use: >>> >>> <xf:action ev:event="xforms-submit-done"> >>> <xf:message><xf:output >>> value="event('response-status-code')"/></xf:message> >>> </xf:action> >>> >>> This is based on the example at : >>> http://www.w3.org/TR/xforms11/#submit-evt-submit-done >>> >>> Anyway, thank you Alain for your very quick answer! >>> >>> Best regards, >>> Grégoire >>> >>> >>> ------------------------------------------------------------------------------ >>> The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE: >>> Pinpoint memory and threading errors before they happen. >>> Find and fix more than 250 security defects in the development cycle. >>> Locate bottlenecks in serial and parallel code that limit performance. >>> http://p.sf.net/sfu/intel-dev2devfeb >>> >>> >>> _______________________________________________ >>> Xsltforms-support mailing list >>> Xsl...@li... >>> https://lists.sourceforge.net/lists/listinfo/xsltforms-support >>> >> >> >> -- >> --- >> Efraim Feinstein >> Lead Developer >> Open Siddur Project >> http://opensiddur.net >> http://wiki.jewishliturgy.org >> >> >> ------------------------------------------------------------------------------ >> Index, Search & Analyze Logs and other IT data in Real-Time with Splunk >> Collect, index and harness all the fast moving IT data generated by your >> applications, servers and devices whether physical, virtual or in the cloud. >> Deliver compliance at lower cost and gain new business insights. >> Free Software Download: http://p.sf.net/sfu/splunk-dev2dev >> >> >> _______________________________________________ >> Xsltforms-support mailing list >> Xsl...@li... >> https://lists.sourceforge.net/lists/listinfo/xsltforms-support > |