Methods Summary |
---|
protected static synchronized org.apache.axis.server.AxisServer | getAxisServer()
if (myAxisServer == null) {
myAxisServer = new AxisServer();
}
return myAxisServer;
|
public boolean | getDoThreads()
return doThreads;
|
public java.lang.String | getHost()
return host;
|
public org.apache.commons.net.pop3.POP3Client | getPOP3()Obtain the serverSocket that that MailServer is listening on.
return pop3;
|
public static void | main(java.lang.String[] args)Server process.
Options opts = null;
try {
opts = new Options(args);
} catch (MalformedURLException e) {
log.error(Messages.getMessage("malformedURLException00"), e);
return;
}
try {
doThreads = (opts.isFlagSet('t") > 0);
String host = opts.getHost();
int port = ((opts.isFlagSet('p") > 0) ? opts.getPort() : 110);
POP3Client pop3 = new POP3Client();
MailServer sas = new MailServer(host, port, opts.getUser(), opts.getPassword());
sas.setPOP3(pop3);
sas.start();
} catch (Exception e) {
log.error(Messages.getMessage("exception00"), e);
return;
}
|
public void | run()Accept requests from a given TCP port and send them through the
Axis engine for processing.
log.info(Messages.getMessage("start00", "MailServer", host + ":" + port));
// Accept and process requests from the socket
while (!stopped) {
try {
pop3.connect(host, port);
pop3.login(userid, password);
POP3MessageInfo[] messages = pop3.listMessages();
if (messages != null && messages.length > 0) {
for (int i = 0; i < messages.length; i++) {
Reader reader = pop3.retrieveMessage(messages[i].number);
if (reader == null) {
continue;
}
StringBuffer buffer = new StringBuffer();
BufferedReader bufferedReader =
new BufferedReader(reader);
int ch;
while ((ch = bufferedReader.read()) != -1) {
buffer.append((char) ch);
}
bufferedReader.close();
ByteArrayInputStream bais = new ByteArrayInputStream(buffer.toString().getBytes());
Properties prop = new Properties();
Session session = Session.getDefaultInstance(prop, null);
MimeMessage mimeMsg = new MimeMessage(session, bais);
pop3.deleteMessage(messages[i].number);
if (mimeMsg != null) {
MailWorker worker = new MailWorker(this, mimeMsg);
if (doThreads) {
Thread thread = new Thread(worker);
thread.setDaemon(true);
thread.start();
} else {
worker.run();
}
}
}
}
} catch (java.io.InterruptedIOException iie) {
} catch (Exception e) {
log.debug(Messages.getMessage("exception00"), e);
break;
} finally {
try {
pop3.logout();
pop3.disconnect();
Thread.sleep(3000);
} catch (Exception e) {
log.error(Messages.getMessage("exception00"), e);
}
}
}
log.info(Messages.getMessage("quit00", "MailServer"));
|
public void | setDoThreads(boolean value)
doThreads = value;
|
public void | setPOP3(org.apache.commons.net.pop3.POP3Client pop3)Set the serverSocket this server should listen on.
(note : changing this will not affect a running server, but if you
stop() and then start() the server, the new socket will be used).
this.pop3 = pop3;
|
public void | start()Start this server as a NON-daemon.
start(false);
|
public void | start(boolean daemon)Start this server.
Spawns a worker thread to listen for HTTP requests.
if (doThreads) {
Thread thread = new Thread(this);
thread.setDaemon(daemon);
thread.start();
} else {
run();
}
|
public void | stop()Stop this server.
This will interrupt any pending accept().
/*
* Close the server socket cleanly, but avoid fresh accepts while
* the socket is closing.
*/
stopped = true;
log.info(Messages.getMessage("quit00", "MailServer"));
// Kill the JVM, which will interrupt pending accepts even on linux.
System.exit(0);
|