1 13 26 27 package org.ejbca.ui.tcp; 28 29 import java.io.File ; 30 import java.net.UnknownHostException ; 31 import java.util.Properties ; 32 import java.util.logging.FileHandler ; 33 import java.util.logging.Level ; 34 import java.util.logging.Logger ; 35 36 import org.apache.commons.lang.StringUtils; 37 import org.quickserver.net.AppException; 38 import org.quickserver.net.server.QuickServer; 39 40 43 public class CmpTcpServer { 44 45 public static String VER = "1.0"; 46 47 public static QuickServer myServer = null; 48 49 public static void init(Properties prop) { 50 CmpTcpConfiguration.instance().init(prop); 51 } 52 53 public static void start() throws UnknownHostException { 54 String cmdHandle = "org.ejbca.ui.tcp.CmpTcpCommandHandler"; 55 String auth = null; 56 57 myServer = new QuickServer(); 58 myServer.setClientAuthenticationHandler(auth); 59 myServer.setBindAddr(CmpTcpConfiguration.instance().getBindHost()); 60 myServer.setPort(CmpTcpConfiguration.instance().getPort()); 61 myServer.setName("CMP TCP Server v " + VER); 62 if(getQuickServerVersion() >= 1.2) { 63 System.out.println("Using 1.2 feature"); 64 myServer.setClientBinaryHandler(cmdHandle); 65 myServer.setClientEventHandler(cmdHandle); 66 67 myServer.setConsoleLoggingToMicro(); 69 } 70 71 Logger logger = null; 73 FileHandler txtLog = null; 74 String logDir = CmpTcpConfiguration.instance().getLogDir(); 75 File log = new File (logDir + "/"); 76 if(!log.canRead()) 77 log.mkdir(); 78 try { 79 logger = Logger.getLogger(""); 80 logger.setLevel(Level.FINEST); 81 82 logger = Logger.getLogger("cmptcpserver"); 83 logger.setLevel(Level.FINEST); 84 txtLog = new FileHandler (logDir+"/cmptcpserver.log"); 85 txtLog.setFormatter(new org.quickserver.util.logging.MicroFormatter()); 87 logger.addHandler(txtLog); 88 89 myServer.setAppLogger(logger); 91 myServer.setConsoleLoggingFormatter("org.quickserver.util.logging.SimpleTextFormatter"); 93 myServer.setConsoleLoggingLevel(Level.INFO); 94 } catch(Exception e){ 95 System.err.println("Could not create xmlLog FileHandler : "+e); 96 } 97 99 try { 100 String confFile = CmpTcpConfiguration.instance().getConfFile(); 101 if (!StringUtils.isEmpty(confFile)) { 102 Object config[] = new Object [] {confFile}; 103 if (myServer.initService(config) == false) { 104 System.out.println("Configuration from config file "+confFile+" failed!"); 105 } 106 } 107 108 myServer.startServer(); 109 } catch(AppException e){ 112 System.out.println("Error in server : "+e); 113 e.printStackTrace(); 114 } 115 } 116 117 public static void stop() { 118 if (myServer != null) { 119 try { 120 myServer.stopServer(); 121 } catch (AppException e) { 122 System.out.println("Error in server : "+e); 123 e.printStackTrace(); 124 } 125 } 126 } 127 public static float getQuickServerVersion() { 128 return QuickServer.getVersionNo(); 129 } 130 } 131 132 133 | Popular Tags |