David Sewell | 11 Jul 2012 16:59
Favicon

[MarkLogic Dev General] HTTP server URL rewriting and empty GET requests

Just a note for anyone using MarkLogic URL rewriting.

A typical MarkLogic URL rewrite script for an HTTP server looks like this in 
pseudo-code:

let $URL := xdmp:get-request-url()
return
   if (matches($URL, something)) then replace($URL, regex, replacement)
   . . .
   else $URL

It turns out that if an HTTP client is ill-behaved and sends an empty HTTP GET 
request (you can simulate this using telnet to the server port), it triggers a 
500 error in MarkLogic: XDMP-RETURNTYPE complaining that the rewrite script is 
not returning a string. This means that one's rewrite script needs explicitly to 
handle null URLs, for example

   if (empty($URL) or $URL eq '') then [some replacement]

"some replacement" should probably be the root document of the server, e.g. 
/default.xqy (at any rate that's what Apache serves up in the same situation).

Possibly MarkLogic should itself handle an empty return value from the rewrite 
script without throwing an error.

DS

--

-- 
David Sewell, Editorial and Technical Manager
ROTUNDA, The University of Virginia Press
(Continue reading)

DJaun Maclin | 11 Jul 2012 23:05

[MarkLogic Dev General] Serving PDFs from the MarkLogic Server

Hi everyone,

I was wondering how could I serve PDF files in the Marklogic Server to the outside world for downloading and viewing purposes. I would love to have a direct link to the PDF file store in the database. Has anyone dealt with this before?

Thanks
Dj
<div>
<div>Hi everyone,</div>
<div><br></div>
<div>I was wondering how could I serve PDF files in the Marklogic Server to the outside world for downloading and viewing purposes. I would love to have a direct link to the PDF file store in the database. Has anyone dealt with this before?</div>
<div><br></div>
<div>Thanks</div>
<div>Dj</div>
</div>
David Lee | 11 Jul 2012 23:07

Re: [MarkLogic Dev General] Serving PDFs from the MarkLogic Server

You can server PDF's if you store them as a binary file.

You can also dynamically generate them (but it requires an app server).

I have done both and served them from a ML application no problem.

You do want to set the mime-type correctly for the response.

 

-----------------------------------------------------------------------------

David Lee
Lead Engineer
MarkLogic Corporation
dlee-efBvD/aTHCF8UrSeD/g0lQ@public.gmane.org
Phone: +1 650-287-2531
Cell:  +1 812-630-7622

www.marklogic.com

This e-mail and any accompanying attachments are confidential. The information is intended solely for the use of the individual to whom it is addressed. Any review, disclosure, copying, distribution, or use of this e-mail communication by others is strictly prohibited. If you are not the intended recipient, please notify us immediately by returning this message to the sender and delete all copies. Thank you for your cooperation.

 

From: general-bounces-ld4jwAGwUXTgXEvjvSGRgMKenhbt+owO@public.gmane.org [mailto:general-bounces-ld4jwAGwUXTgXEvjvSGRgEPhkuQigjxi@public.gmane.org.com] On Behalf Of DJaun Maclin
Sent: Wednesday, July 11, 2012 5:06 PM
To: General Discussion
Subject: [MarkLogic Dev General] Serving PDFs from the MarkLogic Server

 

Hi everyone,

 

I was wondering how could I serve PDF files in the Marklogic Server to the outside world for downloading and viewing purposes. I would love to have a direct link to the PDF file store in the database. Has anyone dealt with this before?

 

Thanks

Dj

<div><div class="WordSection1">
<p class="MsoNormal"><span>You can server PDF's if you store them as a binary file.<p></p></span></p>
<p class="MsoNormal"><span>You can also dynamically generate them (but it requires an app server).<p></p></span></p>
<p class="MsoNormal"><span>I have done both and served them from a ML application no problem.<p></p></span></p>
<p class="MsoNormal"><span>You do want to set the mime-type correctly for the response.<p></p></span></p>
<p class="MsoNormal"><span><p>&nbsp;</p></span></p>
<div>
<p class="MsoNormal"><span>-----------------------------------------------------------------------------<p></p></span></p>
<p class="MsoNormal"><span>David Lee<br>Lead Engineer<br>MarkLogic Corporation<br></span><span>dlee@...<br></span><span>Phone: +1 650-287-2531<br>Cell:&nbsp; +1 812-630-7622</span><span><br><a href="http://www.marklogic.com/"><span>www.marklogic.com</span></a><br><br></span><span>This e-mail and any accompanying attachments are confidential. The information is intended solely for the use of the individual to whom it is addressed. Any review, disclosure, copying, distribution, or use of this e-mail communication by others is strictly prohibited. If you are not the intended recipient, please notify us immediately by returning this message to the sender and delete all copies. Thank you for your cooperation.</span><span><p></p></span></p>
</div>
<p class="MsoNormal"><span><p>&nbsp;</p></span></p>
<div>
<div><div><p class="MsoNormal"><span>From:</span><span> general-bounces@... [mailto:general-bounces@....com] On Behalf Of DJaun Maclin<br>Sent: Wednesday, July 11, 2012 5:06 PM<br>To: General Discussion<br>Subject: [MarkLogic Dev General] Serving PDFs from the MarkLogic Server<p></p></span></p></div></div>
<p class="MsoNormal"><p>&nbsp;</p></p>
<div><p class="MsoNormal"><span>Hi everyone,<p></p></span></p></div>
<div><p class="MsoNormal"><span><p>&nbsp;</p></span></p></div>
<div><p class="MsoNormal"><span>I was wondering how could I serve PDF files in the Marklogic Server to the outside world for downloading and viewing purposes. I would love to have a direct link to the PDF file store in the database. Has anyone dealt with this before?<p></p></span></p></div>
<div><p class="MsoNormal"><span><p>&nbsp;</p></span></p></div>
<div><p class="MsoNormal"><span>Thanks<p></p></span></p></div>
<div><p class="MsoNormal"><span>Dj<p></p></span></p></div>
</div>
</div></div>
Danny Sokolsky | 12 Jul 2012 18:52

Re: [MarkLogic Dev General] Serving PDFs from the MarkLogic Server

Here is an example of an xqy file that does what David is talking about, using fn:doc to serve up a pdf stored as
binary in MarkLogic:

(: pdf.xqy :)

xquery version"1.0-ml";

xdmp:set-response-content-type("application/pdf"),

let $pdf := xdmp:get-request-field("pdf","")
return
fn:doc($pdf)

And then you can call this from some html in another XQY file, something like this:

(: some other xqy :)

<a href="pdf.xqy?pdf=/my/pdf/uri/doc.pdf" target="_blank">View my PDF file in a new window</a>

-Danny

From: general-bounces@...
[mailto:general-bounces <at> developer.marklogic.com] On Behalf Of David Lee
Sent: Wednesday, July 11, 2012 2:08 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Serving PDFs from the MarkLogic Server

You can server PDF's if you store them as a binary file.
You can also dynamically generate them (but it requires an app server).
I have done both and served them from a ML application no problem.
You do want to set the mime-type correctly for the response.

-----------------------------------------------------------------------------
David Lee
Lead Engineer
MarkLogic Corporation
dlee@...
Phone: +1 650-287-2531
Cell:  +1 812-630-7622
www.marklogic.com

This e-mail and any accompanying attachments are confidential. The information is intended solely for
the use of the individual to whom it is addressed. Any review, disclosure, copying, distribution, or use
of this e-mail communication by others is strictly prohibited. If you are not the intended recipient,
please notify us immediately by returning this message to the sender and delete all copies. Thank you for
your cooperation.

From: general-bounces@...
[mailto:general-bounces <at> developer.marklogic.com] On Behalf Of DJaun Maclin
Sent: Wednesday, July 11, 2012 5:06 PM
To: General Discussion
Subject: [MarkLogic Dev General] Serving PDFs from the MarkLogic Server

Hi everyone,

I was wondering how could I serve PDF files in the Marklogic Server to the outside world for downloading and
viewing purposes. I would love to have a direct link to the PDF file store in the database. Has anyone dealt
with this before?

Thanks
Dj
DJaun Maclin | 12 Jul 2012 21:35

Re: [MarkLogic Dev General] Serving PDFs from the MarkLogic Server

Thanks for the example, Danny!

On 7/12/12 11:52 AM, "Danny Sokolsky" <Danny.Sokolsky@...> wrote:

>Here is an example of an xqy file that does what David is talking about,
>using fn:doc to serve up a pdf stored as binary in MarkLogic:
>
>
>(: pdf.xqy :)
>
>xquery version"1.0-ml";
>
>xdmp:set-response-content-type("application/pdf"),
>
>let $pdf := xdmp:get-request-field("pdf","")
>return
>fn:doc($pdf)
>
>
>And then you can call this from some html in another XQY file, something
>like this:
>
>(: some other xqy :)
>
><a href="pdf.xqy?pdf=/my/pdf/uri/doc.pdf" target="_blank">View my PDF
>file in a new window</a>
>
>
>-Danny
>
>From: general-bounces@...
>[mailto:general-bounces@...] On Behalf Of David Lee
>Sent: Wednesday, July 11, 2012 2:08 PM
>To: MarkLogic Developer Discussion
>Subject: Re: [MarkLogic Dev General] Serving PDFs from the MarkLogic
>Server
>
>You can server PDF's if you store them as a binary file.
>You can also dynamically generate them (but it requires an app server).
>I have done both and served them from a ML application no problem.
>You do want to set the mime-type correctly for the response.
>
>--------------------------------------------------------------------------
>---
>David Lee
>Lead Engineer
>MarkLogic Corporation
>dlee@...
>Phone: +1 650-287-2531
>Cell:  +1 812-630-7622
>www.marklogic.com
>
>This e-mail and any accompanying attachments are confidential. The
>information is intended solely for the use of the individual to whom it
>is addressed. Any review, disclosure, copying, distribution, or use of
>this e-mail communication by others is strictly prohibited. If you are
>not the intended recipient, please notify us immediately by returning
>this message to the sender and delete all copies. Thank you for your
>cooperation.
>
>From: general-bounces@...
>[mailto:general-bounces@...] On Behalf Of DJaun Maclin
>Sent: Wednesday, July 11, 2012 5:06 PM
>To: General Discussion
>Subject: [MarkLogic Dev General] Serving PDFs from the MarkLogic Server
>
>Hi everyone,
>
>I was wondering how could I serve PDF files in the Marklogic Server to
>the outside world for downloading and viewing purposes. I would love to
>have a direct link to the PDF file store in the database. Has anyone
>dealt with this before?
>
>Thanks
>Dj
>_______________________________________________
>General mailing list
>General@...
>http://developer.marklogic.com/mailman/listinfo/general

DJaun Maclin | 12 Jul 2012 21:12

Re: [MarkLogic Dev General] Serving PDFs from the MarkLogic Server

I was able to set the mime type to get the correct response.

Thanks, David!

 

Dj

 

From: general-bounces-ld4jwAGwUXTgXEvjvSGRgMKenhbt+owO@public.gmane.org [mailto:general-bounces-ld4jwAGwUXTgXEvjvSGRgMKenhbt+owO@public.gmane.org] On Behalf Of David Lee
Sent: Wednesday, July 11, 2012 4:08 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Serving PDFs from the MarkLogic Server

 

You can server PDF's if you store them as a binary file.

You can also dynamically generate them (but it requires an app server).

I have done both and served them from a ML application no problem.

You do want to set the mime-type correctly for the response.

 

-----------------------------------------------------------------------------

David Lee
Lead Engineer
MarkLogic Corporation
dlee-efBvD/aTHCF8UrSeD/g0lQ@public.gmane.org
Phone: +1 650-287-2531
Cell:  +1 812-630-7622

www.marklogic.com

This e-mail and any accompanying attachments are confidential. The information is intended solely for the use of the individual to whom it is addressed. Any review, disclosure, copying, distribution, or use of this e-mail communication by others is strictly prohibited. If you are not the intended recipient, please notify us immediately by returning this message to the sender and delete all copies. Thank you for your cooperation.

 

From: general-bounces-ld4jwAGwUXTgXEvjvSGRgMKenhbt+owO@public.gmane.org [mailto:general-bounces-ld4jwAGwUXTgXEvjvSGRgMKenhbt+owO@public.gmane.org] On Behalf Of DJaun Maclin
Sent: Wednesday, July 11, 2012 5:06 PM
To: General Discussion
Subject: [MarkLogic Dev General] Serving PDFs from the MarkLogic Server

 

Hi everyone,

 

I was wondering how could I serve PDF files in the Marklogic Server to the outside world for downloading and viewing purposes. I would love to have a direct link to the PDF file store in the database. Has anyone dealt with this before?

 

Thanks

Dj

<div>
<div class="Section1">
<p class="MsoNormal"><span>I was able to set the mime type to get the correct response.<p></p></span></p>
<p class="MsoNormal"><span>Thanks, David!<p></p></span></p>
<p class="MsoNormal"><span><p>&nbsp;</p></span></p>
<p class="MsoNormal"><span>Dj<p></p></span></p>
<p class="MsoNormal"><span><p>&nbsp;</p></span></p>
<div>
<div class="MsoNormal" align="center"><span>
</span></div>
<p class="MsoNormal"><span>From:</span><span> general-bounces@...
 [mailto:general-bounces@...] <span>On Behalf Of
</span>David Lee<br><span>Sent:</span> Wednesday, July 11, 2012 4:08 PM<br><span>To:</span> MarkLogic Developer Discussion<br><span>Subject:</span> Re: [MarkLogic Dev General] Serving PDFs from the MarkLogic Server</span><p></p></p>
</div>
<p class="MsoNormal"><span><p>&nbsp;</p></span></p>
<p class="MsoNormal"><span>You can server PDF's if you store them as a binary file.<p></p></span></p>
<p class="MsoNormal"><span>You can also dynamically generate them (but it requires an app server).<p></p></span></p>
<p class="MsoNormal"><span>I have done both and served them from a ML application no problem.<p></p></span></p>
<p class="MsoNormal"><span>You do want to set the mime-type correctly for the response.<p></p></span></p>
<p class="MsoNormal"><span><p>&nbsp;</p></span></p>
<div>
<p class="MsoNormal"><span>-----------------------------------------------------------------------------<p></p></span></p>
<p class="MsoNormal"><span>David Lee<br>
Lead Engineer<br>
MarkLogic Corporation<br></span><span>dlee@...<br></span><span>Phone: +1 650-287-2531<br>
Cell:&nbsp; +1 812-630-7622</span><span><br><a href="http://www.marklogic.com/">www.marklogic.com</a><br><br></span><span>This e-mail and any accompanying attachments are confidential. The information is intended solely for the use of the individual to whom
 it is addressed. Any review, disclosure, copying, distribution, or use of this e-mail communication by others is strictly prohibited. If you are not the intended recipient, please notify us immediately by returning this message to the sender and delete all
 copies. Thank you for your cooperation.</span><span><p></p></span></p>
</div>
<p class="MsoNormal"><span><p>&nbsp;</p></span></p>
<div>
<div>
<div>
<p class="MsoNormal"><span>From:</span><span> general-bounces@...
 [mailto:general-bounces@...] <span>On Behalf Of
</span>DJaun Maclin<br><span>Sent:</span> Wednesday, July 11, 2012 5:06 PM<br><span>To:</span> General Discussion<br><span>Subject:</span> [MarkLogic Dev General] Serving PDFs from the MarkLogic Server<p></p></span></p>
</div>
</div>
<p class="MsoNormal"><span><p>&nbsp;</p></span></p>
<div>
<p class="MsoNormal"><span>Hi everyone,<p></p></span></p>
</div>
<div>
<p class="MsoNormal"><span><p>&nbsp;</p></span></p>
</div>
<div>
<p class="MsoNormal"><span>I was wondering how could I serve PDF files in the Marklogic Server to the outside world for downloading and viewing purposes. I
 would love to have a direct link to the PDF file store in the database. Has anyone dealt with this before?<p></p></span></p>
</div>
<div>
<p class="MsoNormal"><span><p>&nbsp;</p></span></p>
</div>
<div>
<p class="MsoNormal"><span>Thanks<p></p></span></p>
</div>
<div>
<p class="MsoNormal"><span>Dj<p></p></span></p>
</div>
</div>
</div>
</div>

Gmane