import lotus.domino.*; import java.io.*; import java.net.*; // This is a Lotus Notes agent that shows how to get a web page // (or other URL file, like a graphic) public class JavaAgent extends AgentBase { public void NotesMain() { try { // get the web page below and print to the console (toString is implied) System.out.println(GetURLFile("http://localhost/TestDb.nsf/")); } catch(Exception e) { e.printStackTrace(); } } public ByteArrayOutputStream GetURLFile(String urlString) throws MalformedURLException, NoRouteToHostException, ConnectException, IOException { return GetURLFile(urlString, "", 0); } public ByteArrayOutputStream GetURLFile( String urlString, String proxyServer, int proxyPort) throws MalformedURLException, NoRouteToHostException, ConnectException, IOException { // Get the given URL and return it as a ByteArrayOutputStream. // You can then convert it using either toString or toByteArray, // whichever makes more sense (web pages can easily be // treated as Strings, binary files like graphics should be byte // arrays). You can optionally pass a proxyServer name and // port, if you're behind a proxy; otherwise, just pass a blank // String for the server name and 0 for the proxy port. BufferedInputStream fileStream = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); URL theUrl; if (proxyServer == null) proxyServer = ""; if ((proxyServer.length() > 0) && (proxyPort > 0)) { // use HTTP proxy, even for FTP downloads theUrl = new URL("http", proxyServer, proxyPort, urlString); } else { theUrl = new URL(urlString); } // go get the file URLConnection con = theUrl.openConnection(); // if we were able to connect (we would have errored out // by now if not), try to get the file. fileStream = new BufferedInputStream(con.getInputStream()); // write to the ByteArrayOutputStream int howManyBytes; byte[] bytesIn = new byte[1024]; while ((howManyBytes = fileStream.read(bytesIn)) >= 0) { baos.write(bytesIn, 0, howManyBytes); } // close the remote connection and return what we got fileStream.close(); return baos; } }