/*
* getMailFile.java
*
* Created on June 10, 2003, 3:49 PM
* by Keith Nolen
* sourced from a Domino agent created by Jake Howlett
*/
import java.io.*;
import java.net.*;
import lotus.domino.*;
import org.apache.xmlrpc.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
*
* @author Keith Nolen, http://www.yellerdog.net
* @version 0.1
*/
public class getMailFile extends HttpServlet {
/** Initializes the servlet.
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
/** Destroys the servlet.
*/
public void destroy() {
}
/** Handles the HTTP POST
method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//Create the Apache RPC server
XmlRpcServer xmlrpc = new XmlRpcServer();
/*Register this servlet's class as the handler
* All requests for method beginning domino.*
* will come to this class. To use another
* class the line would become:
* xmlrpc.addHandler ("domino", new handlerClass() );
*/
xmlrpc.addHandler ("domino", this );
//Get the request InputStream (which is XML) and
//pass it in to the server
InputStream is = request.getInputStream();
byte[] result = xmlrpc.execute( is );
/*
*Thanks to Johan Känngård, http://dev.kanngard.net/
*for debugging the following line.
*/
//pw.println( new String(result) );
//Set the content type to XML; get a handle on the output stream
response.setContentType ("text/xml");
response.setContentLength (result.length);
OutputStream out = response.getOutputStream();
out.write(result);
out.flush();
}
/* This method is called via an RPC request for
* .domino.getUsersMailFileLocation
*
* Parameter = username (string)
* Returns: path to user's mail file (string)
*/
public String getUsersMailFileLocation(String userName) throws Exception
{ String fPath = null;
NotesThread.sinitThread();
try {
// Assume the NAB is on this server and we have access
Session s = NotesFactory.createSession();
Database nab = s.getDatabase("", "names.nsf");
View people = nab.getView("($VIMPeople)");
Document person = people.getDocumentByKey(userName, false);
fPath = person.getItemValueString("MailFile");
//recycle our Domino objects to avoid memory hogging
person.recycle();
people.recycle();
nab.recycle();
s.recycle();
} catch (NotesException ne) {
System.out.println(ne.id + " " + ne.text);
} finally {
// return the mail file path
NotesThread.stermThread();
}
return fPath;
}
}