repo = (NNTPRepository)componentManager
.lookup("org.apache.james.nntpserver.repository.NNTPRepository");
}
public void handleConnection( Socket connection ) throws IOException {
final Logger logger = getLogger();
try {
this.socket = connection;
reader = new BufferedReader(new InputStreamReader(socket.getInputStream())) {
public String readLine() throws IOException {
String s = super.readLine();
if ( DEBUG_PROTOCOL )
logger.debug("C: "+s);
return s;
}
};
writer = new PrintWriter(socket.getOutputStream()) {
public void println() {
// lines must end with CRLF, irrespective of the OS
print("\r\n");
flush();
}
public void println(String s) {
super.println(s);
if ( DEBUG_PROTOCOL )
logger.debug("S: "+s);
}
};
logger.info( "Connection from " + socket.getInetAddress());
} catch (Exception e) {
logger.error( "Cannot open connection from: " + e.getMessage(), e );
}
try {
final PeriodicTimeTrigger trigger = new PeriodicTimeTrigger( timeout, -1 );
scheduler.addTrigger( this.toString(), trigger, this );
// section 7.1
if ( repo.isReadOnly() )
writer.println("201 "+helloName+" NNTP Service Ready, posting prohibited");
else
writer.println("200 "+helloName+" NNTP Service Ready, posting permitted");
while (parseCommand(reader.readLine()))
scheduler.resetTrigger(this.toString());
reader.close();
writer.close();
socket.close();
scheduler.removeTrigger(this.toString());
logger.info("Connection closed");
} catch (Exception e) {
doQUIT();
//writer.println("502 Error closing connection.");
//writer.flush();
logger.error( "Exception during connection:" + e.getMessage(), e );
try { socket.close(); } catch (IOException ioe) { }
}
}