We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


Streaming a file to browser using an Agent

prohacx asked
Medium Priority
Last Modified: 2013-12-18
Hi there!

As you probably know, I'm new to Lotus Notes development and I'm currently trying to convert a Servlet I wrote to work inside an Agent.

The Servlet used to generate a PDF file that was streamed directly to the browser using the HttpServletResponse instance. This instance has methods like .setContentType("application/pdf"), .setHeader("Content-disposition", "inline; filename=dummy.pdf"), etc.

Basically, I'm looking in how to use such methods inside an Agent, since there's no HttpServletResponse there.

I already succeeded in using a java.io.PrintWriter that I got through a call to the AgentBase.getAgentOutput(), but I think this can only be used for adding character data, not for header data...

Any hints?

Thanks in advance!
Watch Question

I am not sure why you want to convert servlet into an agent ?? As you can run the servlet from Domino by enabling the servlet manager in domino and then call/open it using url function



Yes, I know, that's the way I'm currently doing it, but it's kind of an exercise to me.

I'm wandering how this can be done in Notes, since it has advantages (easy replication, ...) as well.

I prefer the Servlet way (since I'm more comfortable with it), but can it be done in a Notes Agent as well?


Unfortunately, probabkyt can't be done because of some screwy things with the Lotus implementation of PrintWriter.

1) Agent output to browser is done via a PrintWriter object attached to AgentContext
2) It doesn't stream it, it waits until you close the PrintWriter
3) It tends to insert newline characters every once in a while, which will completely mess up teh PDF, even if you weren;t trying to stream it.


Indeed, using a PrintWriter isn't the way to go, I agree.

That's why I'm looking for something like the HttpServletResponse class, but in an Agent. On the HttpServletResponse of a Servlet, you can put whatever you want, including PDF. Does such class exist in an Agent?

Also, I noticed that when I run code inside an Agent, code that generates HTML and writes it to the PrintWriter, Notes puts extra tags in front (<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<body text="#000000">) and in the end (</body></html>).

Can this be switched off? Does this mean that I can only generate HTML 4.01 transitional and no XHTML1.1 or other content? How should I insert my own header data (<title></title>, meta tags, javascript, ...) then???

Many thanks in advance!
Give this a shot..

Create a lotus script agent with following script

Dim s as New NotesSession
dim db as NotesDatabase
dim ag as NotesAgent

Print "Content-Type:application/pdf";

set db = s.CurrentDatabase
' I am not sure about the following two lines whether it might impose any kind of limitations..!!
set ag = db.GetAgent( "Java Agent equivalent to Servlet") ' This will be a handle to your java agent
call ag.run()

What it especially does is .. the print command stops domino from generating any content of its own.

Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Because LS print statement by passes domino generated html tags.. I am not sure PW can do that..If it does then well and good.


Hi there!

Again, you guys helped me out great! Too bad I can't use the PrintWriter to stream PDF (or can I?)...

But you were right: setting

                  java.io.PrintWriter toBrowser = getAgentOutput();
                  // Remove html tags generated by Notes by setting
                  // the content type explicitly...

and then using println on the PrintWriter instance does remove all tags generated by Notes, so that's cool.

Maybe I'll try to do the PDF streaming again later, right now I'm trying to get some background images inside the PDF first, seems to be not so easy either...



P.S.: I set content-type to text/html, because it was in another agent that the extra tags were generated and that other agent generated HTML, that's why. As said, I still have to try to output PDF, since that should be done through a ByteArrayOutputStream.

Normally, he only reason why you wnat to have an agent do the streaming is because agents integrate better with the Domino security model.  The way I have handled such things in the past is to have the agent create a "nearly secure" copy of the file to be streamed -- not truly secure, merely very difficult to find.  It then redirects the user to the copy.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.