1 19 20 package org.apache.james.imapserver.util; 21 22 import java.io.IOException ; 23 import java.net.ServerSocket ; 24 import java.net.Socket ; 25 26 import javax.mail.MessagingException ; 27 28 import org.apache.avalon.framework.configuration.ConfigurationException; 29 import org.apache.avalon.framework.configuration.DefaultConfiguration; 30 import org.apache.avalon.framework.container.ContainerUtil; 31 import org.apache.james.imapserver.ImapHandler; 32 import org.apache.james.imapserver.TestConstants; 33 import org.apache.james.imapserver.mock.MockImapHandlerConfigurationData; 34 import org.apache.james.imapserver.mock.MockWatchdog; 35 import org.apache.james.mailboxmanager.MailboxManagerException; 36 import org.apache.james.services.DNSServer; 37 import org.apache.james.test.mock.avalon.MockLogger; 38 39 public class ImapServerLauncher implements TestConstants 40 { 41 42 43 private DNSServer dnsServer; 44 45 public void go() throws IOException , MessagingException , MailboxManagerException 46 { 47 ServerSocket ss = new ServerSocket (HOST_PORT); 48 final MockImapHandlerConfigurationData theConfigData=new MockImapHandlerConfigurationData(); 49 while (true) { 50 51 final Socket s=ss.accept(); 52 new Thread () { 53 public void run() { 54 try { 55 ImapHandler imapHandler=new ImapHandler(); 56 imapHandler.enableLogging(new MockLogger()); 57 imapHandler.setConfigurationData(theConfigData); 58 imapHandler.setDnsServer(getDNSServer()); 59 imapHandler.setStreamDumpDir("streamdump"); 60 imapHandler.setWatchdog(new MockWatchdog()); 61 System.out.println("Handle connection "+s); 62 imapHandler.handleConnection(s); 63 System.out.println("Handle connection finished."+s); 64 65 } catch (Exception e) { 66 throw new RuntimeException (e); 67 } 68 } 69 }.start(); 70 71 72 } 73 74 } 75 76 public DNSServer getDNSServer() throws Exception { 77 dnsServer=new org.apache.james.dnsserver.DNSServer(); 78 ContainerUtil.enableLogging(dnsServer, new MockLogger()); 79 ContainerUtil.configure(dnsServer, new DefaultConfiguration("dnsserver")); 80 ContainerUtil.initialize(dnsServer); 81 return dnsServer; 82 } 83 84 public static void main(String [] args) 85 { 86 try { 87 new ImapServerLauncher().go(); 88 } catch (Exception e) { 89 throw new RuntimeException (e); 90 } 91 92 } 93 94 } 95 | Popular Tags |