1 package com.quikj.server.web; 2 3 import com.quikj.server.framework.*; 4 import com.quikj.client.raccess.*; 5 6 import java.net.*; 7 import java.io.*; 8 9 import javax.xml.parsers.*; 11 import org.xml.sax.*; 12 import org.w3c.dom.*; 13 14 import java.rmi.*; 15 import java.rmi.registry.*; 16 17 public class HTTPApplicationConfiguration 18 { 19 public static final String ROOT_NODE_NAME = "http-configuration"; 20 21 public static final String EL_HTTP_SERVER = "http-server"; 22 23 public static final String ATT_HTTP_SERVER_HOST = "host"; 24 25 public static final String ATT_HTTP_SERVER_PORT = "port"; 26 27 public static final String EL_HTTP_PORT = "http-port"; 28 29 public static final String ATT_HTTP_PORT = "port"; 30 31 public static final String EL_PLUGIN_APP = "plugin-application"; 32 33 public static final String ATT_PLUGIN_APP_ID = "id"; 34 35 public static final String ATT_PLUGIN_APP_CLASS = "class"; 36 37 public static final String EL_PLUGIN_PARAM = "param"; 38 39 public static final String ATT_PLUGIN_NAME = "name"; 40 41 public static final String ATT_PLUGIN_VALUE = "value"; 42 43 public static final String EL_DB_PARAMS = "db-params"; 44 45 public static final String ATT_DB_CLASS = "class"; 46 47 public static final String ATT_DB_URL = "url"; 48 49 public static final String ATT_DB_HOST = "host"; 50 51 public static final String ATT_DB_USER = "user"; 52 53 public static final String ATT_DB_PASSWORD = "password"; 54 55 public static final String EL_LICENCE = "license"; 56 57 public static final String ATT_LICENSE_DIR = "dir"; 58 59 public static final String ATT_LICENSE_FILE = "file"; 60 61 public static final String EL_REMOTE_OPERATIONS = "remote-operations"; 62 63 public static final String ATT_REGISTRY = "registry-server"; 64 65 public static final String ATT_REGISTRY_PORT = "registry-port"; 66 67 public static final String ATT_REGISTRY_URL = "registry-url"; 68 69 public static final String ATT_REGISTRY_SERVICE = "service-name"; 70 71 public HTTPApplicationConfiguration(String dir, String file) 72 throws ArrayIndexOutOfBoundsException , FileNotFoundException, 73 IOException, AceException, SAXException, 74 ParserConfigurationException 75 { 76 absPath = AceConfigTableFileParser.getAcePath( 77 AceConfigTableFileParser.LOCAL_DATA, dir, file); 78 loadConfigurationFile(); 79 instance = this; 80 } 81 82 public static HTTPApplicationConfiguration Instance() 83 { 84 return instance; 85 } 86 87 public String getFullPathName() 88 { 89 return absPath; 90 } 91 92 public void loadConfigurationFile() throws FileNotFoundException, 93 IOException, SAXException, AceException, 94 ParserConfigurationException 95 96 { 97 File file = new File(absPath); 98 lastModTime = file.lastModified(); 99 100 FileInputStream fis = new FileInputStream(file); 101 102 DocumentBuilder doc_builder = XMLBuilder.Instance() 103 .getDocumentBuilder(); 104 Document doc = doc_builder.parse(fis); 105 106 processDoc(doc); 107 108 fis.close(); 109 } 110 111 public boolean isModified() 112 { 113 File file = new File(absPath); 114 long mod_time = file.lastModified(); 115 116 if (mod_time > lastModTime) 117 { 118 return true; 119 } 120 else 121 { 122 return false; 123 } 124 } 125 126 public String getProcessName() 127 { 128 return processName; 129 } 130 131 public int getProcessInstance() 132 { 133 return processInstance; 134 } 135 136 public int getLogGroup() 137 { 138 return logGroup; 139 } 140 141 public String getRxHostName() 142 { 143 return rxHost; 144 } 145 146 public String getTxHostName() 147 { 148 return txHost; 149 } 150 151 public int getTxPort() 152 { 153 return txPort; 154 } 155 156 public int getRxPort() 157 { 158 return rxPort; 159 } 160 161 public String getHTTPServerHost() 162 { 163 return httpServerHost; 164 } 165 166 public int getHTTPServerPort() 167 { 168 return httpServerPort; 169 } 170 171 public int getListeningPort() 172 { 173 return httpPort; 174 } 175 176 private void processDoc(Document doc) throws AceException 177 { 178 initValues(); 179 180 if (doc.getNodeType() != Node.DOCUMENT_NODE) 181 { 182 184 throw new AceException("Document does not begin with an XML node"); 185 } 186 187 Node root_element; 188 boolean root_found = false; 189 for (root_element = doc.getFirstChild(); root_element != null; root_element = root_element 190 .getNextSibling()) 191 { 192 if (root_element.getNodeType() == Node.ELEMENT_NODE) 193 { 194 if (root_element.getNodeName().equals(ROOT_NODE_NAME) == false) 195 { 196 throw new AceException("Root node name " 197 + root_element.getNodeName() + " must be " 198 + ROOT_NODE_NAME); 199 } 200 root_found = true; 201 break; 202 203 } 204 } 206 207 if (root_found == false) 208 { 209 throw new AceException("Root node " + ROOT_NODE_NAME + " not found"); 210 } 211 212 Node ele_node; 214 for (ele_node = root_element.getFirstChild(); ele_node != null; ele_node = ele_node 215 .getNextSibling()) 216 { 217 if (ele_node.getNodeType() == Node.ELEMENT_NODE) 218 { 219 String node_name = ele_node.getNodeName(); 220 221 if (node_name.equals(EL_HTTP_SERVER) == true) 222 { 223 processHTTPServer(ele_node); 224 } 225 else if (node_name.equals(EL_LICENCE) == true) 226 { 227 processLicense(ele_node); 228 } 229 else if (node_name.equals(EL_HTTP_PORT) == true) 230 { 231 processHTTPPort(ele_node); 232 } 233 else if (node_name.equals(EL_PLUGIN_APP) == true) 234 { 235 processPluginApp(ele_node); 236 } 237 else if (node_name.equals(EL_DB_PARAMS) == true) 238 { 239 processDbParams(ele_node); 240 } 241 else if (node_name.equals(EL_REMOTE_OPERATIONS) == true) 242 { 243 processRemoteOperations(ele_node); 244 } 245 else if (node_name.equals(AceConfigLogParams.EL_LOG_PARAM) == true) 246 { 247 AceConfigLogParams log_parms = new AceConfigLogParams( 248 ele_node); 249 logGroup = log_parms.getLogGroup(); 250 processName = log_parms.getProcessName(); 251 processInstance = log_parms.getProcessInstance(); 252 rxHost = log_parms.getRxHost(); 253 rxPort = log_parms.getRxPort(); 254 txHost = log_parms.getTxHost(); 255 txPort = log_parms.getTxPort(); 256 257 try 258 { 259 new AceLogger(txHost, txPort, processName, 261 processInstance, logGroup); 262 AceLogger.Instance().start(); 263 } 264 catch (Exception ex) 265 { 266 throw new AceException( 267 "System logger could not be started: " 268 + ex.getClass().getName() + ": " 269 + ex.getMessage()); 270 } 271 } 272 else if (node_name.equals(AceCommandConfigParser.EL_COMMAND) == true) 273 { 274 AceCommandConfigParser command = new AceCommandConfigParser( 275 ele_node); 276 commandPort = command.getPort(); 277 } 278 else 279 { 280 throw new AceException("Unknown element " + node_name); 281 } 282 } 283 } 285 286 if (checkParams() == false) 288 { 289 throw new AceException("Mandatory parameter(s) missing"); 290 } 291 } 292 293 private void processHTTPPort(Node node) throws AceException 294 { 295 String port_s = AceXMLHelper.getXMLAttribute(node, ATT_HTTP_PORT); 296 try 297 { 298 httpPort = Integer.parseInt(port_s); 299 } 300 catch (NumberFormatException ex) 301 { 302 throw new AceException("The HTTP port must be an integer number :" 303 + port_s); 304 } 305 } 306 307 private void processHTTPServer(Node node) throws AceException 308 { 309 String [] attributes = { ATT_HTTP_SERVER_HOST, ATT_HTTP_SERVER_PORT }; 310 311 String [] attrib_values = AceXMLHelper 312 .getXMLAttributes(node, attributes); 313 314 if ((attrib_values[0] == null) || (attrib_values[1] == null)) 315 { 316 throw new AceException("One or more options from " 317 + ATT_HTTP_SERVER_HOST + ", " + ATT_HTTP_SERVER_PORT 318 + " is not specified in " + EL_HTTP_SERVER); 319 } 320 321 httpServerHost = new String (attrib_values[0]); 322 323 try 324 { 325 httpServerPort = Integer.parseInt(attrib_values[1]); 326 } 327 catch (NumberFormatException ex) 328 { 329 throw new AceException("invalid value - " + attrib_values[1] 330 + " for the option " + ATT_HTTP_SERVER_PORT 331 + " - must be a numeric value"); 332 } 333 } 334 335 private void processRemoteOperations(Node node) throws AceException 336 { 337 String [] attributes = { ATT_REGISTRY, ATT_REGISTRY_PORT, 338 ATT_REGISTRY_URL, ATT_REGISTRY_SERVICE }; 339 340 String [] attrib_values = AceXMLHelper 341 .getXMLAttributes(node, attributes); 342 343 if (attrib_values[0] == null) 344 { 345 registry = false; 346 } 347 else if (attrib_values[0].equals("yes") == true) 348 { 349 registry = true; 350 } 351 else if (attrib_values[0].equals("no") == true) 352 { 353 registry = false; 354 } 355 else 356 { 357 throw new AceException(attrib_values[0] + " for the attribute " 358 + ATT_REGISTRY + " must have the value \"yes\" or \"no\""); 359 } 360 361 if (attrib_values[1] != null) 362 { 363 try 364 { 365 registryPort = Integer.parseInt(attrib_values[1]); 366 } 367 catch (NumberFormatException ex) 368 { 369 throw new AceException(attrib_values[1] + " for the attribute " 370 + ATT_REGISTRY_PORT + " must have a numeric value"); 371 } 372 } 373 374 if (attrib_values[2] != null) 375 { 376 registryURL = attrib_values[2]; 377 } 378 379 if (attrib_values[3] != null) 380 { 381 registryServiceName = attrib_values[3]; 382 } 383 384 try 385 { 386 if (registry == true) 387 { 388 Registry registry = LocateRegistry.createRegistry(registryPort); 390 if (AceLogger.Instance() != null) 391 { 392 AceLogger 393 .Instance() 394 .log( 395 AceLogger.INFORMATIONAL, 396 AceLogger.SYSTEM_LOG, 397 "HTTPApplicationConfiguration.processRemoteOperations() -- Registry service started at port " 398 + registryPort); 399 } 400 } 401 402 AceRMIInterface rs = new AceRMIImpl(); 404 405 String url = null; 406 if (registryURL.endsWith("/") == true) 407 { 408 url = registryURL; 409 } 410 else 411 { 412 url = registryURL + "/"; 413 } 414 415 String host = InetAddress.getLocalHost().getHostName(); 416 417 String rname = url + registryServiceName + "/" + host; 418 Naming.rebind(rname, rs); 419 420 if (AceLogger.Instance() != null) 421 { 422 AceLogger 423 .Instance() 424 .log( 425 AceLogger.INFORMATIONAL, 426 AceLogger.SYSTEM_LOG, 427 "HTTPApplicationConfiguration.processRemoteOperations() -- HTTPSRemoteService bound with name " 428 + rname); 429 } 430 } 431 catch (java.net.UnknownHostException ex0) 432 { 433 throw new AceException(ex0.getClass().getName() 434 + " occured while loading RMI service: " + ex0.getMessage()); 435 } 436 catch (RemoteException ex) 437 { 438 throw new AceException(ex.getClass().getName() 439 + " occured while loading RMI service: " + ex.getMessage()); 440 } 441 catch (MalformedURLException ex1) 442 { 443 throw new AceException(ex1.getClass().getName() 444 + " occured while loading RMI service: " + ex1.getMessage()); 445 } 446 } 447 448 private void processLicense(Node node) throws AceException 449 { 450 String [] attributes = { ATT_LICENSE_DIR, ATT_LICENSE_FILE }; 451 452 String [] attrib_values = AceXMLHelper 453 .getXMLAttributes(node, attributes); 454 455 if ((attrib_values[0] == null) || (attrib_values[1] == null)) 456 { 457 throw new AceException("One or more options from " 458 + ATT_LICENSE_DIR + ", " + ATT_LICENSE_FILE 459 + " is not specified in " + EL_LICENCE); 460 } 461 462 licenseDir = attrib_values[0]; 463 licenseFile = attrib_values[1]; 464 465 try 467 { 468 new AceLicenseManager(licenseDir, licenseFile); 469 } 470 catch (Exception ex) 471 { 472 throw new AceException( 473 "The license manager could not be started : " 474 + ex.getClass().getName() + ": " + ex.getMessage()); 475 } 476 } 477 478 private void processPluginApp(Node node) throws AceException 479 { 480 String [] attributes = { ATT_PLUGIN_APP_ID, ATT_PLUGIN_APP_CLASS }; 481 482 String [] attrib_values = AceXMLHelper 483 .getXMLAttributes(node, attributes); 484 485 if ((attrib_values[0] == null) || (attrib_values[1] == null)) 486 { 487 throw new AceException("One or more options from " 488 + ATT_PLUGIN_APP_ID + ", " + ATT_HTTP_SERVER_PORT 489 + " is not specified in " + EL_PLUGIN_APP); 490 } 491 492 int id = 0; 493 try 494 { 495 id = Integer.parseInt(attrib_values[0]); 496 } 497 catch (NumberFormatException ex) 498 { 499 throw new AceException("invalid value - " + attrib_values[0] 500 + " for the option " + ATT_PLUGIN_APP_ID 501 + " - must be a numeric value"); 502 } 503 String class_name = attrib_values[1]; 504 505 PluginParameters params = new PluginParameters(); 507 508 Node ele_node; 509 for (ele_node = node.getFirstChild(); ele_node != null; ele_node = ele_node 510 .getNextSibling()) 511 { 512 if (ele_node.getNodeType() == Node.ELEMENT_NODE) 513 { 514 if (ele_node.getNodeName().equals(EL_PLUGIN_PARAM) == true) 515 { 516 String [] sattributes = { ATT_PLUGIN_NAME, ATT_PLUGIN_VALUE }; 517 String [] sattrib_values = AceXMLHelper.getXMLAttributes( 518 ele_node, sattributes); 519 520 if ((sattrib_values[0] == null) 521 || (sattrib_values[1] == null)) 522 { 523 throw new AceException("One or more options from " 524 + ATT_PLUGIN_NAME + ", " + ATT_PLUGIN_VALUE 525 + " is not specified for " + EL_PLUGIN_PARAM 526 + " for plugin-id " + id); 527 } 528 529 params.addParameter(sattrib_values[0], sattrib_values[1]); 530 } 531 else 532 { 533 throw new AceException("invalid node name - " 534 + ele_node.getNodeName() + " for plugin-id " + id); 535 } 536 } 537 } 539 540 if (PluginAppList.Instance().add(id, class_name, params) == false) { 546 throw new AceException("Class Id: " + id + " class name: " 547 + class_name + " could not be loaded - " 548 + PluginAppList.Instance().getErrorMessage()); 549 } 550 } 551 552 private void processDbParams(Node node) throws AceException 553 { 554 String [] attributes = { ATT_DB_CLASS, ATT_DB_URL, ATT_DB_HOST, 555 ATT_DB_USER, ATT_DB_PASSWORD }; 556 557 String [] attrib_values = AceXMLHelper 558 .getXMLAttributes(node, attributes); 559 560 if ((attrib_values[0] == null) || (attrib_values[1] == null) 561 || (attrib_values[2] == null) || (attrib_values[3] == null) 562 || (attrib_values[4] == null)) 563 { 564 throw new AceException("One or more options from " + EL_DB_PARAMS 565 + " is not specified"); 566 } 567 568 new JDBCConnection(attrib_values[0], attrib_values[1], 569 attrib_values[2], attrib_values[3], attrib_values[4]); 570 } 571 572 private void initValues() 573 { 574 logGroup = 0; 575 rxHost = null; 576 rxPort = 0; 577 txHost = null; 578 txPort = 0; 579 processName = null; 580 processInstance = -1; 581 httpServerHost = null; 582 httpServerPort = 0; 583 licenseDir = null; 584 licenseFile = null; 585 commandPort = -1; 586 587 registry = false; 588 registryPort = 1099; 589 registryURL = "rmi://localhost:1099"; 590 registryServiceName = "AceHTTPSRemoteAccess"; 591 } 592 593 private boolean checkParams() 594 { 595 boolean ret = true; 596 597 if ((logGroup == 0) || (rxHost == null) || (rxPort == 0) 598 || (txHost == null) || (txPort == 0) || (processName == null) 599 || (processInstance < 0) || (httpServerHost == null) 600 || (httpServerPort <= 0) || (licenseDir == null) 601 || (licenseFile == null)) 602 { 603 ret = false; 604 } 605 return ret; 606 } 607 608 613 public java.lang.String getLicenseDir() 614 { 615 return licenseDir; 616 } 617 618 624 public void setLicenseDir(java.lang.String licenseDir) 625 { 626 this.licenseDir = licenseDir; 627 } 628 629 634 public java.lang.String getLicenseFile() 635 { 636 return licenseFile; 637 } 638 639 645 public void setLicenseFile(java.lang.String licenseFile) 646 { 647 this.licenseFile = licenseFile; 648 } 649 650 655 public int getCommandPort() 656 { 657 return commandPort; 658 } 659 660 666 public void setCommandPort(int commandPort) 667 { 668 this.commandPort = commandPort; 669 } 670 671 677 public boolean isRegistry() 678 { 679 return this.registry; 680 } 681 682 689 public void setRegistry(boolean registry) 690 { 691 this.registry = registry; 692 } 693 694 700 public int getRegistryPort() 701 { 702 return this.registryPort; 703 } 704 705 712 public void setRegistryPort(int registryPort) 713 { 714 this.registryPort = registryPort; 715 } 716 717 723 public String getRegistryURL() 724 { 725 return this.registryURL; 726 } 727 728 735 public void setRegistryURL(String registryURL) 736 { 737 this.registryURL = registryURL; 738 } 739 740 746 public String getRegistryServiceName() 747 { 748 return this.registryServiceName; 749 } 750 751 758 public void setRegistryServiceName(String registryServiceName) 759 { 760 this.registryServiceName = registryServiceName; 761 } 762 763 private long lastModTime; 764 765 private String absPath; 766 767 private int logGroup; 768 769 private String rxHost; 770 771 private int rxPort; 772 773 private String txHost; 774 775 private int txPort; 776 777 private String processName; 778 779 private int processInstance; 780 781 private String httpServerHost; 782 783 private int httpServerPort; 784 785 private int httpPort; 786 787 private String licenseDir; 788 789 private String licenseFile; 790 791 private int commandPort; 792 793 private static HTTPApplicationConfiguration instance = null; 794 795 796 private boolean registry; 797 798 799 private int registryPort; 800 801 802 private String registryURL; 803 804 805 private String registryServiceName; 806 807 } 808 809 | Popular Tags |