1 23 package com.sun.enterprise.appclient; 24 25 import com.sun.appserv.naming.S1ASCtxFactory; 26 import com.sun.enterprise.appclient.AppContainer; 27 import com.sun.enterprise.appclient.HttpAuthenticator; 28 import com.sun.enterprise.appclient.jws.TemplateCache; 29 import com.sun.enterprise.appclient.jws.Util; 30 import com.sun.enterprise.config.clientbeans.CertDb; 31 import com.sun.enterprise.config.clientbeans.ClientBeansFactory; 32 import com.sun.enterprise.config.clientbeans.ClientContainer; 33 import com.sun.enterprise.config.clientbeans.ClientCredential; 34 import com.sun.enterprise.config.clientbeans.ElementProperty; 35 import com.sun.enterprise.config.clientbeans.Security; 36 import com.sun.enterprise.config.clientbeans.Ssl; 37 import com.sun.enterprise.config.clientbeans.TargetServer; 38 import com.sun.enterprise.config.ConfigContext; 39 import com.sun.enterprise.config.ConfigException; 40 import com.sun.enterprise.config.ConfigFactory; 41 import com.sun.enterprise.connectors.ActiveResourceAdapter; 42 import com.sun.enterprise.connectors.ConnectorRegistry; 43 import com.sun.enterprise.connectors.ConnectorRuntime; 44 import com.sun.enterprise.deployment.*; 45 import com.sun.enterprise.deployment.archivist.AppClientArchivist; 46 import com.sun.enterprise.deployment.archivist.ApplicationArchivist; 47 import com.sun.enterprise.deployment.backend.ClientJarMakerThread; 48 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 49 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 50 import com.sun.enterprise.deployment.deploy.shared.InputJarArchive; 51 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapperFactory; 52 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapperFactoryMgr; 53 import com.sun.enterprise.InjectionManager; 54 import com.sun.enterprise.J2EESecurityManager; 55 import com.sun.enterprise.naming.ProviderManager; 56 import com.sun.enterprise.security.GUIErrorDialog; 57 import com.sun.enterprise.security.SSLUtils; 58 import com.sun.enterprise.server.logging.ACCLogManager; 59 import com.sun.enterprise.Switch; 60 import com.sun.enterprise.util.FileUtil; 61 import com.sun.enterprise.util.i18n.StringManager; 62 import com.sun.enterprise.util.JarClassLoader; 63 import com.sun.enterprise.util.ORBManager; 64 import com.sun.enterprise.util.shared.ArchivistUtils; 65 import com.sun.enterprise.util.Utility; 66 import com.sun.logging.LogDomains; 67 import com.sun.web.server.HttpsURLStreamHandlerFactory; 68 69 import java.io.*; 70 import java.net.*; 71 import java.util.Iterator ; 72 import java.util.jar.JarFile ; 73 import java.util.logging.Level ; 74 import java.util.logging.Logger ; 75 import java.util.logging.LogManager ; 76 import java.util.Properties ; 77 import java.util.Vector ; 78 79 85 public class Main 86 { 87 private static final String CLIENT = "-client"; 88 private static final String NAME = "-name"; 89 private static final String MAIN_CLASS = "-mainclass"; 90 private static final String TEXT_AUTH = "-textauth"; 91 private static final String XML_PATH = "-xml"; 92 private static final String ACC_CONFIG_XML = "-configxml"; 93 private static final String DEFAULT_CLIENT_CONTAINER_XML = "sun-acc.xml"; 94 private static final String SUNACC_XML_URL = "sun-acc.xml.url"; 96 private static final String NO_APP_INVOKE = "-noappinvoke"; 97 private static final String USER = "-user"; 99 private static final String PASSWORD = "-password"; 100 private static final String PASSWORD_FILE = "-passwordfile"; 101 private static final String LOGIN_NAME = "j2eelogin.name"; 102 private static final String LOGIN_PASSWORD = "j2eelogin.password"; 103 private static final String DASH = "-"; 104 105 private static final String lineSep = System.getProperty("line.separator"); 106 107 111 public static final String APPCLIENT_IIOP_DEFAULTHOST_PROPERTYNAME = "com.sun.aas.jws.iiop.defaultHost"; 112 public static final String APPCLIENT_IIOP_DEFAULTPORT_PROPERTYNAME = "com.sun.aas.jws.iiop.defaultPort"; 113 public static final String APPCLIENT_IIOP_FAILOVER_ENDPOINTS_PROPERTYNAME = "com.sun.aas.jws.iiop.failover.endpoints"; 114 public static final String APPCLIENT_PROBE_CLASSNAME_PROPERTYNAME = "com.sun.aas.jws.probeClassName"; 115 116 117 public static final String APPCLIENT_RETAIN_TEMP_FILES_PROPERTYNAME = "com.sun.aas.jws.retainTempFiles"; 118 119 120 public static final String APPCLIENT_ISJWS_PROPERTYNAME = "com.sun.aas.jws.isJWS"; 121 122 127 public static final String SUN_ACC_SECURITY_CONFIG_PROPERTY = "security.config.file"; 128 129 130 private static final String LOGIN_CONF_FILE_PREFIX = "login"; 131 private static final String LOGIN_CONF_FILE_SUFFIX = ".conf"; 132 133 134 private static final String LOGIN_CONF_PROPERTY_NAME = "java.security.auth.login.config"; 135 136 137 private static final String DEFAULT_TEMPLATE_PREFIX = "jws/templates/"; 138 private static final String SUN_ACC_DEFAULT_TEMPLATE = DEFAULT_TEMPLATE_PREFIX + "default-sun-accTemplate.xml"; 139 private static final String WSS_CLIENT_CONFIG_TEMPLATE = DEFAULT_TEMPLATE_PREFIX + "default-wss-client-configTemplate.xml"; 140 private static final String LOGIN_CONF_TEMPLATE = DEFAULT_TEMPLATE_PREFIX + "appclientlogin.conf"; 141 142 143 private static final String WSS_CLIENT_CONFIG_PREFIX = "wsscc"; 144 private static final String WSS_CLIENT_CONFIG_SUFFIX = ".xml"; 145 private static final String SUN_ACC_PREFIX = "sunacc"; 146 private static final String SUN_ACC_SUFFIX = ".xml"; 147 148 private static Logger _logger; 149 150 private static final boolean debug = false; 151 private static StringManager localStrings = 152 StringManager.getManager(Main.class); 153 private static boolean guiAuth; 154 private static boolean runClient=true; 155 156 private static String host; 157 158 private static String port; 159 160 161 private static StringBuilder pendingLogInfo = new StringBuilder (); 162 private static StringBuilder pendingLogFine = new StringBuilder (); 163 164 165 private static String [] args; 166 167 168 private static boolean isJWS; 169 170 171 private static boolean retainTempFiles = false; 172 173 private static final String SUPPORT_MODULE_FORMAT = "support.module.format"; 174 private static final String SUPPORT_MODULE_FORMAT_DEFAULT_VALUE = "true"; 175 private static final String supportModuleFormatValue = System.getProperty(SUPPORT_MODULE_FORMAT, SUPPORT_MODULE_FORMAT_DEFAULT_VALUE); 176 private static final boolean supportModuleFormat = Boolean.parseBoolean(supportModuleFormatValue); 177 178 public static void main(String [] args) { 179 if (supportModuleFormat) { 180 new MainWithModuleSupport(args); 181 } else { 182 new Main(args); 183 } 184 } 185 186 public Main(String [] args) { 187 188 String arg = null; 189 String clientJar = null; 190 String displayName = null; 191 String mainClass = null; 192 String xmlPath = null; 193 String accConfigXml = null; 194 String jwsACCConfigXml = null; 195 Vector <String > appArgs = new Vector <String >(); 196 int i = 0; 197 198 isJWS = Boolean.getBoolean(APPCLIENT_ISJWS_PROPERTYNAME); 199 retainTempFiles = Boolean.getBoolean(APPCLIENT_RETAIN_TEMP_FILES_PROPERTYNAME); 200 201 guiAuth = Boolean.valueOf 202 (System.getProperty("auth.gui", "true")).booleanValue(); 203 if(args.length < 1) { 205 usage(); 206 } else { 207 while(i < args.length) { 208 arg = args[i++]; 209 if(arg.equals(CLIENT)) { 210 if(i < args.length && !args[i].startsWith(DASH)) { 211 clientJar = args[i++]; 212 } else { 213 usage(); 214 } 215 } else if(arg.equals(NAME) && !args[i].startsWith(DASH)) { 216 if(i < args.length && mainClass == null) { 218 displayName = args[i++]; 219 } else { 220 usage(); 221 } 222 } else if(arg.equals(MAIN_CLASS) && !args[i].startsWith(DASH)) { 223 if(i < args.length && displayName == null) { 225 mainClass = args[i++]; 226 } else { 227 usage(); 228 } 229 } else if(arg.equals(XML_PATH) ) { 230 if(i < args.length && xmlPath == null) { 231 xmlPath = args[i++]; 232 } else { 233 usage(); 234 } 235 } else if(arg.equals(ACC_CONFIG_XML) ) { 236 if(i < args.length && accConfigXml == null) { 237 accConfigXml = args[i++]; 238 } else { 239 usage(); 240 } 241 } else if(arg.equals(TEXT_AUTH)) { 242 guiAuth = false; 244 } else if(arg.equals(NO_APP_INVOKE)) { 245 runClient = false; 246 } else if(arg.equals(USER)) { 247 if(i < args.length) { 248 System.setProperty(LOGIN_NAME, args[i++]); 249 } else { 250 usage(); 251 } 252 } else if(arg.equals(PASSWORD)) { 253 if (i < args.length) { 254 System.setProperty(LOGIN_PASSWORD, args[i++]); 255 } else { 256 usage(); 257 } 258 } else if (arg.equals(PASSWORD_FILE)) { 259 if (i < args.length) { 260 try { 261 System.setProperty(LOGIN_PASSWORD, 262 loadPasswordFromFile(args[i++])); 263 } catch(IOException ex) { 264 throw new IllegalArgumentException (ex.getMessage()); 265 } 266 } else { 267 usage(); 268 } 269 } else { 270 appArgs.add(arg); 271 } 272 } 273 } 274 275 String className=null; 276 277 if(clientJar == null && ! isJWS) { 278 if (appArgs.size()==0 && mainClass==null) { 281 usage(); 282 } 283 String value; 286 if (mainClass==null) { 287 value = appArgs.elementAt(0); 288 } else { 289 value = mainClass; 290 } 291 if (value.endsWith(".class")) { 292 className = value.substring(0, value.length()-".class".length()); 293 } else { 294 className = value; 295 } 296 297 String path = className.replace('.', File.separatorChar) + ".class"; 298 File file = new File (path); 299 if (!file.isAbsolute()) { 300 file = new File (System.getProperty("user.dir"), path); 301 } 302 308 if (!file.exists() && ! isJWS) { 309 usage(); 311 } 312 } 313 314 315 if (xmlPath != null) { 316 validateXMLFile(xmlPath); 317 } else if (accConfigXml != null ) { 318 validateXMLFile(accConfigXml); 319 xmlPath = accConfigXml; } else if (isJWS) { 321 326 try { 327 jwsACCConfigXml = prepareJWSConfig(); 328 if (jwsACCConfigXml != null) { 329 validateXMLFile(jwsACCConfigXml); 330 xmlPath = jwsACCConfigXml; 331 } 332 } catch (Throwable thr) { 333 System.err.println("Error preparing configuration"); 334 thr.printStackTrace(System.err); 335 System.exit(1); 336 } 337 } 338 339 340 _logger = LogDomains.getLogger(LogDomains.ACC_LOGGER); 342 343 LogManager logMgr = LogManager.getLogManager(); 344 if (logMgr instanceof ACCLogManager) { 345 ((ACCLogManager) logMgr).init(xmlPath); 346 } 347 348 351 if (pendingLogInfo.length() > 0) { 352 _logger.info(pendingLogInfo.toString()); 353 354 if (pendingLogFine.length() > 0) { 355 _logger.fine(pendingLogFine.toString()); 356 } 357 } 358 359 363 if (isJWS) { 364 try { 365 prepareJWSLoginConfig(); 366 } catch (Throwable thr) { 367 _logger.log(Level.SEVERE, "Error preparing default login configuration", thr); 368 System.exit(1); 369 } 370 } 371 372 373 Utility.checkJVMVersion(); 374 375 376 SecurityManager secMgr = System.getSecurityManager(); 377 if (secMgr != null && 378 !(J2EESecurityManager.class.equals(secMgr.getClass()))) { 379 J2EESecurityManager mgr = new J2EESecurityManager(); 380 System.setSecurityManager(mgr); 381 } 382 if (_logger.isLoggable(Level.INFO)) { 383 if (secMgr != null) { 384 _logger.info("acc.secmgron"); 385 } else { 386 _logger.info("acc.secmgroff"); 387 } 388 } 389 390 com.sun.enterprise.security.KeyTool.initProvider(); 391 try{ 392 396 SSLUtils.initStoresAtStartup(); 397 } catch (Exception e){ 398 402 if(_logger.isLoggable(Level.FINER)){ 403 _logger.log(Level.FINER, "main.ssl_keystore_init_failed", e); 405 } else{ 406 _logger.log(Level.WARNING, "main.ssl_keystore_init_failed"); 408 } 409 } 410 411 try { 412 Switch.getSwitch().setProviderManager(ProviderManager.getProviderManager()); 413 setTargetServerProperties(xmlPath); 415 416 int exitCode = 0; AppContainer container = null; 418 419 Cleanup cleanup = new Cleanup(); 422 Runtime runtime = Runtime.getRuntime(); 423 runtime.addShutdownHook(cleanup); 424 425 java.security.AccessController.doPrivileged(new 427 java.security.PrivilegedAction () { 428 public Object run() { 429 URL.setURLStreamHandlerFactory(new 430 HttpsURLStreamHandlerFactory()); 431 return null; 432 } 433 }); 434 435 File appClientFile; 436 444 if (isJWS) { 445 448 appClientFile = findAppClientFileForJWSLaunch(); 449 } else if (clientJar==null) { 450 453 File userDir = new File (System.getProperty("user.dir")); 454 File appClientClass = new File (userDir, className); 455 appClientFile = appClientClass.getParentFile(); 456 } else { 457 460 appClientFile = new File (clientJar); 461 } 462 463 URL[] urls = new URL[1]; 465 urls[0] = appClientFile.toURI().toURL(); 466 471 ClassLoader currentCL = Thread.currentThread().getContextClassLoader(); 472 ClassLoader jcl = new URLClassLoader(urls, currentCL); 473 Thread.currentThread().setContextClassLoader(jcl); 474 ApplicationClientDescriptor appDesc = null; 475 476 478 484 if((clientJar!=null || isJWS ) && FileUtil.isEARFile(appClientFile)) { 485 486 487 Application app = null; 489 try { 490 ApplicationArchivist arch = new ApplicationArchivist(); 491 arch.setAnnotationProcessingRequested(true); 492 493 arch.setClassLoader(jcl); 496 app = (Application) arch.open(appClientFile); 497 498 } catch (Throwable t) { 499 _logger.log(Level.WARNING, "acc.failed_load_client_desc", 500 clientJar); 501 throw t; 502 } 503 app.setClassLoader(jcl); 504 appDesc = null; 505 506 int appclientCount = 0; 507 for (Iterator itr = 508 app.getApplicationClientDescriptors().iterator(); 509 itr.hasNext();) { 510 ApplicationClientDescriptor next = 511 (ApplicationClientDescriptor) itr.next(); 512 appclientCount++; 513 } 514 515 for (Iterator itr = 516 app.getApplicationClientDescriptors().iterator(); 517 itr.hasNext();) { 518 519 ApplicationClientDescriptor next = 520 (ApplicationClientDescriptor) itr.next(); 521 if (appclientCount == 1) { 522 if (mainClass != null) { 524 if (!next.getMainClassName().equals(mainClass)) { 525 next.setMainClassName(mainClass); 526 } 527 } 528 appDesc = next; 529 break; 530 } else { if (mainClass != null) { 532 if (next.getMainClassName().equals(mainClass)) { 533 appDesc = next; 534 break; 535 } 536 } else { 537 if (displayName == null) { 538 _logger.log(Level.SEVERE,"acc.no_mainclass_or_displayname"); 539 System.exit(1); 540 } else if (displayName != null && next.getName().equals(displayName)) { 541 if(appDesc == null) { 542 appDesc = next; 543 } else { 544 _logger.log(Level.WARNING, "acc.duplicate_display_name"); 546 System.exit(1); 547 } 548 } 549 } 550 } 551 552 } 553 if (appDesc != null) { 555 container = new AppContainer(appDesc, guiAuth); 556 } 559 } else { 560 561 563 565 try { 566 AppClientArchivist arch = new AppClientArchivist(); 569 arch.setAnnotationProcessingRequested(true); 570 arch.setClassLoader(jcl); 571 572 if (className!=null) { 574 appDesc = (ApplicationClientDescriptor) arch.getDefaultBundleDescriptor(); 575 } else { 576 appDesc = (ApplicationClientDescriptor) arch.open(appClientFile.getAbsolutePath()); 581 } 582 583 if (className!=null) { 584 AbstractArchive archive; 586 if (appClientFile.isDirectory()) { 587 archive = new FileArchive(); 588 ((FileArchive) archive).open(appClientFile.getAbsolutePath()); 589 } else { 590 archive = new InputJarArchive(); 591 ((InputJarArchive) archive).open(appClientFile.getAbsolutePath()); 592 } 593 594 if (appDesc.getMainClassName()==null || appDesc.getMainClassName().length()==0) { 595 appDesc.setMainClassName(className); 596 arch.processAnnotations(appDesc, archive); 597 598 if (mainClass==null && ! isJWS) { 601 appArgs.removeElementAt(0); 602 } 603 } 604 } 605 606 } catch (Throwable t) { 607 _logger.log(Level.WARNING, 608 "main.appclient_descriptors_failed", (displayName == null) ? mainClass : displayName); 609 throw t; 610 } 611 container = new AppContainer(appDesc, guiAuth); 612 } 613 if(container == null) { 614 _logger.log(Level.WARNING, "acc.no_client_desc", 615 (displayName == null) ? mainClass : displayName); 616 617 System.exit(1); 618 } 619 Authenticator.setDefault(new HttpAuthenticator(container)); 623 624 _logger.log(Level.INFO, "acc.orb_host_name", host); 626 _logger.log(Level.INFO, "acc.orb_port_number", port); 627 628 Properties props = new Properties (); 629 props.put("org.omg.CORBA.ORBInitialHost", host); 630 props.put("org.omg.CORBA.ORBInitialPort", port); 631 632 String appMainClass = container.preInvoke(props); 633 cleanup.setAppContainer(container); 634 635 Class cl = null; 637 try { 638 cl = jcl.loadClass(appMainClass); 639 } catch (java.lang.ClassNotFoundException cnf) { 640 String errorMessage = localStrings.getString 641 ("appclient.mainclass.not.found", appMainClass); 642 _logger.log(Level.WARNING, errorMessage); 643 throw cnf; 644 } 645 646 _logger.log(Level.INFO, "acc.load_app_class", appMainClass); 647 648 String [] applicationArgs = new String [appArgs.size()]; 649 for(int sz = 0; sz < applicationArgs.length; sz++) { 650 applicationArgs[sz] = (String ) appArgs.elementAt(sz); 651 } 652 653 if (appDesc.hasWebServiceClients()) { 658 File moduleFile; 659 if (appDesc.getApplication()==null 660 || appDesc.getApplication().isVirtual()) { 661 moduleFile = appClientFile; 664 } else { 665 InputJarArchive earFile = new InputJarArchive(); 666 earFile.open(appClientFile.getAbsolutePath()); 667 String moduleName = appDesc.getModuleDescriptor().getArchiveUri(); 668 InputStream is = earFile.getEntry(moduleName); 669 moduleFile = File.createTempFile("appclient", ".jar"); 670 moduleFile.deleteOnExit(); 671 OutputStream os = new FileOutputStream(moduleFile); 672 ArchivistUtils.copy(new BufferedInputStream(is), new BufferedOutputStream(os)); 673 earFile.close(); 674 } 675 for (Iterator itr = appDesc.getServiceReferenceDescriptors().iterator(); 677 itr.hasNext();) { 678 679 ServiceReferenceDescriptor serviceRef = (ServiceReferenceDescriptor) itr.next(); 680 if (serviceRef.getWsdlFileUri()!=null) { 681 File wsdlFile = new File (serviceRef.getWsdlFileUri()); 685 if(wsdlFile.isAbsolute()) { 686 serviceRef.setWsdlFileUrl(wsdlFile.toURI().toURL()); 687 } else { 688 serviceRef.setWsdlFileUrl(FileUtil.getEntryAsUrl(moduleFile, serviceRef.getWsdlFileUri())); 691 } 692 } 693 } 694 } 695 696 697 System.setProperty("javax.xml.ws.spi.Provider", "com.sun.enterprise.webservice.spi.ProviderImpl"); 699 InjectionManager injMgr = Switch.getSwitch().getInjectionManager(); 703 injMgr.injectClass(cl, appDesc); 704 705 if(runClient) { 706 Utility.invokeApplicationMain(cl, applicationArgs); 707 _logger.info("Application main() finished normally"); 708 } 709 710 711 injMgr.invokeClassPreDestroy(cl, appDesc); 713 714 shutDownSystemAdapters(); 717 718 } catch (java.lang.reflect.InvocationTargetException ite) { 722 Throwable tt = ite.getTargetException(); 723 _logger.log(Level.WARNING, "acc.app_exception", tt); 724 shutDownSystemAdapters(); 725 System.exit(1); 726 } catch (Throwable t) { 727 if (t instanceof javax.security.auth.login.FailedLoginException ){ 728 729 _logger.info("acc.login_error"); 730 boolean isGui = 731 Boolean.valueOf 732 (System.getProperty ("auth.gui","true")).booleanValue(); 733 String errorMessage = 734 localStrings.getString 735 ("main.exception.loginError", 736 "Incorrect login and/or password"); 737 738 if (isGui) { 739 GUIErrorDialog ged = new GUIErrorDialog (errorMessage); 740 ged.show (); 741 } 742 } 743 744 _logger.log(Level.WARNING, "acc.app_exception", t); 745 746 if (t instanceof javax.naming.NamingException ) { 747 _logger.log(Level.WARNING, "acc.naming_exception_received"); 748 } 749 750 shutDownSystemAdapters(); 751 752 System.exit(1); 753 } 754 } 755 756 private static void setTargetServerProperties(String clientXmlLocation) 757 throws ConfigException { 758 try { 760 if(clientXmlLocation == null || clientXmlLocation.equals("")) { 761 clientXmlLocation = DEFAULT_CLIENT_CONTAINER_XML; 762 } 763 764 System.setProperty(SUNACC_XML_URL, clientXmlLocation); 766 _logger.log(Level.INFO, "acc.using_xml_location", clientXmlLocation); 767 768 ConfigContext ctx = ConfigFactory.createConfigContext( 769 clientXmlLocation, true, 770 false, false, 771 ClientContainer.class, 772 new ACCEntityResolver()); 773 774 ClientContainer cc = ClientBeansFactory.getClientBean(ctx); 775 776 host = cc.getTargetServer(0).getAddress(); 777 port = cc.getTargetServer(0).getPort(); 778 779 TargetServer[] tServer = cc.getTargetServer(); 781 String targetServerEndpoints = null; 782 if (tServer.length > 1) { 783 for (int i = 0; i < tServer.length; i++) { 784 if (targetServerEndpoints == null) { 785 targetServerEndpoints = tServer[i].getAddress() + 786 ":" + tServer[i].getPort(); 787 } else { 788 targetServerEndpoints = targetServerEndpoints + "," + 789 tServer[i].getAddress() + 790 ":" + tServer[i].getPort(); 791 } 792 } 793 } 794 795 setSSLData(cc); 796 797 ClientCredential cCrd = cc.getClientCredential(); 799 if(cCrd != null) { 800 if (System.getProperty(LOGIN_NAME) == null) { 803 _logger.config("using login name from client container xml..."); 804 System.setProperty(LOGIN_NAME, cCrd.getUserName()); 805 } 806 if (System.getProperty(LOGIN_PASSWORD) == null) { 807 _logger.config("using password from client container xml..."); 808 System.setProperty(LOGIN_PASSWORD, cCrd.getPassword()); 809 } 810 } 811 String endpoints_property = null; 812 ElementProperty[] props = cc.getElementProperty(); 814 for ( int i=0; i<props.length; i++ ) { 815 if ( props[i].getName().equals("ssl") ) { 816 if ( props[i].getValue().equals("required") ) { 817 (ORBManager.getCSIv2Props()).put(ORBManager.ORB_SSL_CLIENT_REQUIRED, 818 "true"); 819 } 820 } 821 if ( props[i].getName().equals(S1ASCtxFactory.LOAD_BALANCING_PROPERTY) ) { 822 System.setProperty(props[i].getName(),props[i].getValue()); 823 } 824 if ( props[i].getName().equals(S1ASCtxFactory.IIOP_ENDPOINTS_PROPERTY) ) { 825 endpoints_property = props[i].getValue().trim(); 826 827 } 828 } 829 830 834 String jwsEndpointsProperty = null; 835 if (endpoints_property == null) { 836 jwsEndpointsProperty = System.getProperty(Main.APPCLIENT_IIOP_FAILOVER_ENDPOINTS_PROPERTYNAME); 837 endpoints_property = jwsEndpointsProperty; 838 } 839 840 _logger.fine("targetServerEndpoints = " + targetServerEndpoints + 841 "endpoints_property = " + 842 endpoints_property); 843 if (targetServerEndpoints == null && endpoints_property != null) { 844 System.setProperty( 845 S1ASCtxFactory.IIOP_ENDPOINTS_PROPERTY, 846 endpoints_property); 847 848 853 if (jwsEndpointsProperty == null) { 854 _logger.warning("acc.targetserver.endpoints.warning"); 855 } 856 } else if (targetServerEndpoints != null && endpoints_property == null) { 857 System.setProperty( 858 S1ASCtxFactory.IIOP_ENDPOINTS_PROPERTY, 859 targetServerEndpoints.trim()); 860 } else if (targetServerEndpoints != null && endpoints_property != null) { 861 System.setProperty( 862 S1ASCtxFactory.IIOP_ENDPOINTS_PROPERTY, 863 targetServerEndpoints.trim() + "," + 864 endpoints_property); 865 870 if (jwsEndpointsProperty == null) { 871 _logger.warning("acc.targetserver.endpoints.warning"); 872 } 873 _logger.fine("System.getProperty(S1ASCtxFactory.IIOP_ENDPOINTS_PROPERTY) ==> " + System.getProperty(S1ASCtxFactory.IIOP_ENDPOINTS_PROPERTY)); 874 } 875 } catch (ConfigException t) { 876 _logger.log(Level.WARNING,"acc.acc_xml_file_error" , 877 new Object [] {clientXmlLocation, t.getMessage()}); 878 _logger.log(Level.FINE, "exception : " + t.toString(), t); 879 throw t; 880 } 881 } 882 883 private static void setSSLData(ClientContainer cc) { 884 try { 885 TargetServer tServer = cc.getTargetServer(0); 887 Security security = tServer.getSecurity(); 892 if (security == null) { 893 _logger.fine("No Security input set in ClientContainer.xml"); 894 return; 896 } 897 Ssl ssl = security.getSsl(); 898 if (ssl == null) { 899 _logger.fine("No SSL input set in ClientContainer.xml"); 900 return; 902 903 } 904 SSLUtils.setAppclientSsl(ssl); 907 } catch (Exception ex) { 908 909 } 910 } 911 912 913 private static void validateXMLFile(String xmlFullName) 914 { 915 if(xmlFullName == null || 917 xmlFullName.startsWith("-")){ usage(); 919 } 920 try { 921 File f = new File (xmlFullName); 922 if((f != null) && f.exists() && f.isFile() && f.canRead()){ 923 return; 924 }else{ xmlMessage(xmlFullName); 926 usage(); 927 } 928 } catch (Exception ex) { 929 xmlMessage(xmlFullName); 930 usage(); 931 } 932 } 934 935 private void shutDownSystemAdapters() { 938 try { 939 com.sun.enterprise.PoolManager poolmgr = 940 Switch.getSwitch().getPoolManager(); 941 if ( poolmgr != null ) { 942 Switch.getSwitch().getPoolManager().killFreeConnectionsInPools(); 943 } 944 } catch( Exception e ) { 945 } 947 948 try { 949 ConnectorRegistry registry = ConnectorRegistry.getInstance(); 950 ActiveResourceAdapter activeRar = registry.getActiveResourceAdapter 951 (ConnectorRuntime.DEFAULT_JMS_ADAPTER); 952 if (activeRar != null) { 953 activeRar.destroy(); 954 } 955 } catch (Exception e) { 956 _logger.fine("Exception caught while shutting down system adapter:"+e.getMessage()); 958 } 959 } 960 961 private static void usage() { 962 System.out.println(localStrings.getString("main.usage", 963 "appclient [ -client <appjar> ] [-mainclass <appClass-name>|-name <display-name>] [-xml <xml>] [-textauth] [-user <username>] [-password <password>|-passwordfile <password-file>] [app-args]")); 964 System.exit(1); 965 } 966 967 private static void xmlMessage(String xmlFullName) 968 { 969 System.out.println(localStrings.getString("main.cannot_read_clientContainer_xml", xmlFullName, 970 "Client Container xml: " + xmlFullName + " not found or unable to read.\nYou may want to use the -xml option to locate your configuration xml.")); 971 972 } 973 974 private String loadPasswordFromFile(String fileName) 975 throws IOException { 976 InputStream inputStream = null; 977 try { 978 inputStream = new BufferedInputStream(new FileInputStream(fileName)); 979 Properties props = new Properties (); 980 props.load(inputStream); 981 return props.getProperty("PASSWORD"); 982 } finally { 983 if (inputStream != null) { 984 inputStream.close(); 985 } 986 } 987 } 988 989 private static class Cleanup extends Thread { 990 private AppContainer appContainer = null; 991 private boolean cleanedUp = false; 992 993 public Cleanup() { 994 } 995 996 public void setAppContainer(AppContainer container) { 997 appContainer = container; 998 } 999 1000 public void run() { 1001 cleanUp(); 1002 } 1003 1004 public void cleanUp() { 1005 if( !cleanedUp ) { 1006 try { 1007 if( appContainer != null ) { 1008 appContainer.postInvoke(); 1009 } 1010 } 1011 catch(Throwable t) { 1012 } 1013 finally { 1014 cleanedUp = true; 1015 } 1016 } } 1018 } 1019 1024 private String prepareJWSConfig() throws IOException, FileNotFoundException { 1025 return prepareJWSDefaultConfig(); 1026 } 1027 1028 1033 private String prepareJWSDefaultConfig() throws IOException, FileNotFoundException { 1034 String result = null; 1035 1036 1039 String sunACCTemplate = Util.loadResource(this.getClass(), SUN_ACC_DEFAULT_TEMPLATE); 1040 String wssClientConfigTemplate = Util.loadResource(this.getClass(), WSS_CLIENT_CONFIG_TEMPLATE); 1041 1042 1047 Properties tokenValues = new Properties (System.getProperties()); 1048 1049 1052 String wssClientConfig = Util.replaceTokens(wssClientConfigTemplate, tokenValues); 1053 File wssClientConfigFile = Util.writeTextToTempFile(wssClientConfig, WSS_CLIENT_CONFIG_PREFIX, WSS_CLIENT_CONFIG_SUFFIX, retainTempFiles); 1054 pendingLogFine.append("Temporary wss-client-config.xml file: " + wssClientConfigFile.getAbsolutePath() + lineSep); 1055 1056 1065 String quotedConfigFileSpec = wssClientConfigFile.getAbsolutePath().replaceAll("\\\\", "\\\\\\\\"); 1066 tokenValues.setProperty(SUN_ACC_SECURITY_CONFIG_PROPERTY, quotedConfigFileSpec); 1067 1068 String sunaccContent = Util.replaceTokens(sunACCTemplate, tokenValues); 1069 File sunaccFile = Util.writeTextToTempFile(sunaccContent, SUN_ACC_PREFIX, SUN_ACC_SUFFIX, retainTempFiles); 1070 pendingLogFine.append("Temporary sun-acc.xml file: " + sunaccFile.getAbsolutePath()); 1071 1072 return sunaccFile.getAbsolutePath(); 1073 } 1074 1075 1079 private void prepareJWSLoginConfig() throws IOException, FileNotFoundException { 1080 prepareJWSDefaultLoginConfig(); 1081 } 1082 1083 1087 private void prepareJWSDefaultLoginConfig() throws IOException, FileNotFoundException { 1088 String configContent = Util.loadResource(this.getClass(), LOGIN_CONF_TEMPLATE); 1089 File configFile = Util.writeTextToTempFile(configContent, LOGIN_CONF_FILE_PREFIX, LOGIN_CONF_FILE_SUFFIX, retainTempFiles); 1090 String configFilePath = configFile.getAbsolutePath(); 1091 pendingLogFine.append("Temporary appclientlogin.conf file: " + configFilePath); 1092 System.setProperty(LOGIN_CONF_PROPERTY_NAME, configFilePath); 1093 } 1094 1095 1099 private File findAppClientFileForJWSLaunch() throws ClassNotFoundException , URISyntaxException { 1100 1105 String probeClassName = System.getProperty(APPCLIENT_PROBE_CLASSNAME_PROPERTYNAME); 1106 _logger.fine("Probing class " + probeClassName); 1107 Class probeClass = Class.forName(probeClassName); 1108 URL workingURL = probeClass.getProtectionDomain().getCodeSource().getLocation(); 1109 _logger.fine("Location of appclient jar file: " + workingURL.toString()); 1110 1111 1118 URI workingURI = workingURL.toURI(); 1119 String ssp = workingURI.getSchemeSpecificPart(); 1120 return new File (ssp); 1121 } 1122} 1123 | Popular Tags |