import lotus.domino.*;
import java.io.*;
import java.net.*;
import java.util.*;
public class JavaAgentExample extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Database db = agentContext.getCurrentDatabase();
View view = db.getView("[VIEWNAME]");
DocumentCollection dc = view.getAllDocumentsByKey("[CATEGORYVALUE]", true);
int ndocs = dc.getCount();
int i = 0;
Document doc = dc.getFirstDocument();
while( doc != null ) {
i++;
String field1 = doc.getItemValueString("field1");
String enc_field1 = URLEncoder.encode(field1);
//(more fields)
String content= "field1=" + enc_field1;//+"&&enc_field2="+enc_field2+...(more params);
URL url = new URL("[URL]");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
// Sets the request method to POST, and enable to send data
connection.setRequestMethod("POST");
connection.setAllowUserInteraction(false);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
// Sets the defaul Content-type and content lenght for POST requests
connection.setRequestProperty( "Content-type", "application/x-www-form-urlencoded" );
connection.setRequestProperty( "Content-length", Integer.toString(content.length()));
DataOutputStream out = new DataOutputStream (connection.getOutputStream ());
out.writeBytes (content);
out.flush ();
out.close ();
connection.disconnect();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while(null != (line = in.readLine())) {
System.out.println(line);
}
String title = db.getTitle();
System.out.println("Current database is \"" + title + "\"");
doc = dc.getNextDocument();
}
}catch(NotesException ne) {
System.out.println("NotesError " + ne.text);}catch(Exception e) {
e.printStackTrace();
}
}
}