After some testing, it appears that xdmp:http-get doesn't like xdmp:xdmp:url-encode output, but it's okay with fn:encode-for-uri. The call is to a self-signed SSL appserver. This works:

let $rest-url := 
  concat($url, 
  'v1/values/uris?options=uris&format=xml&structuredQuery=',
  fn:encode-for-uri(xdmp:quote($q)))
return
xdmp:http-get($url,
<options xmlns="xdmp:document-get" xmlns:http="xdmp:http">{ 
   element http:authentication {
     element http:username { 'user' },
     element http:password { 'pass' }
   } }
  <http:verify-cert>false</http:verify-cert>
</options>)

But swapping fn:encode-for-uri for xdmp:url-encode results in a 401 error:

<response xmlns="xdmp:http">
    <code>401</code>
    <message>Unauthorized</message>
    <headers>
      <www-authenticate>Digest realm="public", qop="auth", nonce="c975aeaf1b6774e1a51f5b30d9ca7c61", opaque="a08df0deda23d70d"</www-authenticate>
      <content-type>application/xml</content-type>
      <server>MarkLogic</server>
      <content-length>211</content-length>
      <connection>close</connection>
    </headers>
  </response>
  <rapi:error xmlns:rapi="http://marklogic.com/rest-api">
    <rapi:status-code>401</rapi:status-code>
    <rapi:status>Failed Auth</rapi:status>
    <rapi:message-code/>
    <rapi:message>Unauthenticated</rapi:message>
  </rapi:error>

I tested saving the output of both functions to a local file and using those strings to hit the endpoint from a browser, and they both worked. Is this a bug or something I likely don't understand about http-get and/or url-encode?

-Will


From: Charles Greer <[email protected]>
Organization: MarkLogic Corporation
Reply-To: MarkLogic Discussion <[email protected]>
Date: Wednesday, February 20, 2013 4:24 PM
To: MarkLogic Discussion <[email protected]>
Subject: Re: [MarkLogic Dev General] Dynamically building a structured query

Hi Will,

What's wrong with double quotes?

Are you looking to encode the whole shebang? How about

concat($url, 
       $path, 
       "?options=uris&amp;structuredQuery=",
       xdmp:url-encode(xdmp:quote($structured-query-xml)))

Charles


On 02/20/2013 04:06 PM, Will Thompson wrote:
This is kind of a pedantic style-related question, but I am building a 
structured query and want to submit it to the REST values endpoint. However, 
that endpoint doesn't like double quotes, so I can't do something tidy like: 
concat($url, $path, "?options=uris&amp;structuredQuery=", 
xdmp:quote($structured-query-xml)) because xdmp:quote outputs double quotes for 
the namespace declaration. I tried POSTing the XML, but the values endpoint only 
accepts GET requests (?). I couldn't find an option to force xdmp:quote to 
serialize attributes using single quotes (maybe that’s not technically allowed?).

Is there a better way to approach this, or is my best option to just replace the 
double quotes from xdmp:quote output?

-Will




_______________________________________________
General mailing list
[email protected]http://developer.marklogic.com/mailman/listinfo/general

-- 
Charles Greer
Senior Engineer
MarkLogic Corporation
[email protected]
Phone: +1 707 408 3277
www.marklogic.com
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to