I have solved this by creating a servlet with context parameters.
I have an RUI external type function to open a link in a remote browser window. I can call this externaltype function from RUI with a link I create.
This link goes to the servlet contains a parameter with the id of the file.
The servlet consumes a web service to retrieve the file details from the database with the id of the file, and returns the file.
The externaltype javascript code:
egl.defineClass( 'customJavaScript.widgets', 'BrowserFuncts', { "eze$$initializeDOMElement": function(){ }, "constructor": function(){ //theWidget=this; }, "openWindow" : function (windowURL, options) { m = window.open(windowURL,'_blank',options); return true; }});
The egl externaltype code:
package externalTypes;delegate EndPageEvent()endexternalType BrowserFunctions extends Widget type JavaScriptObject { relativePath = "customJavaScript/widgets", javaScriptName = "BrowserFuncts" } function openWindow(windowURL string in, options string in);end
The code to use the openWindow function (from within the handler or the widget)
link string = "http://as400server:10021/PdfServices/getFile?fileID=" + id; Browserfuncties BrowserFunctions = new Browserfunctions(); browserFuncties.openWindow(link, "");
And the servlet:
package com.molcy.java.servlets.file;import java.io.BufferedInputStream;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.math.BigDecimal;import java.rmi.RemoteException;import java.util.Random;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.xml.rpc.ServiceException;import com.molcy.java.util.PathUtils;import com.molcy.webservices.Services.BestandService;import com.molcy.webservices.Services.BestandServiceServiceLocator;import com.molcy.webservices.UIRecords.UIBestandRec;/* * Dit zorgt ervoor dat het mime type goed staat. * Indien "Content-Disposition" als attachment staat, kan je in firefox niet automatisch openen. * getfile zal dus altijd met dialoogvenster zijn en zal de bestandsnaam correct zijn * getfilemime kan de browser kijken hoe hij het behandelt en zal de bestandsnaam getfile zijn * */public class getFile extends HttpServlet { private static final long serialVersionUID = 1L; public getFile() { super(); // TODO Auto-generated constructor stub } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int fileID = Integer.parseInt(request.getParameter("fileID")); BestandServiceServiceLocator blocator = new BestandServiceServiceLocator(); try { BestandService bserv = blocator.getBestandService(); UIBestandRec bestRec = bserv.getBestand(new BigDecimal(fileID)); String extension = PathUtils.getExtension(bestRec.getPad()); Random generator = new Random(); int i = generator.nextInt(); if (i < 0) i = i * -1; //String ct = PathUtils.getMimeType(bestRec.getOrigBestandNaam()+ "." + extension); response.addHeader("Content-Disposition", "attachment; filename=\"" + bestRec.getOmschr().trim() + "-" + i + "." + extension + "\""); response.setContentType(PathUtils.getMimeType(bestRec.getOrigBestandNaam())); File f = new File(PathUtils.movePathToQNC(bestRec.getPad())); BufferedInputStream in = new BufferedInputStream(new FileInputStream(f)); int len; byte[] buf = new byte[1024]; while ((len = in.read(buf)) > 0){ response.getOutputStream().write(buf, 0, len); } in.close(); response.getOutputStream().close(); } catch (RemoteException e){ System.out.println("Servlet getFile: Fout bij ophalen bestandsdetails voor bestand met id " + fileID + " " + e.getMessage()); } catch (ServiceException servEx){ System.out.println("Servlet getFile: Fout bij instellen service " + servEx.getMessage()); } } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub }}
I have just copied the code as it works for me.
It might be too complex for your needs.
Kind regards,
Bram
Bram_Callewaert