1 package org.enhydra.server; 2 3 import java.io.File ; 4 import java.util.ArrayList ; 5 import java.util.Date ; 6 import java.util.Enumeration ; 7 import java.util.HashMap ; 8 import java.util.Hashtable ; 9 import java.util.Iterator ; 10 11 import javax.servlet.Servlet ; 12 13 import org.enhydra.server.conf.EnhydraServerXML; 14 import org.enhydra.server.util.PathUtil; 15 import org.enhydra.server.util.UnpackWar; 16 17 import com.lutris.appserver.server.Application; 18 import com.lutris.appserver.server.httpPresentation.servlet.HttpPresentationServlet; 19 import com.lutris.appserver.server.session.MemoryPersistence; 20 import com.lutris.logging.LogChannel; 21 import com.lutris.logging.Logger; 22 import com.lutris.util.Config; 23 24 46 public class EnhydraServer { 47 50 public static final String APPS_DIR = "apps"; 52 public static final String SERVER = "Server"; 53 public static final String APPLICATION = "Application"; 54 public static final String CONF_FILE = "ConfFile"; 55 public static final String CONF_FILE_CLASS = "ConfFileClass"; public static final String DEFAULT_CONF_FILE_CLASS = "com.lutris.util.ConfigFile"; 58 public static final String LOG_CLASS = "LogClassName"; public static final String DEFAULT_LOG_CLASS = "com.lutris.logging.StandardLogger"; 61 public static final String SERVLET = "Servlet"; 62 public static final String CLASS_NAME = "ClassName"; 63 public static final String DOC_ROOT = "DocRoot"; 64 public static final String DESCRIPTION = "Description"; 65 public static final String RUNNING = "Running"; 66 public static final String CLASS_PATH = "ClassPath"; 67 public static final String INIT_ARGS = "InitArgs"; 68 public static final String URL = "Url"; 69 public static final String CONNECTION = "Connection"; 70 public static final String ENABLED = "Enabled"; 71 public static final String APP_CLASS = "AppClass"; 72 public static final String PRESENTATION_PREFIX = "PresentationPrefix"; 73 public static final String AUTO_RELOAD = "AutoReload"; 74 public static final String SESSION_MANAGER = "SessionManager"; 75 public static final String SESSION_MANAGER_KEY = "org.enhydra.session.manager"; 76 78 81 protected static final String APP_URLPATH = "URLPath"; protected static final String APP_CONTEXTPATH = "contextPath"; protected static final String APP_NAME = "name"; 84 protected static final String APP_DESCRIPTION = "description"; 85 protected static final String APP_RUNNING = "running"; 86 protected static final String APP_CONNECTIONS = "connections"; 90 private static EnhydraServer enhydraServer = null; 91 94 private static String appsDir = null; 95 98 102 private Hashtable apps; 103 106 private ArrayList connectionPorts; 107 110 private ApplicationServer applicationServer; 111 114 private EnhydraServerXML serverConfig; 115 118 private static boolean started = false; 119 122 private int debug = 0; 123 124 private static Logger standardLogger; 125 private static LogChannel logChannel = null; 126 127 128 private EnhydraServer() { 129 132 134 151 152 if (Logger.getCentralLogger() != null) 160 logChannel = Logger.getCentralLogger().getChannel("Enhydra"); 161 162 } 178 181 private void init(){ 182 183 logChannel.write(Logger.DEBUG, "init()"); 185 apps = new Hashtable (); 186 applicationServer = null; 187 connectionPorts = new ArrayList (0); 188 } 189 194 public static EnhydraServer getInstance(){ 195 if (enhydraServer == null) { 196 enhydraServer = new EnhydraServer(); 197 enhydraServer.init(); 198 } 199 return enhydraServer; 200 } 201 207 public synchronized void startup(){ 208 logChannel.write(Logger.INFO,"Startup Enhydraserver ..."); 209 try{ 210 String home = System.getProperty("enhydra.home"); 211 if(appsDir == null){ 213 214 File appsDirFile = new File (home,APPS_DIR); 215 appsDir = appsDirFile.getAbsolutePath(); 216 } 217 logChannel.write(Logger.DEBUG,"conf dir="+appsDir); 218 File cFile = new File (home,"conf/EnhydraServer.xml"); 220 serverConfig = new EnhydraServerXML(cFile.getAbsolutePath()); 221 222 228 }catch(Exception e){ 229 logChannel.write(Logger.ALERT,"Fail to startup EnhydraServer", e); 230 return; 231 } 232 233 if (applicationServer == null){ 234 logChannel.write(Logger.ERROR,"Can't startup EnhydraServer, applicationServer = null"); 235 return; 236 } 237 if (started){ 238 logChannel.write(Logger.WARNING,"EnhydraServer already started"); 239 return; 240 } 241 242 try{ 243 244 246 HashMap [] appsHash = serverConfig.getApplications(); 248 249 String [] appNames = new String [appsHash.length]; 250 for(int i=0;i<appsHash.length;i++){ 251 appNames[i] = (String ) appsHash[i].get(APP_NAME); 252 } 253 if(appNames != null){ 254 for (int i=0;i<appNames.length;i++){ 255 AppInfo appInfo = new AppInfo(appNames[i],appsHash[i]); 257 apps.put(appNames[i],appInfo); 258 logChannel.write(Logger.INFO,"add Application "+i+":"+appNames[i]); 259 if(appInfo.isRunning()){ 260 appInfo.setRunning(false); startApplication(appNames[i]); } 263 } 264 } 265 }catch (Exception e){ 266 logChannel.write(Logger.ERROR,"... at startup():",e); 267 return; 268 } 269 started = true; 270 logChannel.write(Logger.INFO,"EnhydraServer is startup successfuly"); 271 } 272 273 277 public void register(Servlet servlet){ if (servlet == null){ 279 logChannel.write(Logger.ERROR,"Unable to register application, servlet = NULL"); 280 return; 281 } 282 AppInfo appInfo = null; 283 try{ 287 288 AppInfo appInfoTemp = new AppInfo(servlet); 289 String appName = appInfoTemp.getName(); 290 File urlPathTemp = new File (appInfoTemp.getUrlPath()); 291 if(apps.containsKey(appName)){ 292 appInfo = ((AppInfo) apps.get(appName)); 293 if(!urlPathTemp.equals(new File (appInfo.getUrlPath()))) 295 appInfo = null; 296 } 297 if(appInfo==null){ 300 Enumeration keys = apps.keys(); 301 while(keys.hasMoreElements() && (appInfo==null)){ 302 appInfo = ((AppInfo) apps.get((String ) keys.nextElement())); 303 if(!urlPathTemp.equals(new File (appInfo.getUrlPath()))) 304 appInfo = null; 305 } 306 } 307 if(appInfo != null){ 309 appInfo.setApplication(appInfoTemp.getApplication()); 310 }else{ 311 appInfo = appInfoTemp; 317 appInfo.setDescription("Auto registered Enhydra application."); 318 apps.put(appName, appInfo); 319 } 320 if(!appInfo.isRunning()){ 321 appInfo.setRunning(true); 322 appInfo.setStarted(new Date ()); 323 } 324 logChannel.write(Logger.INFO,"Application "+appName+" successfuly registered"); 325 }catch(Exception e) {logChannel.write(Logger.ERROR, "in register() ",e);} 326 return; 327 } 328 332 public void unRegister(Servlet servlet){ 333 if (servlet instanceof HttpPresentationServlet){ 334 335 String appName = ((HttpPresentationServlet) servlet).getApplication().getName(); 336 if (appName != null){ 337 if(apps.containsKey(appName)){ 338 ((AppInfo) apps.get(appName)).setRunning(false); 339 logChannel.write(Logger.INFO,"Application "+appName+" successfuly unregistered"); 340 } 341 } 342 } 343 } 344 345 350 public static void setAppsfDir(String dir){ 351 appsDir = dir; 352 } 353 354 358 public String getAppsDir(){ 359 return appsDir; 360 } 361 362 364 365 370 public AppInfo getAppInfo(String appName){ 371 AppInfo appInfo = (AppInfo)apps.get(appName); 372 if (appInfo == null){ 373 logChannel.write(Logger.WARNING,"EnhydraServer: Can't get AppInfo,"+appName+" not registered"); 374 return null; 375 } 376 377 return appInfo; 378 } 379 380 385 public PresentationInfo getPresentationInfo(String appName){ 386 PresentationInfo presInfo = null; 387 Config config = null; 388 AppInfo appInfo = null; 389 Application app = null; 390 try{ 391 if(apps.containsKey(appName)){ 392 393 appInfo = (AppInfo) apps.get(appName); 394 app = appInfo.getApplication(); 395 config = (Config)appInfo.getConfig(); 396 if ( config!=null ) 397 if ( config.containsKey("PresentationManager")) 398 config = (Config) config.getSection("PresentationManager"); 399 presInfo = new PresentationInfo(app,config); 400 }else logChannel.write(Logger.WARNING,"Can't get PresentationInfo, "+appName+" don't exist!"); 401 } 402 catch(Exception e) { 403 logChannel.write(Logger.ERROR,"Exception in getPresentationInfo", e); 405 } 406 return presInfo; 407 } 408 409 414 public SessionsInfo getSessionsInfo(String appName){ 415 SessionsInfo sessInfo = null; 416 Config config = null; 417 AppInfo appInfo = null; 418 Application app = null; 419 try{ 420 if(apps.containsKey(appName)){ 421 422 appInfo = (AppInfo) apps.get(appName); 423 app = appInfo.getApplication(); 424 config = (Config)appInfo.getConfig(); 425 if ( config!=null ) 426 if ( config.containsKey("SessionManager")) config = (Config) config.getSection("SessionManager"); 427 sessInfo = new SessionsInfo(app,config); 428 }else logChannel.write(Logger.ERROR,"Can't get SessionInfo, "+appName+" don't exist!"); 429 }catch(Exception e){ 430 logChannel.write(Logger.ERROR,"Exception in getSessionInfo()",e); 432 } 433 return sessInfo; 434 } 435 436 441 public SessionEdit getSessionEdit(String appName){ 442 AppInfo appInfo = null; 443 SessionEdit sessEdit = null; 444 Config config = null; 445 try{ 446 if(apps.containsKey(appName)){ 447 appInfo = (AppInfo) apps.get(appName); 448 config = (Config)appInfo.getConfig(); 449 sessEdit = new SessionEdit(config); 450 }else logChannel.write(Logger.WARNING,"Can't get SessionEdit, "+appName+" don't exist!"); 451 }catch(Exception e){ 452 logChannel.write(Logger.ERROR,"Exception in getSessionEdit",e); 454 } 455 return sessEdit; 456 } 457 458 463 public DatabaseInfo getDatabaseInfo(String appName){ 464 DatabaseInfo dbInfo = null; 465 Config config = null; 466 AppInfo appInfo = null; 467 Application app = null; 468 try{ 469 if(apps.containsKey(appName)){ 470 471 appInfo = (AppInfo) apps.get(appName); 472 app = appInfo.getApplication(); 473 config = (Config)appInfo.getConfig(); 474 if ( config!=null ) 475 dbInfo = new DatabaseInfo(app,config); 477 }else logChannel.write(Logger.ERROR,"Can't get DatabaseInfo, "+appName+" don't exist!"); 478 }catch(Exception e){ 479 logChannel.write(Logger.ERROR,"Exception in getDatabaseInfo",e); 481 } 482 return dbInfo; 483 } 484 485 491 public DatabaseEdit getDatabaseEdit(String appName) { 492 AppInfo appInfo = null; 493 DatabaseEdit databaseEdit = null; 494 Config config = null; 495 try{ 496 if(apps.containsKey(appName)){ 497 appInfo = (AppInfo) apps.get(appName); 498 config = (Config)appInfo.getConfig(); 499 databaseEdit = new DatabaseEdit(config); 500 } 501 else logChannel.write(Logger.ERROR,"Can't get DatabaseEdit, "+appName+" don't exist!"); 502 } 503 catch(Exception e) { 504 logChannel.write(Logger.ERROR,"Exception in getDatabaseEdit",e); 506 } 507 return databaseEdit; 508 } 509 510 514 public ApplicationServer getApplicationServer(){ 515 if(applicationServer == null) logChannel.write(Logger.WARNING,"ApplicationServer = null"); 516 return applicationServer; 517 } 518 519 524 public void setApplicationServer(ApplicationServer appServ){ 525 applicationServer = appServ; 526 } 527 532 private void updateServerConfig(AppInfo appInfo){ 533 HashMap appHash = new HashMap (); 534 appHash.put(APP_CONTEXTPATH, appInfo.getContextPath()); 536 appHash.put(APP_URLPATH, PathUtil.makeRelativePath(appsDir, appInfo.getUrlPath())); 538 appHash.put(APP_NAME, appInfo.getName()); 539 if(appInfo.isRunning()){ 540 appHash.put(APP_RUNNING, "true"); 541 }else{ 542 appHash.put(APP_RUNNING, "false"); 543 } 544 appHash.put(APP_DESCRIPTION,appInfo.getDescription()); 545 int[] conns = appInfo.getConnections(); 546 String connections = ""; 547 if(conns != null){ 548 for(int i=0; i<conns.length; i++){ 549 if(i==0){ 550 connections = Integer.toString(conns[i]); 551 }else{ 552 connections += ","+Integer.toString(conns[i]); 553 } 554 } 555 } 556 appHash.put(APP_CONNECTIONS, connections); 557 if(serverConfig.getApplication(appInfo.getContextPath()) != null){ 559 serverConfig.removeApplication(appInfo.getContextPath()); 560 } 561 serverConfig.addApplication(appHash); 562 } 563 567 public boolean saveState(){ 568 boolean isOK = true; 569 logChannel.write(Logger.WARNING,"Saving current EnhydraServer config state ..."); 570 try{ 571 serverConfig.saveDocument(); 575 }catch(Exception e){ 576 logChannel.write(Logger.WARNING,"Can't write EnhydraServer.conf file",e); 577 isOK = false; 578 } 579 return isOK; 580 } 581 582 587 public boolean startApplication(String appName){ 588 589 AppInfo appInfo = (AppInfo) apps.get(appName); 590 logChannel.write(Logger.INFO,"Starting "+appName+" at context path ="+appInfo.getContextPath()+", URL path = "+ appInfo.getUrlPath()); 591 if (appInfo == null){ 592 logChannel.write(Logger.INFO,"Can't start application, invalid application name: "+appName); 593 return false; 594 } 595 if (appInfo.isRunning()){ 596 logChannel.write(Logger.WARNING,"Can't start application : "+appName+", already started"); 597 return false; 598 } 599 if (applicationServer == null){ 600 logChannel.write(Logger.ERROR,"Can't start application, Unknown Application Server"); 601 return false; 602 } 603 if (!applicationServer.startApp(appName)){ 604 logChannel.write(Logger.ERROR,"Can't start application, ApplicationServer.startApp() FAIL"); 605 return false; 606 } 607 try{ 609 appInfo.getWebAppXML().reloadDocument(); appInfo.setRunning(true); 611 appInfo.setStarted(new Date ()); 612 615 updateServerConfig(appInfo); 621 }catch(Exception e){ 622 logChannel.write(Logger.WARNING,"Application started but fail to change EnhydraServer.conf",e); 623 } 624 625 return true; 626 } 627 632 public boolean stopApplication(String appName){ 633 AppInfo appInfo = (AppInfo) apps.get(appName); 635 if (appInfo == null){ 636 logChannel.write(Logger.ERROR,"Can't stop application, invalid application name: "+appName); 637 return false; 638 } 639 if (!appInfo.isRunning()){ 640 logChannel.write(Logger.ERROR,"Can't stop application : "+appName+", not started"); 641 return false; 642 } 643 if (applicationServer == null){ 644 logChannel.write(Logger.ERROR,"Can't stop application, Unknown Application Server"); 645 return false; 646 } 647 if (!applicationServer.stopApp(appName)){ 648 logChannel.write(Logger.ERROR,"Can't stop application, ApplicationServer.stopApp() FAIL"); 649 return false; 650 } 651 try{ 654 appInfo.setRunning(false); 655 appInfo.setStarted(null); updateServerConfig(appInfo); 658 }catch(Exception e){ 659 logChannel.write(Logger.WARNING,"Application stopped but fail to change EnhydraServer.conf",e); 660 } 661 return true; 662 } 663 666 public void stopApplicationServer(){ 667 if (applicationServer == null) 668 logChannel.write(Logger.ERROR,"Can't shutdown application server, applicationServer = null"); 669 else{ 670 applicationServer.stop(); 671 logChannel.write(Logger.INFO,applicationServer.getName()+" stopped"); 672 } 673 } 674 677 public synchronized void shutdown(){ 678 logChannel.write(Logger.INFO,"Shuting down EnhydraServer..."); 679 Enumeration enumApps = apps.keys(); 681 String appName; 682 AppInfo appInfo; 683 while(enumApps.hasMoreElements()){ 684 appName = (String )enumApps.nextElement(); 685 appInfo = (AppInfo)apps.get(appName); 686 if(appInfo.isRunning()) stopApplication(appName); 687 } 688 logChannel.write(Logger.INFO,"EnhydraServer is shutdown !"); 695 MemoryPersistence.shutdown(); apps = new Hashtable (); 697 connectionPorts = new ArrayList (0); 698 started = false; 699 } 700 701 708 public boolean addConnection(String type, String port){ 709 if (applicationServer == null){ 710 logChannel.write(Logger.WARNING,"Can't add connection, applicationServer = null !"); 711 return false; 712 } 713 714 if (applicationServer.addConnection(type,port)){ 715 connectionPorts.add(port); 716 logChannel.write(Logger.INFO,"Connection ("+port+","+type+") added."); 717 return true; 718 } 719 return false; 720 } 721 722 730 public boolean addConnection(String type, String port, String password, String pathToKeyStoreFile){ 731 if (applicationServer == null){ 732 logChannel.write(Logger.WARNING,"Can't add connection, applicationServer = null !"); 733 return false; 734 } 735 if (applicationServer.addConnection(type, port, password, pathToKeyStoreFile)){ 736 connectionPorts.add(port); 737 logChannel.write(Logger.INFO,"Connection ("+port+","+type+") added."); 738 return true; 739 } 740 return false; 741 } 742 743 public boolean removeConnection(String port){ 744 if (applicationServer == null){ 745 logChannel.write(Logger.WARNING,"Can't remove connection, applicationServer = null !"); 746 return false; 747 } 748 if (applicationServer.removeConnection(port)){ 749 try{ 750 connectionPorts.remove(port); 751 }catch(Exception e){ 755 logChannel.write(Logger.WARNING,"Fail to remove connection from config!",e); 756 } 757 return true; 758 } 759 return false; 760 } 761 762 768 public boolean enableConnection(String appName, String portNumber){ 769 AppInfo appInfo = ((AppInfo) apps.get(appName)); 773 int enablePort = Integer.parseInt(portNumber); 774 int[] connections = appInfo.getConnections(); 775 int[] newConnections = null; 776 if(connections == null){ 777 newConnections = new int[1]; 778 newConnections[0] = enablePort; 779 }else{ 780 newConnections = new int[connections.length+1]; 781 newConnections[0] = enablePort; 782 for(int i=0; i<connections.length; i++){ 783 if(connections[i] == enablePort){ 784 logChannel.write(Logger.DEBUG,"Connection on port: "+portNumber+"allready enabled for application "+appName); 785 return false; 786 } 787 newConnections[i+1] = connections[i]; 788 } 789 } 790 appInfo.setConnections(newConnections); 791 updateServerConfig(appInfo); 792 logChannel.write(Logger.INFO,"Connection on port: "+portNumber+" enabled for application "+appName); 793 return true; 794 } 795 796 802 public boolean disableConnection(String appName, String portNumber){ 803 ArrayList enabledConnsList = new ArrayList (0); 807 AppInfo appInfo = ((AppInfo) apps.get(appName)); 808 int disablePort = Integer.parseInt(portNumber); 809 int[] connections = appInfo.getConnections(); 810 811 if(connections != null){ 812 for(int i=0; i<connections.length; i++){ 813 if(connections[i] != disablePort){ 814 enabledConnsList.add(Integer.toString(connections[i])); 815 } 816 } 817 } 818 Object [] objs = enabledConnsList.toArray(); 819 connections = new int[objs.length]; 820 for(int i=0;i<objs.length;i++){ 822 connections[i] = Integer.parseInt((String ) objs[i]); 823 } 824 appInfo.setConnections(connections); 825 updateServerConfig(appInfo); 826 logChannel.write(Logger.INFO,"Connection on port: "+portNumber+" disabled for application "+appName); 827 return true; 828 } 829 830 836 public String [] getEnabledConnections(String appName){ 837 AppInfo appInfo = ((AppInfo) apps.get(appName)); 838 839 String [] enabledPorts = null; 840 int[] connections = appInfo.getConnections(); 841 if(connections != null){ 842 enabledPorts = new String [connections.length]; 843 for(int i=0; i<connections.length; i++){ 844 enabledPorts[i] = Integer.toString(connections[i]); 845 } 846 } 847 return enabledPorts; 848 } 849 850 856 public Config getAppConfig(String appName){ 857 AppInfo ai = (AppInfo) apps.get(appName); 858 if(ai==null){ 859 logChannel.write(Logger.WARNING,"Application "+appName+" not available!"); 860 return null; 861 } 862 return ai.getConfig(); 863 } 864 867 public String [] getAppNames(){ 868 String [] appNames = null; 870 try{ 871 Enumeration enumKeys = apps.keys(); 873 if(enumKeys != null){ 874 appNames = new String [apps.size()]; 875 for(int i=0;enumKeys.hasMoreElements();i++){ 876 appNames[i] = (String ) enumKeys.nextElement(); 877 } 878 } 879 }catch(Exception e){ logChannel.write(Logger.ERROR,"Exception in getAppNames",e);} 880 return appNames; 881 } 882 883 public EnhydraServerXML getConfig(){ 884 return serverConfig; 885 } 886 887 896 897 public boolean addApplication(String appName, String contextPath, String urlFilePath,String description){ 898 String message = null; 899 HashMap appHash = new HashMap (); 900 String urlPath = null; 901 urlFilePath = PathUtil.makeAbsolutePath(getAppsDir(), urlFilePath); 902 903 File urlFile = new File (urlFilePath); 904 if(appName == null){ 905 logChannel.write(Logger.ERROR,"Couldn't add application, application name = null"); 906 return false; 907 } 908 appName.trim(); if(appName.equals("")){ 910 logChannel.write(Logger.ERROR,"Couldn't add application, application name = \"\""); 911 return false; 912 } 913 if(!urlFile.exists()){ 915 logChannel.write(Logger.ERROR,"Couldn't add "+appName+". URL Path file:'"+urlFilePath+"' don't exist!"); 916 return false; 917 } 918 if(urlFile.isDirectory()){ 919 urlPath = urlFilePath; 920 if(!checkApplication(appName,contextPath, urlPath)){ 922 return false; 923 } 924 }else if(urlFile.isFile()){ 925 String fileName = urlFile.getName(); 927 urlPath = fileName.substring(0, fileName.length()-4); 928 if(!checkApplication(appName,contextPath, urlPath)){ 930 return false; 931 } 932 UnpackWar unpack = new UnpackWar(urlFilePath, PathUtil.makeAbsolutePath(getAppsDir(),urlPath)); 934 try{ 935 unpack.execute(); 936 }catch(Exception e){ 937 logChannel.write(Logger.ERROR,"Couldn't add "+appName+"!", e); 938 return false; 939 } 940 } 941 942 943 if(!contextPath.startsWith("/")){ 944 logChannel.write(Logger.ERROR,"Couldn't add "+appName+". Context path must start with '/'!"); 945 return false; }else{ 947 appHash.put(APP_CONTEXTPATH, contextPath); 948 } 949 950 if (apps.get(appName)!= null){ 951 message = "Couldn't add "+appName+". Application "+appName+" already exist!"; 952 logChannel.write(Logger.WARNING,message); 953 return false; 954 }else{ 955 appHash.put(APP_NAME, appName); 956 } 957 appHash.put(APP_URLPATH, urlPath); 958 appHash.put(APP_DESCRIPTION, description); 959 appHash.put(APP_RUNNING, "false"); 960 961 try{ 962 AppInfo appInfo = new AppInfo(appName, appHash); 963 apps.put(appName,appInfo); 964 updateServerConfig(appInfo); 965 }catch(Exception e){ 966 logChannel.write(Logger.ERROR,"ERROR in EnhydraServer.addApplication",e); 967 return false; 968 } 969 970 return true; 971 } 972 973 980 private boolean checkApplication(String appName, String contextPath, String urlPath){ 981 Iterator iter = apps.values().iterator(); 982 AppInfo appInfo = null; 983 String message = null; 984 boolean notExist = true; 985 while( iter.hasNext()){ 986 appInfo = (AppInfo)iter.next(); 987 if(appInfo.getName().equalsIgnoreCase(appName)){ 989 message = "Application name '"+appName+"' allready exist!"; 990 notExist = false; 991 break; 992 } 993 if(appInfo.getContextPath().equalsIgnoreCase(contextPath)){ 995 message = "Application contextPath '"+appName+"' allready exist!"; 996 notExist = false; 997 break; 998 } 999 urlPath = PathUtil.makeAbsolutePath(getAppsDir(), urlPath); 1001 if(PathUtil.makeAbsolutePath(getAppsDir(), appInfo.getUrlPath()).equalsIgnoreCase(urlPath)){ 1002 message = "Application urlPath '"+urlPath+"' allready exist!"; 1003 notExist = false; 1004 break; 1005 } 1006 } 1007 if(!notExist){ 1008 logChannel.write(Logger.ERROR,message); 1009 } 1010 return notExist; 1011 } 1012 1013 1018 public boolean removeApplication(String appName){ 1019 if(!apps.containsKey(appName)){ 1020 logChannel.write(Logger.WARNING,"in removeApplication(): "+appName+" don't exist!"); 1021 return false; 1022 } 1023 AppInfo appInfo = (AppInfo) apps.get(appName); 1024 if (appInfo.isRunning()){ 1025 if(!stopApplication(appName)){ 1026 return false; 1027 } 1028 } 1029 1030 apps.remove(appName); 1031 serverConfig.removeApplication(appInfo.getContextPath()); 1033 1034 logChannel.write(Logger.INFO,"Application "+appName+" removed successfuly."); 1035 return true; 1036 } 1037 1041 public boolean isStarted(){ 1042 return started; 1043 } 1044} | Popular Tags |