From: Thomas W. <tho...@gm...> - 2010-05-11 06:05:05
|
Loren, I think it will be a good idea to have a default value for the header, saved in a XML file in the file system or even better in /db/system/config/httpclient.xml and to have an option to change it in both cases: a) for the current call and b) change it permanently. If the config file(resource) does not exist, the module has to create it. I hope this will help. Thomas ------ Thomas White Mobile:+44 7711 922 966 Skype: thomaswhite gTalk: thomas.0007 Linked-In:http://www.linkedin.com/in/thomaswhite0007 facebook: http://www.facebook.com/thomas.0007 On 11 May 2010 01:38, Loren Cahlander <lor...@gm...> wrote: > I have some updates about httpclient. I am going to be adding function > signatures to put the authentication down in the java code, so that the > XQuery code does not have to handle that. I will also be adding the user > agent to the httpclient calls, so that the web servers can have eXist > visible in the webstats. > > HttpClient client = *new *HttpClient(); > client.getParams().setParameter("http.useragent", "My Browser"); > > Here is the user agent for Safari on my Mac. > > Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) > AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7 > > I am thinking that the user agent should be something like the following: > > eXist/1.5 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) > ApacheCommonsHttpclient/3.1 > > > On May 10, 2010, at 05:52 PM, Loren Cahlander wrote: > > I need to add authentication to the httpclient function module. I will > be adding the optional parameters of username and password to the functions. > If the call without the username and password returns SC_UNAUTHORIZED ala: > http://www.java2s.com/Code/Java/Apache-Common/BasicAuthenticationGetJSPMethodReturnCode.htm > > <http://www.java2s.com/Code/Java/Apache-Common/BasicAuthenticationGetJSPMethodReturnCode.htm> > Does anyone have any serious objections to this? If you do not add the > username/password combination and the call receives an SC_UNAUTHORIZED, then > it will work as it currently works. > > Loren > > > > > Here are the updated function signatures: > > httpclient <http://localhost:8080/exist/functions/httpclient> > ------------------------------ > http://exist-db.org/xquery/httpclient > A module for performing HTTP requests as a client > clear-all <http://localhost:8080/exist/functions/httpclient/clear-all> > ------------------------------ > httpclient:clear-all() empty() > Clears all persistent state (eg. cookies, crednetials, etc.) stored in > the current session on the client. > delete <http://localhost:8080/exist/functions/httpclient/delete> > ------------------------------ > httpclient:delete($url as xs:anyURI, $persist as xs:boolean, > $request-headers as element()?) item() > Performs a HTTP DELETE request. This method returns the HTTP response > encoded as an XML fragment, that looks as follows: <httpclient:response > xmlns:httpclient="http://exist-db.org/xquery/httpclient" > statusCode="200"><httpclient:headers><httpclient:header name="name" > value="value"/>...</httpclient:headers><httpclient:body > type="xml|xhtml|text|binary" mimetype="returned content mimetype">body > content</httpclient:body></httpclient:response> where XML body content will > be returned as a Node, HTML body content will be tidied into an XML > compatible form, a body with mime-type of "text/..." will be returned as a > URLEncoded string, and any other body content will be returned as > xs:base64Binary encoded data. > $url The URL to process $persist Indicates if the HTTP state (eg. > cookies, credentials, etc.) should persist for the life of this xquery > $request-headers Any HTTP Request Headers to set in the form > <headers><header name="" value=""/></headers> > ------------------------------ > Returns the XML body content > delete <http://localhost:8080/exist/functions/httpclient/delete> > ------------------------------ > httpclient:delete($url as xs:anyURI, $persist as xs:boolean, > $request-headers as element()?, $username as xs:string, $password as > xs:string) item() > Performs a HTTP DELETE request. This method returns the HTTP response > encoded as an XML fragment, that looks as follows: <httpclient:response > xmlns:httpclient="http://exist-db.org/xquery/httpclient" > statusCode="200"><httpclient:headers><httpclient:header name="name" > value="value"/>...</httpclient:headers><httpclient:body > type="xml|xhtml|text|binary" mimetype="returned content mimetype">body > content</httpclient:body></httpclient:response> where XML body content will > be returned as a Node, HTML body content will be tidied into an XML > compatible form, a body with mime-type of "text/..." will be returned as a > URLEncoded string, and any other body content will be returned as > xs:base64Binary encoded data. > $url The URL to process $persist Indicates if the HTTP state (eg. > cookies, credentials, etc.) should persist for the life of this xquery > $request-headers Any HTTP Request Headers to set in the form > <headers><header name="" value=""/></headers> $username The username for > authentication $password The password for authentication > ------------------------------ > Returns the XML body content > get <http://localhost:8080/exist/functions/httpclient/get> > ------------------------------ > httpclient:get($url as xs:anyURI, $persist as xs:boolean, $request-headers > as element()?) item() > Performs a HTTP GET request. This method returns the HTTP response > encoded as an XML fragment, that looks as follows: <httpclient:response > xmlns:httpclient="http://exist-db.org/xquery/httpclient" > statusCode="200"><httpclient:headers><httpclient:header name="name" > value="value"/>...</httpclient:headers><httpclient:body > type="xml|xhtml|text|binary" mimetype="returned content mimetype">body > content</httpclient:body></httpclient:response> where XML body content will > be returned as a Node, HTML body content will be tidied into an XML > compatible form, a body with mime-type of "text/..." will be returned as a > URLEncoded string, and any other body content will be returned as > xs:base64Binary encoded data. > $url The URL to process $persist Indicates if the HTTP state (eg. > cookies, credentials, etc.) should persist for the life of this xquery > $request-headers Any HTTP Request Headers to set in the form > <headers><header name="" value=""/></headers> > ------------------------------ > Returns the XML body content > get <http://localhost:8080/exist/functions/httpclient/get> > ------------------------------ > httpclient:get($url as xs:anyURI, $persist as xs:boolean, $request-headers > as element()?, $username as xs:string, $password as xs:string) item() > Performs a HTTP GET request. This method returns the HTTP response > encoded as an XML fragment, that looks as follows: <httpclient:response > xmlns:httpclient="http://exist-db.org/xquery/httpclient" > statusCode="200"><httpclient:headers><httpclient:header name="name" > value="value"/>...</httpclient:headers><httpclient:body > type="xml|xhtml|text|binary" mimetype="returned content mimetype">body > content</httpclient:body></httpclient:response> where XML body content will > be returned as a Node, HTML body content will be tidied into an XML > compatible form, a body with mime-type of "text/..." will be returned as a > URLEncoded string, and any other body content will be returned as > xs:base64Binary encoded data. > $url The URL to process $persist Indicates if the HTTP state (eg. > cookies, credentials, etc.) should persist for the life of this xquery > $request-headers Any HTTP Request Headers to set in the form > <headers><header name="" value=""/></headers> $username The username for > authentication $password The password for authentication > ------------------------------ > Returns the XML body content > head <http://localhost:8080/exist/functions/httpclient/head> > ------------------------------ > httpclient:head($url as xs:anyURI, $persist as xs:boolean, $request-headers > as element()?) item() > Performs a HTTP HEAD request. This method returns the HTTP response > encoded as an XML fragment, that looks as follows: <httpclient:response > xmlns:httpclient="http://exist-db.org/xquery/httpclient" > statusCode="200"><httpclient:headers><httpclient:header name="name" > value="value"/>...</httpclient:headers></httpclient:response> > $url The URL to process $persist Indicates if the HTTP state (eg. > cookies, credentials, etc.) should persist for the life of this xquery > $request-headers Any HTTP Request Headers to set in the form > <headers><header name="" value=""/></headers> > ------------------------------ > Returns the XML body content > head <http://localhost:8080/exist/functions/httpclient/head> > ------------------------------ > httpclient:head($url as xs:anyURI, $persist as xs:boolean, $request-headers > as element()?, $username as xs:string, $password as xs:string) item() > Performs a HTTP HEAD request. This method returns the HTTP response > encoded as an XML fragment, that looks as follows: <httpclient:response > xmlns:httpclient="http://exist-db.org/xquery/httpclient" > statusCode="200"><httpclient:headers><httpclient:header name="name" > value="value"/>...</httpclient:headers></httpclient:response> > $url The URL to process $persist Indicates if the HTTP state (eg. > cookies, credentials, etc.) should persist for the life of this xquery > $request-headers Any HTTP Request Headers to set in the form > <headers><header name="" value=""/></headers> $username The username for > authentication $password The password for authentication > ------------------------------ > Returns the XML body content > options <http://localhost:8080/exist/functions/httpclient/options> > ------------------------------ > httpclient:options($url as xs:anyURI, $persist as xs:boolean, > $request-headers as element()?) item() > Performs a HTTP OPTIONS request. This method returns the HTTP response > encoded as an XML fragment, that looks as follows: <httpclient:response > xmlns:httpclient="http://exist-db.org/xquery/httpclient" > statusCode="200"><httpclient:headers><httpclient:header name="name" > value="value"/>...</httpclient:headers></httpclient:response> > $url The URL to process $persist Indicates if the HTTP state (eg. > cookies, credentials, etc.) should persist for the life of this xquery > $request-headers Any HTTP Request Headers to set in the form > <headers><header name="" value=""/></headers> > ------------------------------ > Returns the XML body content > options <http://localhost:8080/exist/functions/httpclient/options> > ------------------------------ > httpclient:options($url as xs:anyURI, $persist as xs:boolean, > $request-headers as element()?, $username as xs:string, $password as > xs:string) item() > Performs a HTTP OPTIONS request. This method returns the HTTP response > encoded as an XML fragment, that looks as follows: <httpclient:response > xmlns:httpclient="http://exist-db.org/xquery/httpclient" > statusCode="200"><httpclient:headers><httpclient:header name="name" > value="value"/>...</httpclient:headers></httpclient:response> > $url The URL to process $persist Indicates if the HTTP state (eg. > cookies, credentials, etc.) should persist for the life of this xquery > $request-headers Any HTTP Request Headers to set in the form > <headers><header name="" value=""/></headers> $username The username for > authentication $password The password for authentication > ------------------------------ > Returns the XML body content > post <http://localhost:8080/exist/functions/httpclient/post> > ------------------------------ > httpclient:post($url as xs:anyURI, $content as item(), $persist as > xs:boolean, $request-headers as element()?) item() > Performs a HTTP POST request. This method returns the HTTP response > encoded as an XML fragment, that looks as follows: <httpclient:response > xmlns:httpclient="http://exist-db.org/xquery/httpclient" > statusCode="200"><httpclient:headers><httpclient:header name="name" > value="value"/>...</httpclient:headers><httpclient:body > type="xml|xhtml|text|binary" mimetype="returned content mimetype">body > content</httpclient:body></httpclient:response> where XML body content will > be returned as a Node, HTML body content will be tidied into an XML > compatible form, a body with mime-type of "text/..." will be returned as a > URLEncoded string, and any other body content will be returned as > xs:base64Binary encoded data. > $url The URL to process $content The XML POST payload/content. If it > is an XML Node it will be serialized, any other type will be atomized into a > string. $persist Indicates if the HTTP state (eg. cookies, credentials, > etc.) should persist for the life of this xquery $request-headers Any > HTTP Request Headers to set in the form <headers><header name="" > value=""/></headers> > ------------------------------ > Returns the XML body content > post <http://localhost:8080/exist/functions/httpclient/post> > ------------------------------ > httpclient:post($url as xs:anyURI, $content as item(), $persist as > xs:boolean, $request-headers as element()?, $username as xs:string, > $password as xs:string) item() > Performs a HTTP POST request. This method returns the HTTP response > encoded as an XML fragment, that looks as follows: <httpclient:response > xmlns:httpclient="http://exist-db.org/xquery/httpclient" > statusCode="200"><httpclient:headers><httpclient:header name="name" > value="value"/>...</httpclient:headers><httpclient:body > type="xml|xhtml|text|binary" mimetype="returned content mimetype">body > content</httpclient:body></httpclient:response> where XML body content will > be returned as a Node, HTML body content will be tidied into an XML > compatible form, a body with mime-type of "text/..." will be returned as a > URLEncoded string, and any other body content will be returned as > xs:base64Binary encoded data. > $url The URL to process $content The XML POST payload/content. If it > is an XML Node it will be serialized, any other type will be atomized into a > string. $persist Indicates if the HTTP state (eg. cookies, credentials, > etc.) should persist for the life of this xquery $request-headers Any > HTTP Request Headers to set in the form <headers><header name="" > value=""/></headers> $username The username for authentication $password The > password for authentication > ------------------------------ > Returns the XML body content > post-form <http://localhost:8080/exist/functions/httpclient/post-form> > ------------------------------ > httpclient:post-form($url as xs:anyURI, $content as element(), $persist as > xs:boolean, $request-headers as element()?) item() > Performs a HTTP POST request for a form. This method returns the HTTP > response encoded as an XML fragment, that looks as follows: > <httpclient:response xmlns:httpclient=" > http://exist-db.org/xquery/httpclient" > statusCode="200"><httpclient:headers><httpclient:header name="name" > value="value"/>...</httpclient:headers><httpclient:body > type="xml|xhtml|text|binary" mimetype="returned content mimetype">body > content</httpclient:body></httpclient:response> where XML body content will > be returned as a Node, HTML body content will be tidied into an XML > compatible form, a body with mime-type of "text/..." will be returned as a > URLEncoded string, and any other body content will be returned as > xs:base64Binary encoded data. > $url The URL to process $content The form data in the format > <httpclient:fields><httpclient:field name="" value="" > type="string|file"/>...</httpclient:fields>. If the field values will be > suitably URLEncoded and sent with the mime type > application/x-www-form-urlencoded. $persist Indicates if the HTTP state > (eg. cookies, credentials, etc.) should persist for the life of this xquery > $request-headers Any HTTP Request Headers to set in the form > <headers><header name="" value=""/></headers> > ------------------------------ > Returns the XML body content > post-form <http://localhost:8080/exist/functions/httpclient/post-form> > ------------------------------ > httpclient:post-form($url as xs:anyURI, $content as element(), $persist as > xs:boolean, $request-headers as element()?, $username as xs:string, > $password as xs:string) item() > Performs a HTTP POST request for a form. This method returns the HTTP > response encoded as an XML fragment, that looks as follows: > <httpclient:response xmlns:httpclient=" > http://exist-db.org/xquery/httpclient" > statusCode="200"><httpclient:headers><httpclient:header name="name" > value="value"/>...</httpclient:headers><httpclient:body > type="xml|xhtml|text|binary" mimetype="returned content mimetype">body > content</httpclient:body></httpclient:response> where XML body content will > be returned as a Node, HTML body content will be tidied into an XML > compatible form, a body with mime-type of "text/..." will be returned as a > URLEncoded string, and any other body content will be returned as > xs:base64Binary encoded data. > $url The URL to process $content The form data in the format > <httpclient:fields><httpclient:field name="" value="" > type="string|file"/>...</httpclient:fields>. If the field values will be > suitably URLEncoded and sent with the mime type > application/x-www-form-urlencoded. $persist Indicates if the HTTP state > (eg. cookies, credentials, etc.) should persist for the life of this xquery > $request-headers Any HTTP Request Headers to set in the form > <headers><header name="" value=""/></headers> $username The username for > authentication $password The password for authentication > ------------------------------ > Returns the XML body content > put <http://localhost:8080/exist/functions/httpclient/put> > ------------------------------ > httpclient:put($url as xs:anyURI, $content as node(), $persist as > xs:boolean, $request-headers as element()?) item() > Performs a HTTP PUT request.. This method returns the HTTP response > encoded as an XML fragment, that looks as follows: <httpclient:response > xmlns:httpclient="http://exist-db.org/xquery/httpclient" > statusCode="200"><httpclient:headers><httpclient:header name="name" > value="value"/>...</httpclient:headers><httpclient:body > type="xml|xhtml|text|binary" mimetype="returned content mimetype">body > content</httpclient:body></httpclient:response> where XML body content will > be returned as a Node, HTML body content will be tidied into an XML > compatible form, a body with mime-type of "text/..." will be returned as a > URLEncoded string, and any other body content will be returned as > xs:base64Binary encoded data. > $url The URL to process $content The XML PUT payload/content. If it is > an XML Node it will be serialized, any other type will be atomized into a > string. $persist Indicates if the HTTP state (eg. cookies, credentials, > etc.) should persist for the life of this xquery $request-headers Any > HTTP Request Headers to set in the form <headers><header name="" > value=""/></headers> > ------------------------------ > Returns the XML body content > put <http://localhost:8080/exist/functions/httpclient/put> > ------------------------------ > httpclient:put($url as xs:anyURI, $content as node(), $persist as > xs:boolean, $request-headers as element()?, $username as xs:string, > $password as xs:string) item() > Performs a HTTP PUT request.. This method returns the HTTP response > encoded as an XML fragment, that looks as follows: <httpclient:response > xmlns:httpclient="http://exist-db.org/xquery/httpclient" > statusCode="200"><httpclient:headers><httpclient:header name="name" > value="value"/>...</httpclient:headers><httpclient:body > type="xml|xhtml|text|binary" mimetype="returned content mimetype">body > content</httpclient:body></httpclient:response> where XML body content will > be returned as a Node, HTML body content will be tidied into an XML > compatible form, a body with mime-type of "text/..." will be returned as a > URLEncoded string, and any other body content will be returned as > xs:base64Binary encoded data. > $url The URL to process $content The XML PUT payload/content. If it is > an XML Node it will be serialized, any other type will be atomized into a > string. $persist Indicates if the HTTP state (eg. cookies, credentials, > etc.) should persist for the life of this xquery $request-headers Any > HTTP Request Headers to set in the form <headers><header name="" > value=""/></headers> $username The username for authentication $password The > password for authentication > ------------------------------ > Returns the XML body content > > > > ------------------------------------------------------------------------------ > > > _______________________________________________ > Exist-development mailing list > Exi...@li... > https://lists.sourceforge.net/lists/listinfo/exist-development > > |