Solved

Streaming a file to browser using an Agent

Posted on 2004-03-29
10
735 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 31

Accepted Solution

by:
qwaletee earned 250 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now