?
Solved

Streaming a file to browser using an Agent

Posted on 2004-03-29
10
Medium Priority
?
830 Views
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!
0
Comment
Question by:prohacx
  • 4
  • 3
  • 3
10 Comments
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 10704138
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

~Hemanth
0
 
LVL 5

Author Comment

by:prohacx
ID: 10704376
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?

Thanks!
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 10704624
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Author Comment

by:prohacx
ID: 10711486
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">
<html>
<head>
</head>
<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!
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 10713968
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.

0
 
LVL 31

Accepted Solution

by:
qwaletee earned 1000 total points
ID: 10715954
There is no equivalent class to HttpServletResponse -- agents ALWAYS use the printwriter and nothing else.  Hemantha's trick will not work, but something similar will, let me explain.

When Domino sees the first output from an agent (LS or java), it checks to see if the first line is the content header.  If not, it puts its own headings in.  So, you have to set your first output to be the content type heading to bypass Domino putting its own content type and initial HTML tags.

I'm not sure why, but Hemantha was assuming that you would not be able to do this with your Java agent.  So, he tried to work around it by having a LotusScript agent set the conetnt type, and then the LS agent would call your Java agent.  Problem is that only the "main" called agent can give output.  Anything generated by the secondary agent is ignored.

So, you just have to use the content type=initial output trick WITHIN your java agent, by having it be the first thing your agent does (grab agentcontent and the printwriter and then immediately pw.println("Content-type:application/pdf");
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 10716216
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.
0
 
LVL 5

Author Comment

by:prohacx
ID: 10721315
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...
                  toBrowser.println("Content-type:text/html");

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...

Bye!
0
 
LVL 5

Author Comment

by:prohacx
ID: 10721337
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.
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 10728253
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.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
Loops Section Overview
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question