1 package com.quikj.server.web; 2 3 import com.quikj.server.framework.*; 4 5 import java.io.*; 6 import java.net.*; 7 import java.util.*; 8 9 import javax.xml.parsers.*; 11 import org.xml.sax.*; 12 13 public class HTTPApplicationServer 14 { 15 public HTTPApplicationServer() 16 throws IOException, AceException, ParserConfigurationException, SAXException, UnknownHostException 17 { 18 if (AceLicenseManager.getInstance().licenseFeature("ace-application-server") == false) 19 { 20 throw new AceException(AceLicenseManager.getInstance().getErrorMessage()); 21 } 22 23 StringTokenizer token = new StringTokenizer(VERSION, "."); 24 if (AceLicenseManager.getInstance().licenseFeature("version-" 25 + token.nextToken() + "." + token.nextToken()) == false) 26 { 27 throw new AceException(AceLicenseManager.getInstance().getErrorMessage()); 28 } 29 30 31 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.SYSTEM_LOG, 32 "HTTPApplicationServer.HTTPApplicationServer() -- HTTP application server started"); 33 34 if (hostName == null) 35 { 36 try 37 { 38 hostName = InetAddress.getLocalHost().getHostName(); 39 } 40 catch (UnknownHostException ex) 41 { 42 hostName = "Unknown"; 43 } 44 } 45 46 int[] applications = PluginAppList.Instance().listApplications(); 48 for (int i = 0; i < applications.length; i++) 49 { 50 if (PluginAppList.Instance().initApplication(applications[i]) == false) 51 { 52 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 53 "HTTPApplicationServer.HTTPApplicationServer() -- " 54 + " failed to start application id " + applications[i]); 55 } 56 } 57 58 connListener = new HTTPConnectionListener(HTTPApplicationConfiguration.Instance().getListeningPort()); 60 connListener.start(); 61 62 if (HTTPApplicationConfiguration.Instance().getCommandPort() >= 0) 63 { 64 AceCommandService service = new AceCommandService("Ace Application Server " 65 + VERSION, "AAS> ", 66 HTTPApplicationConfiguration.Instance().getCommandPort(), 67 10); 68 69 service.registerCommandHandler("shutdown", 70 new AppServerShutdownCommandHandler()); 71 } 72 73 instance = this; 74 } 75 76 public void dispose() 77 { 78 if (AceCommandService.getInstance() != null) 79 { 80 AceCommandService.getInstance().dispose(); 81 } 82 83 if (connListener != null) 84 { 85 connListener.dispose(); 86 connListener = null; 87 } 88 89 instance = null; 90 } 91 92 public static HTTPApplicationServer getInstance() 93 { 94 return instance; 95 } 96 97 public void waitEnd() 98 { 99 try 100 { 101 connListener.join(); 102 System.exit(0); 103 } 104 catch (InterruptedException ex2) 105 { 106 System.err.println("InterruptedException : " + ex2.getMessage()); 107 System.exit(1); 108 } 109 } 110 111 112 public HTTPConnectionListener getConnectionListener() 113 { 114 return connListener; 115 } 116 117 public String getHostName() 118 { 119 return hostName; 120 } 121 122 public static void main(String [] args) 124 { 125 String dir = null; 126 String file = null; 127 128 for (int i = 0; i < args.length; i++) 130 { 131 if (args[i].startsWith(ARG_DIR) == true) 132 { 133 dir = args[i].substring(ARG_DIR.length()); 134 } 135 else if (args[i].startsWith(ARG_FILE) == true) 136 { 137 file = args[i].substring(ARG_FILE.length()); 138 } 139 else 140 { 141 System.err.println("Command line parameter : " 142 + args[i] 143 + " unrecognized"); 144 System.exit(1); 145 } 146 } 147 148 if ((dir == null) || (file == null)) 149 { 150 System.err.println(ARG_DIR + " and/or " + ARG_FILE 151 + " parameter missing"); 152 System.exit(1); 153 } 154 155 156 HTTPApplicationServer server = null; 157 158 try 159 { 160 AceTimer timer = new AceTimer(); 162 timer.start(); 163 164 new HTTPApplicationConfiguration(dir, file); 166 167 server = new HTTPApplicationServer(); 168 169 Runtime.getRuntime().addShutdownHook(new ShutdownThread()); 170 } 171 catch (Exception ex1) 172 { 173 if (AceLogger.Instance() == null) 174 { 175 System.err.println(ex1.getClass().getName() 176 + " occured while starting Ace application server : " 177 + ex1.getMessage()); 178 } 179 else 180 { 181 AceLogger.Instance().log(AceLogger.FATAL, AceLogger.SYSTEM_LOG, 182 "Error starting Ace application server: " 183 + ex1.getClass().getName() + ": " 184 + ex1.getMessage()); 185 186 try 187 { 188 Thread.sleep(2000L); 189 } 190 catch (InterruptedException ex) 191 { 192 ; 193 } 194 195 } 196 System.exit(1); 197 } 198 199 server.waitEnd(); 201 202 } 203 204 private static final String ARG_DIR = "dir="; 205 private static final String ARG_FILE = "file="; 206 207 private HTTPConnectionListener connListener = null; 208 private static HTTPApplicationServer instance = null; 209 210 public static String VERSION = "1.5.0"; 211 212 private String hostName; 213 } 214 215 216 217 218 219 220 221 222 223 224 225 | Popular Tags |