HI Pragya.
I did not supply you with the exact issue as I did not try to install and
run all 900 lines of code. INstead, I looked at items that seemed suspect
for you to log and verify what is happening with the data between the
rewriter and the invoker. I am still not convinced that you have the XML
you expect at the very early stages. IN fact, I'm not convinced that you
ever retrieve it from the start and even once you do, I still believe you
need to use xdmp:unquote. That's why I suggested you look in those two sets
of code (qualifying this suggestion by experience and not having actually
found your issue exactly.).
But now that there is a log related to some code, lets walk through this:
[as provided by you today]
"
I tried logging in invoker:
let $_populate-map := for $each-param in $urlParams
let $param-value :=
xdmp:get-request-field($each-param)
let $_ :=
xdmp:log(fn:concat("$param-value",$param-value))
...
logs:
2014-10-17 11:16:29.008 Info: rest-ingestion:
module-invoker.xqy?format=xml&moduleName=add-document&requestDirectory=add&apiVersion=v1
2014-10-17 11:16:29.013 Info: rest-ingestion: $param-value*xml*
2014-10-17 11:16:29.013 Info: rest-ingestion: $param-valueadd-document
2014-10-17 11:16:29.013 Info: rest-ingestion: $param-valueadd
2014-10-17 11:16:29.013 Info: rest-ingestion: $param-valuev1
2014-10-17 11:16:29.013 Info: rest-ingestion:
$param-value39932186-9cab-44e9-8f4f-7ebf45dabf8f
2014-10-17 11:16:29.309 Info: rest-ingestion: Ingestion Service End
Point add-document.xqy 39932186-9cab-44e9-8f4f-7ebf45dabf8f
2014-10-17 11:16:29.309 Info: rest-ingestion:
Path/processing/39932186-9cab-44e9-8f4f-7ebf45dabf8f/validDocs/
2014-10-17 11:16:29.309 Info: rest-ingestion:
uri/docs/BONY_4076_REPO-GMR-2000.xml
So its xml at this stage.
"
1) Lets look at the log:
The first thing I note is that you state that you do have XML and you made
bold a line above. I believe you are being mislead by showing
"$param-value" instead of the actual name of the parameter. From what I
see, the *XML *that you made bold is nothing more than the value of the
FORMAT parameter from your query string and not at all related to your XML
content you are looking for. You can verify this with a cleaner log line
and see what request field name is matching the value.
2) OK.. The where IS the content? Lets go back to an earlier message:
You POST the data.
So, now we have to think about how MarkLogic handles the body of a POST
(not something for you to control in your code, but by the REQUEST header:
- IF and only IF the request header*
content-type: application/x-www-form-urlencoded* was present in the
request, then the content of the request body is available via
xdmp:get-request field()
- Otherwise: The content is still stuck in the body and needs to be
retrieved via xdmp:get-request-body()
So, since you use POST, you also have to go back and verify if you are
forcing the content-type: application/x-www-form-urlencoded header. Only
then will you know where to troubleshoot further (because then you will
know where your content is actually available)
-------------------------------------------
I hope this helps.
Kind Regards,
David Ennis
Kind Regards,
David Ennis
David Ennis
*Content Engineer*
[image: HintTech] <http://www.hinttech.com/>
Mastering the value of content
creative | technology | content
Delftechpark 37i
2628 XJ Delft
The Netherlands
T: +31 88 268 25 00
M: +31 63 091 72 80
[image: http://www.hinttech.com] <http://www.hinttech.com>
<https://twitter.com/HintTech> <http://www.facebook.com/HintTech>
<http://www.linkedin.com/company/HintTech>
On 17 October 2014 07:50, Kapoor, Pragya <[email protected]> wrote:
> Hi David,
>
>
> I tried logging in invoker:
> let $_populate-map := for $each-param in $urlParams
> let $param-value :=
> xdmp:get-request-field($each-param)
> let $_ :=
> xdmp:log(fn:concat("$param-value",$param-value))
> ...
> logs:
>
> 2014-10-17 11:16:29.008 Info: rest-ingestion:
> module-invoker.xqy?format=xml&moduleName=add-document&requestDirectory=add&apiVersion=v1
> 2014-10-17 11:16:29.013 Info: rest-ingestion: $param-value*xml*
> 2014-10-17 11:16:29.013 Info: rest-ingestion: $param-valueadd-document
> 2014-10-17 11:16:29.013 Info: rest-ingestion: $param-valueadd
> 2014-10-17 11:16:29.013 Info: rest-ingestion: $param-valuev1
> 2014-10-17 11:16:29.013 Info: rest-ingestion:
> $param-value39932186-9cab-44e9-8f4f-7ebf45dabf8f
> 2014-10-17 11:16:29.309 Info: rest-ingestion: Ingestion Service End Point
> add-document.xqy 39932186-9cab-44e9-8f4f-7ebf45dabf8f
> 2014-10-17 11:16:29.309 Info: rest-ingestion:
> Path/processing/39932186-9cab-44e9-8f4f-7ebf45dabf8f/validDocs/
> 2014-10-17 11:16:29.309 Info: rest-ingestion:
> uri/docs/BONY_4076_REPO-GMR-2000.xml
>
> So its xml at this stage.
>
> At rewriter:
>
>
> case element(POST)
> return
> let $urlParams := let
> $paramNames:= xdmp:get-request-field-names()
> for $eachParam
> in $paramNames
> let $_ :=
> xdmp:log(fn:concat("$eachParam",$eachParam))
> let $paramValue
> := xdmp:get-request-field($eachParam)
> let $_ :=
> xdmp:log(fn:concat("$paramValue",$paramValue))
> return
> concat($eachParam,'=',$paramValue)
>
> logs:
>
>
> ------------------------------
> *From:* [email protected] <
> [email protected]> on behalf of David Ennis <
> [email protected]>
> *Sent:* Thursday, October 16, 2014 5:00 PM
> *To:* MarkLogic Developer Discussion
> *Subject:* Re: [MarkLogic Dev General] using xdmp:eval in REST Service
>
> HI.
>
> Yes, I had a look. The first reason I thought of the xdmp:unquote was
> because of the multipart form post. We have a system where we get XML
> packed inside of json in the body of a post and use xdmp:unquote and this
> seemed similiar.
>
> I concluded that this might have been similiar looking at your code
>
> *rewriter:*
> ...
> case element(POST)
> return
> let $urlParams := let
> $paramNames:= xdmp:get-request-field-names()
> for $eachParam
> in $paramNames
> let $paramValue
> := xdmp:get-request-field($eachParam)
> ....
>
> *INvoker:*
> ...
>
> let $_populate-map := for $each-param in $urlParams
> let $param-value :=
> xdmp:get-request-field($each-param) <----- Still not XML at this stage, I
> would assume
> ...
>
> Kind Regards,
> David
>
>
>
> Kind Regards,
> David Ennis
>
>
> David Ennis
> *Content Engineer*
>
> [image: HintTech] <http://www.hinttech.com/>
> Mastering the value of content
> creative | technology | content
>
> Delftechpark 37i
> 2628 XJ Delft
> The Netherlands
> T: +31 88 268 25 00
> M: +31 63 091 72 80
>
> [image: http://www.hinttech.com] <http://www.hinttech.com>
> <https://twitter.com/HintTech> <http://www.facebook.com/HintTech>
> <http://www.linkedin.com/company/HintTech>
>
> On 16 October 2014 13:15, Kapoor, Pragya <[email protected]> wrote:
>
>> Hi,
>>
>>
>> Yes, I tried using xdmp:unquote on $contents but still not working.
>>
>> Did you get a chance to look into the code which I attached in previous
>> mail?
>>
>>
>>
>> Thanks
>>
>> Pragya
>> ------------------------------
>> *From:* [email protected] <
>> [email protected]> on behalf of David Ennis <
>> [email protected]>
>> *Sent:* Thursday, October 16, 2014 2:41 PM
>> *To:* MarkLogic Developer Discussion
>> *Subject:* Re: [MarkLogic Dev General] using xdmp:eval in REST Service
>>
>> HI.
>>
>> I Know that this does not answer the whole question - but since things
>> are getting serialized, have you tried xdmp:unquote on the serialized XML
>> (the $contents variable in the original example)?
>>
>> Kind Regards,
>> David Ennis
>>
>>
>>
>>
>> On 16 October 2014 06:44, Kapoor, Pragya <[email protected]> wrote:
>>
>>> Hi,
>>>
>>>
>>> I am using Postman Rest Client to call this service. I am using POST
>>> method and sending parameters in form-data.
>>>
>>> URL: http://{hostname}:8010/v1/addDocument
>>> <http://10.190.57.71:8010/v1/addDocument>
>>>
>>>
>>> ML Version: 7.0-2.3
>>>
>>>
>>> I tried using xdmp:invoke instead of xdmp:eval but still the xml is
>>> getting serialized.
>>>
>>>
>>> Attached is the code I am using.
>>>
>>>
>>> Thanks
>>>
>>> Pragya
>>> ------------------------------
>>> *From:* [email protected] <
>>> [email protected]> on behalf of David Lee <
>>> [email protected]>
>>> *Sent:* Wednesday, October 15, 2014 5:26 PM
>>> *To:* MarkLogic Developer Discussion
>>> *Subject:* Re: [MarkLogic Dev General] using xdmp:eval in REST Service
>>>
>>>
>>> Could you show your code for how you run this via the REST interface ?
>>>
>>> Which version of ML, and what method of accessing REST ?
>>>
>>>
>>>
>>> One thing that stands out is the use of Eval ... this can get tricky
>>> when embedding in other code because of the multiple layer of string
>>> escaping needed ...
>>>
>>> You also don’t need the functx import inside the eval but that’s a
>>> different issue.
>>>
>>> Instead of xdmp:eval I prefer xdmp:invoke-function(
>>>
>>> http://docs.marklogic.com/xdmp:invoke-function
>>>
>>>
>>>
>>> This simplifies (eliminates) the need to construct XQuery from strings
>>> (so its safer from XQuery injection and less likely to be corrupted when
>>> created from
>>>
>>> other code.
>>>
>>>
>>>
>>> Your example could then become:
>>>
>>>
>>>
>>> let $DirectoryListing :=
>>>
>>> xdmp:invoke-function(
>>>
>>> function() {
>>>
>>> xdmp:directory($Path)
>>>
>>> } ,
>>>
>>> <options xmlns="xdmp:eval">
>>>
>>> <database>{xdmp:database("Ingestion")}</database>
>>>
>>> </options>
>>>
>>> )
>>>
>>>
>>>
>>> With no need to pass in external parameters or add delcarations in the
>>> body or quote things.
>>>
>>> Try this first - ... it’s a good trick to learn to write easier and
>>> safer code.
>>>
>>>
>>>
>>> But I suspect your real problem is something else - we need to see the
>>> code your running from REST
>>>
>>>
>>>
>>> The only xdmp:log() I see is for the docURI
>>>
>>> xdmp:log(fn:concat("uri",$docUri))
>>>
>>>
>>>
>>> So the code your showing us isnt likely the actual code your running.
>>>
>>>
>>>
>>> Could you provide the code your running ?
>>>
>>> What library or language you using to call the REST APIS's ?
>>>
>>> What your showing looks like the results are being serialized as text
>>> before you get them into
>>>
>>> let $DirectoryListing :=
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> -----------------------------------------------------------------------------
>>>
>>> David Lee
>>> Lead Engineer
>>> *Mark**Logic* Corporation
>>> [email protected]
>>> Phone: +1 812-482-5224
>>>
>>> Cell: +1 812-630-7622
>>> www.marklogic.com
>>>
>>>
>>>
>>> *From:* [email protected] [mailto:
>>> [email protected]] *On Behalf Of *Kapoor, Pragya
>>> *Sent:* Wednesday, October 15, 2014 3:59 AM
>>> *To:* [email protected]
>>> *Subject:* [MarkLogic Dev General] using xdmp:eval in REST Service
>>>
>>>
>>>
>>> Hi,
>>>
>>>
>>>
>>> I need to pick the all the docs in directory path ($Path) from Ingestion
>>> DB and insert them in Db which is configured for rest
>>> services(rest-ingestion).
>>>
>>>
>>>
>>> The below code works fine from Qconsole, but from Rest service , the xml
>>> being picked from the Ingestion DB is not coming as xml when the code is
>>> hit from Rest service. In logs, only content is theres, xml elements are
>>> missing.(attached are the logs)
>>>
>>>
>>>
>>> Please let me know, what I am missing in this code.
>>>
>>>
>>>
>>> Thanks
>>>
>>> Pragya
>>>
>>>
>>>
>>> Code:
>>>
>>>
>>>
>>> import module namespace dls = "http://marklogic.com/xdmp/dls"
>>>
>>> at "/MarkLogic/dls.xqy";
>>>
>>>
>>>
>>> import module namespace functx = "http://www.functx.com"
>>>
>>> at "/MarkLogic/functx/functx-1.0-nodoc-2007-01.xqy";
>>>
>>>
>>>
>>> let $transId := '39932186-9cab-44e9-8f4f-7ebf45dabf8f'
>>>
>>> let $PrefixURI := "/docs/"
>>>
>>>
>>>
>>> let $Path := fn:concat('/processing/', $transId,'/validDocs/')
>>>
>>> let $DirectoryListing :=
>>>
>>> xdmp:eval('
>>>
>>> import module namespace functx = "
>>> http://www.functx.com"
>>>
>>> at
>>> "/MarkLogic/functx/functx-1.0-nodoc-2007-01.xqy";
>>>
>>> declare variable $Path as xs:string
>>> external;
>>>
>>>
>>>
>>> xdmp:directory($Path)
>>>
>>> '
>>>
>>> ,
>>>
>>> (xs:QName("Path"), $Path)
>>>
>>> ,
>>>
>>> <options xmlns="xdmp:eval">
>>>
>>>
>>> <database>{xdmp:database("Ingestion")}</database>
>>>
>>> </options>
>>>
>>> )
>>>
>>> for $FileEntry in $DirectoryListing
>>>
>>> let $Filename :=
>>> functx:substring-after-last(xdmp:node-uri($FileEntry),'/')
>>>
>>> let $docUri := fn:concat($PrefixURI, $Filename)
>>>
>>> let $_ := xdmp:log(fn:concat("uri",$docUri))
>>>
>>> let $contents := $FileEntry
>>>
>>> return
>>>
>>> (: Insert the document :)
>>>
>>> (dls:document-insert-and-manage(
>>>
>>> $docUri,
>>>
>>> fn:false(),
>>>
>>> $contents,
>>>
>>> "created",
>>>
>>> (xdmp:permission("dls-user", "read"),
>>>
>>> xdmp:permission("dls-user", "update")),
>>>
>>> "historic"),
>>>
>>> xdmp:document-add-collections(
>>>
>>> $docUri,
>>>
>>> "latest"),
>>>
>>> xdmp:document-remove-collections(
>>>
>>> $docUri, "historic")
>>>
>>>
>>>
>>> )
>>>
>>>
>>>
>>> "This e-mail and any attachments transmitted with it are for the sole
>>> use of the intended recipient(s) and may contain confidential , proprietary
>>> or privileged information. If you are not the intended recipient, please
>>> contact the sender by reply e-mail and destroy all copies of the original
>>> message. Any unauthorized review, use, disclosure, dissemination,
>>> forwarding, printing or copying of this e-mail or any action taken in
>>> reliance on this e-mail is strictly prohibited and may be unlawful."
>>> "This e-mail and any attachments transmitted with it are for the sole
>>> use of the intended recipient(s) and may contain confidential , proprietary
>>> or privileged information. If you are not the intended recipient, please
>>> contact the sender by reply e-mail and destroy all copies of the original
>>> message. Any unauthorized review, use, disclosure, dissemination,
>>> forwarding, printing or copying of this e-mail or any action taken in
>>> reliance on this e-mail is strictly prohibited and may be unlawful."
>>>
>>> _______________________________________________
>>> General mailing list
>>> [email protected]
>>> http://developer.marklogic.com/mailman/listinfo/general
>>>
>>>
>> "This e-mail and any attachments transmitted with it are for the sole
>> use of the intended recipient(s) and may contain confidential , proprietary
>> or privileged information. If you are not the intended recipient, please
>> contact the sender by reply e-mail and destroy all copies of the original
>> message. Any unauthorized review, use, disclosure, dissemination,
>> forwarding, printing or copying of this e-mail or any action taken in
>> reliance on this e-mail is strictly prohibited and may be unlawful."
>>
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://developer.marklogic.com/mailman/listinfo/general
>>
>>
> "This e-mail and any attachments transmitted with it are for the sole
> use of the intended recipient(s) and may contain confidential , proprietary
> or privileged information. If you are not the intended recipient, please
> contact the sender by reply e-mail and destroy all copies of the original
> message. Any unauthorized review, use, disclosure, dissemination,
> forwarding, printing or copying of this e-mail or any action taken in
> reliance on this e-mail is strictly prohibited and may be unlawful."
>
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
>
>
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general