logo

New Response

« Return to the blog entry

You are replying to:

  1. @Jake

    This Java Agent retrieves XML (or html) when called like this:

    http://host/path/agent?Openagent&Url={Link}

    The XML then has to be parsed in some way of course. If you look in the source at {Link} you can see anexample.

    Source:

    import lotus.domino.*;

    import java.io.PrintWriter;

    import java.io.BufferedReader;

    import java.io.IOException;

    import java.io.InputStreamReader;

    import java.net.*;

    public class JavaAgent extends AgentBase {

    PrintWriter browser;

    public void NotesMain() {

    try {

    Session session = getSession();

    AgentContext agentContext = session.getAgentContext();

    Database db = agentContext.getCurrentDatabase();

    browser = new PrintWriter( getAgentOutput(), true );

    Document doc = agentContext.getDocumentContext();

    Document docToUpdate;

    String docQuery_String_Decoded = doc.getFirstItem("Query_String").getValueString();

    String urlNoAgent = docQuery_String_Decoded.substring( 14 , docQuery_String_Decoded.length() );

    System.out.println("urlNoAgent : "+urlNoAgent);

    String UrlToConnect = urlNoAgent;

    URL url = new URL(UrlToConnect);

    URLConnection uc = url.openConnection();

    BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));

    try {

    sleep(1000);

    }

    catch (Exception e) {System.out.println("Error reading - retrieve(URL url)"); }

    String in,finalstring = "";

    while ((in=br.readLine()) != null){

    finalstring += in+"\n";

    }

    browser.println("Content-Type: text/xml");

    browser.println(finalstring);

    } catch(Exception e) {

    e.printStackTrace();

    }

    }

    }

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment: