From: Loren C. <lor...@gm...> - 2010-05-11 00:53:31
|
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 > > 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://exist-db.org/xquery/httpclient A module for performing HTTP requests as a client clear-all httpclient:clear-all() empty() Clears all persistent state (eg. cookies, crednetials, etc.) stored in the current session on the client. 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 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 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 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 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 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 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 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 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 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 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 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 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 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 |