-2

I am trying to implement a feature that returns a zip file upon calling an agent on Domino system. So domino is the webserver that returns a zip file.

A 3rd party app would use something like a wget statement to call a domino based system url and they would get a zip file.

Does anyone have an existing implementation of this kind of an idea where we can share thoughts on that or suggestions are welcome.

Thanks in advance.

Kalyan
  • 27
  • 1
  • 10

2 Answers2

0

this can be achieved by using java.util.zip and a xpage

if (doc != null)
                {
                    Vector<String> attachments = (Vector<String>) s.evaluate("@AttachmentNames", doc);
                    if (attachments != null)
                    {
                        if (attachments.size() > 0)
                        {
                            HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
                            this.setHeaders(response, zipFileName);
                            ZipOutputStream zipOutStream = new ZipOutputStream(response.getOutputStream());
                            EmbeddedObject embeddedObj = null;
                            BufferedInputStream bufferInStream = null;
                            for (String attName : (Vector<String>) attachments)
                            {
                                embeddedObj = doc.getAttachment(attName);
                                if (embeddedObj != null)
                                {
                                    if (embeddedObj.getType() == EmbeddedObject.EMBED_ATTACHMENT)
                                    {
                                        bufferInStream = new BufferedInputStream(embeddedObj.getInputStream());
                                        int bufferLength = bufferInStream.available();
                                        byte[] data = new byte[bufferLength];
                                        bufferInStream.read(data, 0, bufferLength);
                                        ZipEntry entry = new ZipEntry(embeddedObj.getName());
                                        zipOutStream.putNextEntry(entry);
                                        zipOutStream.write(data);
                                        zipOutStream.closeEntry();
                                        bufferInStream.close();
                                        try
                                        {
                                            embeddedObj.recycle();
                                        } catch (Exception ex2)
                                        {
                                            OpenLogItem.logError(ex2);
                                        }

                                    }
                                }
                            }
                            zipOutStream.flush();
                            zipOutStream.close();
                        }
                        result = true;
                        facesContext.responseComplete();
                    }
                    doc.recycle();
                }



private void setHeaders(HttpServletResponse response,String zipFileName)
{
    try{
    response.setContentType("application/octet-stream");
    response.setDateHeader("Expires", 0);
    response.setHeader("Pragma", "Public");
    response.setHeader("Content-Description", "File Transfer");
    response.setHeader("Content-Disposition", "attachment; filename=" + zipFileName);
    response.setHeader("Content-Transfer-Encoding", "binary");
    }
    catch(Exception ex)

    {
        OpenLogItem.logError(ex);
    }

}
umeli
  • 1,068
  • 8
  • 14
  • Thank you. Will try this approach and let you know the feedback. Thanks for the code too. – Kalyan Oct 08 '15 at 07:02
  • Thanks for your inputs, following Mr. Richard's tip here as that approach is quicker for us. Appreciate your response. – Kalyan Oct 09 '15 at 07:36
0

Just store the zip file in a document in a Notes database on the server. The URL will be of the form:

 www.yourHost.com/your Path/yourDatabase.nsf/viewUNID/docUNID/$File/yourFilename.zip

Use whatever tool you want to retrieve it.

(This assumes, of course, that the server has been properly set up to support HTTP.)

Richard Schwartz
  • 14,463
  • 2
  • 23
  • 41
  • Thanks a lot. This is the way we are designing it by storing it on a temp record and call the URL. But there is a processing time here as we create a zip file based on the input parameters from the URL. So, need to tweak it to make sure that with one URL call, output will be a zip file. – Kalyan Oct 08 '15 at 07:01
  • What you can do is write your agent to store the zip file in the temp document and then send the correct URL back to the browser as a redirect. As I recall, if the only thing your agent puts into the response is the URL enclosed in square brackets (i.e., [www.etc.etc/etc/$File/filename.zip]), it will be processed as a redirect. The other way, again if I recall correctly, is by setting putting into the response. – Richard Schwartz Oct 08 '15 at 16:53
  • Interesting coincidence... This question about redirecting just appeared: http://stackoverflow.com/questions/33002200/how-to-redirect-webpage-by-lotus-notes-java-agent – Richard Schwartz Oct 08 '15 at 16:55
  • Thanks for the inputs again. Due to some increased processing time, we are not storing it on a notes doc as upload is taking a while for larger files. Instead we are creating zip and putting it on HTML folder and using print "[]" statement, pushing it back via the agent itself. So far, it works well under the test phase. Will get back with more feedback as and when I get another approach. – Kalyan Oct 09 '15 at 07:35