1 23 24 package com.sun.enterprise.appclient.jws; 25 26 import com.sun.enterprise.appclient.AppClientInfo; 27 import com.sun.enterprise.appclient.Main; 28 import com.sun.enterprise.appclient.MainWithModuleSupport; 29 import com.sun.enterprise.config.ConfigException; 30 import com.sun.enterprise.deployment.Application; 31 import com.sun.enterprise.deployment.ApplicationClientDescriptor; 32 import com.sun.enterprise.deployment.Descriptor; 33 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 34 import com.sun.enterprise.deployment.deploy.shared.ArchiveFactory; 35 import com.sun.enterprise.deployment.interfaces.DeploymentImplConstants; 36 import com.sun.enterprise.deployment.runtime.JavaWebStartAccessDescriptor; 37 import com.sun.enterprise.deployment.util.ModuleDescriptor; 38 import com.sun.enterprise.instance.AppclientModulesManager; 39 import com.sun.enterprise.instance.AppsManager; 40 import com.sun.enterprise.instance.BaseManager; 41 import com.sun.enterprise.instance.InstanceEnvironment; 42 import com.sun.enterprise.loader.EJBClassPathUtils; 43 import com.sun.enterprise.server.ApplicationServer; 44 import com.sun.enterprise.server.ServerContext; 45 import com.sun.enterprise.util.ExecException; 46 import com.sun.enterprise.util.ORBManager; 47 import com.sun.enterprise.util.ProcessExecutor; 48 import com.sun.enterprise.util.SystemPropertyConstants; 49 import com.sun.enterprise.util.io.FileUtils; 50 import com.sun.enterprise.util.i18n.StringManager; 51 import com.sun.enterprise.util.net.NetUtils; 52 import com.sun.enterprise.web.WebContainer; 53 import com.sun.logging.LogDomains; 54 import java.io.BufferedReader ; 55 import java.io.File ; 56 import java.io.FileInputStream ; 57 import java.io.FileNotFoundException ; 58 import java.io.IOException ; 59 import java.io.InputStream ; 60 import java.io.InputStreamReader ; 61 import java.net.URI ; 62 import java.net.URISyntaxException ; 63 import java.util.Collections ; 64 import java.util.Date ; 65 import java.util.Enumeration ; 66 import java.util.HashMap ; 67 import java.util.List ; 68 import java.util.Map ; 69 import java.util.Properties ; 70 import java.util.Set ; 71 import java.util.Vector ; 72 import java.util.jar.Attributes ; 73 import java.util.jar.JarEntry ; 74 import java.util.jar.JarFile ; 75 import java.util.jar.Manifest ; 76 import java.util.logging.Level ; 77 import java.util.logging.Logger ; 78 import java.util.regex.Matcher ; 79 import java.util.regex.Pattern ; 80 import javax.enterprise.deploy.shared.ModuleType ; 81 import javax.servlet.http.HttpServletRequest ; 82 import org.xml.sax.SAXParseException ; 83 84 import org.omg.CORBA.ORB ; 85 import com.sun.corba.ee.spi.folb.ClusterInstanceInfo; 86 import com.sun.corba.ee.spi.folb.GroupInfoService; 87 import com.sun.corba.ee.spi.folb.SocketInfo; 88 import com.sun.corba.ee.impl.orbutil.ORBConstants; 89 import org.omg.CORBA.ORBPackage.InvalidName ; 90 91 112 public class AppclientJWSSupportInfo { 113 114 115 private static final String JNLP_MIME_TYPE = "application/x-java-jnlp-file"; 116 private static final String HTML_MIME_TYPE = "text/html"; 117 private static final String XML_MIME_TYPE = "application/xml"; 118 119 120 private static AppclientJWSSupportInfo instance = null; 121 122 136 private static final String REQUEST_PATH_INFO_PATTERN = "/(" + 137 NamingConventions.APPCLIENT_CATEGORY + "|" + 138 NamingConventions.APPLICATION_CATEGORY + "|" + 139 NamingConventions.APPSERVER_CATEGORY + "|" + 140 ")/(.*?)(?:/(.*(?:$|\\z)))?"; 141 142 146 private static final int PATTERN_CATEGORY_GROUP_NUMBER = 1; 147 private static final int PATTERN_REGNAME_GROUP_NUMBER = 2; 148 private static final int PATTERN_RELATIVEPATH_GROUP_NUMBER = 3; 149 150 151 private static final Pattern requestPathInfoPattern = Pattern.compile(REQUEST_PATH_INFO_PATTERN); 152 153 157 private static final String SERVER_RETAIN_TEMP_FILES_PROPERTYNAME = MainWithModuleSupport.APPCLIENT_RETAIN_TEMP_FILES_PROPERTYNAME; 158 159 165 private static final String IIOP_ENDPOINT_TYPE_PREFIX_IGNORE = "SSL"; 166 167 168 private static final String APPCLIENT_JAR_SECURITY_ELEMENT_PROPERTYNAME = "appclient.jar.security.setting"; 169 170 171 private StringManager localStrings = StringManager.getManager(getClass()); 172 173 186 187 private Map <String ,ContentOrigin> appclients; 188 private Map <String ,ContentOrigin> applications; 189 private Map <String ,ContentOrigin> appserverOrigins; 190 private Map <String ,ContentOrigin> signedAppserverOrigins; 191 private Map <String ,ContentOrigin> extJarAppserverOrigins; 192 193 198 private Map <String ,Content> contentMap; 199 200 201 202 private Map <String ,Map <String ,ContentOrigin>> originTypes; 203 204 208 209 protected ServerContext appServerContext; 210 211 212 protected InstanceEnvironment instEnv; 213 214 215 protected AppsManager appsManager; 216 217 218 protected AppclientModulesManager appclientModulesManager; 219 220 private static final String lineSep = System.getProperty("line.separator"); 221 222 private Logger _logger=LogDomains.getLogger(NamingConventions.JWS_LOGGER); 223 224 225 private TemplateCache templateCache; 226 227 228 private URI installRootURI; 229 230 231 private File installRootDir; 232 233 234 private File libRoot; 235 236 237 private File tempJarDirectory; 238 239 240 private File j2eeModulesDir; 241 242 243 private File j2eeApplicationsDir; 244 245 246 private ExtensionFileManager extensionFileManager; 247 248 private String UNSIGNED_JWSACC_JARFILE_NAME = "appserv-jwsacc.jar"; 249 250 private String SIGNED_JWSACC_JARFILE_NAME = "appserv-jwsacc-signed.jar"; 251 252 256 public static AppclientJWSSupportInfo getInstance() throws IOException , Exception { 257 if (instance == null) { 258 instance = new AppclientJWSSupportInfo(); 259 260 265 AppclientJWSSupportManager.getInstance(); 266 } 267 return instance; 268 } 269 270 275 private AppclientJWSSupportInfo() throws IOException , Exception { 276 277 extensionFileManager = new ExtensionFileManager(); 278 279 283 appclients = Collections.synchronizedMap(new HashMap <String ,ContentOrigin>()); 284 applications = Collections.synchronizedMap(new HashMap <String ,ContentOrigin>()); 285 appserverOrigins = Collections.synchronizedMap(new HashMap <String ,ContentOrigin>()); 286 signedAppserverOrigins = Collections.synchronizedMap(new HashMap <String ,ContentOrigin>()); 287 extJarAppserverOrigins = Collections.synchronizedMap(new HashMap <String ,ContentOrigin>()); 288 289 contentMap = Collections.synchronizedMap(new HashMap <String ,Content>()); 290 291 294 originTypes = new HashMap <String ,Map <String ,ContentOrigin>>(); 295 originTypes.put(NamingConventions.APPCLIENT_CATEGORY, appclients); 296 originTypes.put(NamingConventions.APPLICATION_CATEGORY, applications); 297 originTypes.put(NamingConventions.APPSERVER_CATEGORY, appserverOrigins); 298 originTypes.put(NamingConventions.APPSERVER_CATEGORY, signedAppserverOrigins); 299 originTypes.put(NamingConventions.APPSERVER_EXTJAR_FILES, extJarAppserverOrigins); 300 301 304 findAppServerObjects(); 305 306 316 String installRootDirSpec = System.getProperty("com.sun.aas.installRoot"); 317 installRootDir = new File (installRootDirSpec).getCanonicalFile(); 318 installRootURI = installRootDir.toURI(); 319 320 323 templateCache = new TemplateCache(); 324 325 330 String instanceRootDirSpec = instEnv.getInstancesRoot(); 331 File instanceRootDir = new File (instanceRootDirSpec); 332 libRoot = new File (installRootDir, "lib"); 333 334 338 preloadAppserverContent(); 339 } 340 341 347 public void startJWSServicesForAppclient(Application application, ModuleDescriptor moduleDescr) 348 throws IOException , URISyntaxException , ConfigException, SAXParseException , ConfigException, Exception { 349 String regName = application.getRegistrationName(); 350 351 if ( ! appclientModulesManager.isRegistered(regName)) { 352 findAppServerObjects(); 353 if ( ! appclientModulesManager.isRegistered(regName)) { 354 throw new ConfigException("Cannot locate config information for app client " + regName); 355 } 356 } 357 358 361 String appclientMapKey = NamingConventions.TopLevelAppclient.actualContextRoot(application); 362 AppclientContentOrigin origin = findAppclient(appclientMapKey); 363 364 if (origin != null) { 365 _logger.warning("Attempted to start Java Web Start services for stand-alone app client " + regName + " when they were already started; ignoring the duplicate request"); 366 return; 367 } 368 369 _logger.fine("Starting Java Web Start services for stand-alone app client " + application.getRegistrationName()); 370 371 375 origin = prepareTopLevelAppclient(application, moduleDescr); 376 if (origin != null) { 377 startJWSServices(origin); 378 379 appclients.put(appclientMapKey, origin); 380 381 String logOutput = (_logger.isLoggable(Level.FINE) ? origin.toLongString() : origin.toString()); 382 _logger.info("Java Web Start services started for stand-alone app client " + logOutput); 383 } 384 } 385 386 393 public void endJWSServicesForAppclient(Application application, ModuleDescriptor moduleDescr) { 394 _logger.fine("Ending Java Web Start services for stand-alone app client " + application.getRegistrationName()); 395 396 String appclientMapKey = NamingConventions.TopLevelAppclient.actualContextRoot(application); 397 AppclientContentOrigin origin = findAppclient(appclientMapKey); 398 if (origin != null) { 399 endJWSServices(origin); 400 appclients.remove(appclientMapKey); 401 402 _logger.info("Java Web Start services ended for stand-alone app client " + origin); 403 } 404 } 405 406 413 public void startJWSServicesForApplication(Application application, ModuleDescriptor [] moduleDescriptors) 414 throws IOException , URISyntaxException , SAXParseException , ConfigException, Exception { 415 String applicationMapKey = NamingConventions.TopLevelApplication.contextRoot(application); 416 String regName = application.getRegistrationName(); 417 if ( ! appsManager.isRegistered(regName)) { 418 findAppServerObjects(); 419 if ( ! appsManager.isRegistered(regName)) { 420 throw new ConfigException("Cannot locate config information for application " + regName); 421 } 422 } 423 _logger.fine("Starting Java Web Start services for application " + regName); 424 425 428 ApplicationContentOrigin origin = findApplication(applicationMapKey); 429 if (origin != null) { 430 _logger.warning("Attempt to start Java Web Start services for application " + regName + " when they were already started; ignoring the duplicate request"); 431 return; 432 } 433 434 438 origin = prepareApplication(application, moduleDescriptors); 439 440 startJWSServices(origin); 441 442 445 applications.put(applicationMapKey, origin); 446 447 String logOutput = (_logger.isLoggable(Level.FINE) ? origin.toLongString() : origin.toString()); 448 _logger.info("Java Web Start services started for application " + logOutput); 449 } 450 451 457 public void endJWSServicesForApplication(Application application, ModuleDescriptor[] moduleDescrs) { 458 String applicationMapKey = NamingConventions.TopLevelApplication.contextRoot(application); 459 ApplicationContentOrigin origin = findApplication(applicationMapKey); 460 if (origin != null) { 461 _logger.fine("Ending Java Web Start services for application " + origin.getTopLevelRegistrationName()); 462 endJWSServices(origin); 463 _logger.info("Java Web Start services ended for application: " + origin); 464 465 468 applications.remove(applicationMapKey); 469 } 470 } 471 472 478 public boolean isEnabled(UserContentOrigin origin){ 479 boolean result = false; 480 String regName = origin.getApplication().getRegistrationName(); 481 try { 482 if (origin instanceof ApplicationContentOrigin) { 483 result = appsManager.isJavaWebStartEnabled(regName); 484 } else { 485 result = appclientModulesManager.isJavaWebStartEnabled(regName); 486 } 487 return result; 488 } catch (ConfigException ce) { 489 _logger.log(Level.SEVERE, "Error checking if Java Web Start access enabled for app client " + origin.getApplication().getRegistrationName(), ce); 490 return false; 491 } 492 } 493 494 500 public boolean isEnabled(ApplicationContentOrigin origin) { 501 try { 502 return appsManager.isJavaWebStartEnabled(origin.getApplication().getRegistrationName()); 503 } catch (ConfigException ce) { 504 _logger.log(Level.SEVERE, "Error checking if Java Web Start access enabled for application " + origin.getApplication().getRegistrationName(), ce); 505 return false; 506 } 507 } 508 515 public Content getContent(HttpServletRequest request) { 516 517 String pathInfo = request.getPathInfo(); 518 519 523 String contentKey = NamingConventions.pathToContentKey(pathInfo); 524 525 530 Content result = contentMap.get(contentKey); 531 532 536 if (result != null) { 537 ContentOrigin origin = result.getOrigin(); 538 if ( ! origin.isEnabled()) { 539 if (_logger.isLoggable(Level.FINE)) { 540 _logger.fine("Located requested document with content key " + contentKey + " but reporting 'not found' because the administrator has disabled Java Web Start access for the application or app client"); 541 } 542 result = null; 543 } 544 } else if (_logger.isLoggable(Level.WARNING) && (result == null) ) { 545 551 _logger.warning("Attempt failed to find Java Web Start content at path " + pathInfo + "; content is available at these paths:" + contentMap.keySet()); 552 } 553 554 return result; 555 } 556 557 561 public void startJWSServicesForDeployedAppclients() { 562 for (ContentOrigin origin : appclients.values()) { 563 AppclientContentOrigin acOrigin = (AppclientContentOrigin) origin; 564 if (acOrigin.isAdhocPathRegistered() == false) { 565 startJWSServices(acOrigin); 566 } 567 } 568 569 for (ContentOrigin origin : applications.values()) { 570 ApplicationContentOrigin aOrigin = (ApplicationContentOrigin) origin; 571 if (aOrigin.isAdhocPathRegistered() == false) { 572 startJWSServices(aOrigin); 573 } 574 } 575 } 576 577 583 private AppclientContentOrigin findAppclient(String regName) { 584 AppclientContentOrigin result = (AppclientContentOrigin) appclients.get(regName); 585 return result; 586 } 587 588 594 private AppclientContentOrigin findAppclient(Application application, ModuleDescriptor moduleDescr) { 595 return findAppclient(application.getRegistrationName()); 596 } 597 598 603 private ApplicationContentOrigin findApplication(String regName) { 604 ApplicationContentOrigin result = (ApplicationContentOrigin) applications.get(regName); 605 return result; 606 } 607 612 private ApplicationContentOrigin findApplication(Application application) { 613 return findApplication(application.getRegistrationName()); 614 } 615 616 620 private void startJWSServices(AppclientContentOrigin origin) { 621 622 WebContainer container = WebContainer.getInstance(); 623 if (container != null) { 625 629 String targetPathString = origin.getTargetPath(); 630 WebPath targetPath = new WebPath(targetPathString); 631 JWSAdHocServletInfo info = new JWSAdHocServletInfo(targetPath.path(), targetPath.contextRoot()); 632 633 String virtualContextRoot = origin.getVirtualPath(); 634 WebPath virtualPath = new WebPath(virtualContextRoot); 635 _logger.info("Registering ad hoc servlet: " + virtualPath); 636 container.registerAdHocPath(virtualPath.path(), 637 virtualPath.contextRoot(), 638 origin.getTopLevelRegistrationName(), 639 info); 640 origin.adhocPathRegistered(); 641 } 642 } 643 644 648 private void endJWSServices(AppclientContentOrigin origin) { 649 650 for (Content c : origin.getContents()) { 651 contentMap.remove(c.getContentKey()); 652 } 653 654 WebPath path = new WebPath(origin.getVirtualPath()); 655 _logger.fine("Unregistering ad hoc servlet: " + path); 656 657 WebContainer container = WebContainer.getInstance(); 658 if (container != null) { 659 container.unregisterAdHocPath(path.path(), path.contextRoot()); 660 } 661 } 662 663 668 private void startJWSServices(ApplicationContentOrigin origin) { 669 670 WebContainer container = WebContainer.getInstance(); 671 if (container != null) { 675 for (AppclientContentOrigin appclient : origin.getAppclientOrigins()) { 676 startJWSServices(appclient); 677 } 678 origin.adhocPathRegistered(); 679 } 680 } 681 682 687 private void endJWSServices(ApplicationContentOrigin origin) { 688 689 for (AppclientContentOrigin appclient : origin.getAppclientOrigins()) { 690 endJWSServices(appclient); 691 } 692 693 for (Content c : origin.getContents()) { 694 contentMap.remove(c.getContentKey()); 695 } 696 } 697 698 703 private void findAppServerObjects() throws IllegalStateException { 704 707 StringBuilder failedObjects = new StringBuilder (); 708 709 Throwable relatedException = null; 710 if ((appServerContext = ApplicationServer.getServerContext()) == null) { 711 failedObjects.append(lineSep).append(" ApplicationServer.getServerContext()"); 712 } 713 if ((instEnv = appServerContext.getInstanceEnvironment()) == null) { 714 failedObjects.append(lineSep).append(" appServerContext.getInstanceEnvironment()"); 715 } 716 try { 717 appsManager = new AppsManager(instEnv, false); 718 } catch (ConfigException ce) { 719 relatedException = ce; 720 failedObjects.append(lineSep).append(" AppsManager(instEnv)"); 721 } 722 723 try { 724 appclientModulesManager = new AppclientModulesManager(instEnv, false); 725 } catch (ConfigException ce) { 726 relatedException = ce; failedObjects.append(lineSep).append(" AppclientModulesManager(instEnv)"); 728 } finally { 729 732 if (failedObjects.length() > 0) { 733 if (relatedException == null) { 734 relatedException = new IllegalStateException ("Null returned"); 735 } 736 throw new IllegalStateException ("The following utility objects could not be initialized: " + failedObjects.toString(), relatedException); 737 } 738 } 739 } 740 741 750 private void preloadAppserverContent() throws IOException , Exception { 751 752 759 AppserverContentOrigin signedLibFilesOrigin = new AppserverContentOrigin( 760 NamingConventions.APPSERVER_CATEGORY, 761 NamingConventions.APPSERVER_LIB_FILES); 762 763 addJWSACCStaticContent(signedLibFilesOrigin); 764 765 768 signedAppserverOrigins.put(NamingConventions.APPSERVER_LIB_FILES, signedLibFilesOrigin); 769 770 AppserverContentOrigin libFilesOrigin = new AppserverContentOrigin( 771 NamingConventions.APPSERVER_CATEGORY, 772 NamingConventions.APPSERVER_LIB_FILES); 773 774 778 addAppserverStaticContent(libRoot, libFilesOrigin, false , 779 "appserv-rt.jar", 780 "appserv-cmp.jar", 781 "appserv-admin.jar", 782 "appserv-deployment-client.jar", 783 "javaee.jar", 784 "appserv-ext.jar", 785 "mail.jar", 786 "activation.jar", 787 "appserv-ws.jar", 788 "toplink-essentials.jar", 789 "dbschema.jar" 790 ); 791 792 795 appserverOrigins.put(NamingConventions.APPSERVER_LIB_FILES, libFilesOrigin); 796 797 800 AppserverContentOrigin derbyLibFilesOrigin = new AppserverContentOrigin( 801 NamingConventions.APPSERVER_CATEGORY, 802 NamingConventions.APPSERVER_LIB_FILES); 803 File derbyRoot = new File (installRootDir, "javadb"); 804 File derbyLib = new File (derbyRoot, "lib"); 805 806 addAppserverStaticContent(derbyLib, derbyLibFilesOrigin, false , "derbyclient.jar"); 807 appserverOrigins.put(NamingConventions.APPSERVER_DERBY_FILES, derbyLibFilesOrigin); 808 809 813 AppserverContentOrigin mqlibFilesOrigin = new AppserverContentOrigin( 814 NamingConventions.APPSERVER_CATEGORY, 815 NamingConventions.APPSERVER_LIB_FILES); 816 817 File mqRoot = new File (installRootDir, "imq"); 818 File mqlibRoot = new File (mqRoot, "lib"); 819 820 addAppserverStaticContent(mqlibRoot, mqlibFilesOrigin, false , "fscontext.jar"); 821 appserverOrigins.put(NamingConventions.APPSERVER_MQLIB_FILES, mqlibFilesOrigin); 822 823 826 AppserverContentOrigin jmsraFilesOrigin = new AppserverContentOrigin( 827 NamingConventions.APPSERVER_CATEGORY, 828 NamingConventions.APPSERVER_LIB_FILES); 829 830 File installRoot = new File (libRoot, "install"); 831 File appsRoot = new File (installRoot, "applications"); 832 File jmsraRoot = new File (appsRoot, "jmsra"); 833 834 addAppserverStaticContent(jmsraRoot, jmsraFilesOrigin, false , "imqjmsra.jar"); 835 836 appserverOrigins.put(NamingConventions.APPSERVER_JMSRALIB_FILES, jmsraFilesOrigin); 837 838 841 AppserverContentOrigin extJarsOrigin = new AppserverContentOrigin( 842 NamingConventions.APPSERVER_CATEGORY, 843 NamingConventions.APPSERVER_LIB_FILES); 844 845 Map <ExtensionFileManager.ExtensionKey,ExtensionFileManager.Extension> extFileInfo = extensionFileManager.getExtensionFileEntries(); 846 847 for (ExtensionFileManager.Extension e : extFileInfo.values()) { 848 File f = e.getFile(); 849 String path = NamingConventions.extJarFilePath(e.getExtDirectoryNumber(), f); 850 String contentKey = extJarsOrigin.getContentKeyPrefix() + path; 851 AppserverStaticContent extContent = new AppserverStaticContent( 852 extJarsOrigin, 853 contentKey, 854 path, 855 f, 856 installRootURI, 857 false); 858 859 extJarsOrigin.pathToContent.put(extContent.getContentKey(), extContent); 860 contentMap.put(extContent.getContentKey(), extContent); 861 } 862 863 extJarAppserverOrigins.put(NamingConventions.APPSERVER_EXTJAR_FILES, extJarsOrigin); 864 } 865 866 private void addJWSACCStaticContent(AppserverContentOrigin origin) throws Exception { 867 868 String signedJarFileName = NamingConventions.SignedJar.signedJarPath(UNSIGNED_JWSACC_JARFILE_NAME); 869 String path = "/" + signedJarFileName; 870 String contentKey = origin.getContentKeyPrefix() + path; 871 File unsignedJar = new File (installRootDir, "lib" + File.separator + UNSIGNED_JWSACC_JARFILE_NAME); 872 File signedJar = new File (instEnv.getJavaWebStartPath(), signedJarFileName); 873 874 SignedStaticContent content = new SignedStaticContent( 875 origin, 876 contentKey, 877 path, 878 signedJar, 879 unsignedJar, 880 installRootURI, 881 localStrings, 882 true 883 ); 884 885 addAppserverStaticContent(origin, content); 886 } 887 888 896 private void addAppserverStaticContent(File dir, AppserverContentOrigin origin, boolean isMain, String ... fileName) { 897 for (String fn : fileName) { 898 String path = "/" + fn; 899 String contentKey = origin.getContentKeyPrefix() + path; 900 901 AppserverStaticContent content = new AppserverStaticContent( 902 origin, 903 contentKey, 904 path, 905 new File (dir, fn), 906 installRootURI, 907 isMain); 908 909 913 addAppserverStaticContent(origin, content); 914 } 915 } 916 917 925 private void addAppserverStaticContent(AppserverContentOrigin origin, StaticContent content) { 926 930 origin.pathToContent.put(content.getContentKey(), content); 931 contentMap.put(content.getContentKey(), content); 932 } 933 934 950 protected Properties prepareInitPlaceholders( 951 AppclientContentOrigin origin, 952 String mainClassName 953 ) { 954 String appclientRegName = origin.getTopLevelRegistrationName(); 955 956 Properties answer = new Properties (); 957 958 answer.setProperty("appserver.codebase.path", NamingConventions.appServerCodebasePath()); 959 960 answer.setProperty("appclient.codebase.path", NamingConventions.appclientCodebasePath(origin)); 961 answer.setProperty("appclient.context-root", origin.getContextRoot()); 962 String vendor = origin.getVendor(); 963 answer.setProperty("appclient.vendor", (vendor == null || vendor.length() == 0) ? localStrings.getString("jws.defaultVendorName") : vendor); 964 answer.setProperty("appclient.client.jnlp.filename", NamingConventions.Client.JNLPFilename(appclientRegName)); 965 answer.setProperty("appclient.client.html.filepath", NamingConventions.Client.HTMLPath(appclientRegName)); 966 answer.setProperty("appclient.mainext.jnlp.filename", NamingConventions.Main.JNLPExtFilename(appclientRegName)); 967 968 976 prepareIIOPProperties(answer); 977 978 984 boolean retainTempFiles = Boolean.getBoolean(SERVER_RETAIN_TEMP_FILES_PROPERTYNAME); 985 answer.setProperty("appclient.retainTempFiles.propertyName", MainWithModuleSupport.APPCLIENT_RETAIN_TEMP_FILES_PROPERTYNAME); 986 answer.setProperty("appclient.retainTempFiles", String.valueOf(retainTempFiles)); 987 988 992 String displayName = origin.getDisplayName(); 993 String jnlpInformationTitle = (displayName != null && displayName.length() > 0) ? displayName : "Application Client " + appclientRegName; 994 answer.setProperty("appclient.information.title", jnlpInformationTitle); 995 996 999 String jnlpInformationHomepageFilepath = NamingConventions.Main.HTMLPath(appclientRegName); 1000 answer.setProperty("appclient.information.homepage.filepath", jnlpInformationHomepageFilepath); 1001 1002 1005 answer.setProperty("appclient.information.description.one-line", jnlpInformationTitle); 1006 1007 1010 String description = origin.getDescription(); 1011 String jnlpInformationShortDescription = (description != null && description.length() > 0) ? description : jnlpInformationTitle; 1012 answer.setProperty("appclient.information.description.short", jnlpInformationShortDescription); 1013 1014 1021 prepareAppserverPlaceholders(answer); 1022 1023 1029 String mainClassArgsValue = ""; 1030 if ((mainClassName != null) && ( ! mainClassName.equals("")) ) { 1031 mainClassArgsValue = " <argument>-mainclass</argument>" + lineSep + 1032 " <argument>" + mainClassName + "</argument>"; 1033 } 1034 answer.setProperty( 1035 "appclient.main.class.arguments", mainClassArgsValue); 1036 1037 1041 answer.setProperty("appclient.isJWS.propertyName", MainWithModuleSupport.APPCLIENT_ISJWS_PROPERTYNAME); 1042 answer.setProperty("appclient.download.host.propertyName", MainWithModuleSupport.APPCLIENT_DOWNLOAD_HOST_PROPERTYNAME); 1043 answer.setProperty("appclient.user.code.is.signed.propertyName", AppClientInfo.USER_CODE_IS_SIGNED_PROPERTYNAME); 1044 return answer; 1045 } 1046 1047 1050 private void prepareIIOPProperties(Properties props) { 1051 1058 props.setProperty("appclient.iiop.defaultHost.propertyName", MainWithModuleSupport.APPCLIENT_IIOP_DEFAULTHOST_PROPERTYNAME); 1059 props.setProperty("appclient.iiop.defaultPort.propertyName", MainWithModuleSupport.APPCLIENT_IIOP_DEFAULTPORT_PROPERTYNAME); 1060 props.setProperty("appclient.iiop.defaultPort", String.valueOf(ORBManager.getORBInitialPort())); 1061 1062 1066 String failoverEndpoints = getIIOPEndpoints(); 1067 String failoverEndpointsSetting = ""; 1068 if (failoverEndpoints != null) { 1069 failoverEndpointsSetting = "<property name=\"" + MainWithModuleSupport.APPCLIENT_IIOP_FAILOVER_ENDPOINTS_PROPERTYNAME + "\" value=\"" + failoverEndpoints + "\"/>"; 1070 } 1071 props.setProperty("appclient.iiop.failover.endpoints", failoverEndpointsSetting); 1072 } 1073 1074 1079 private String getIIOPEndpoints() { 1080 String result = null; 1081 1119 return result; 1120 } 1121 1122 1128 private void prepareAppserverPlaceholders(Properties p) { 1129 p.setProperty( 1130 "appserver.information.title", 1131 localStrings.getString("jws.appserver.information.title")); 1132 p.setProperty( 1133 "appserver.information.vendor", 1134 localStrings.getString("jws.appserver.information.vendor")); 1135 p.setProperty( 1136 "appserver.information.description.one-line", 1137 localStrings.getString("jws.appserver.information.description.one-line")); 1138 p.setProperty( 1139 "appserver.information.description.short", 1140 localStrings.getString("jws.appserver.information.description.short")); 1141 } 1142 1143 1146 private ApplicationContentOrigin prepareApplication(Application application, ModuleDescriptor [] moduleDescrs) 1147 throws IOException , URISyntaxException , SAXParseException , ConfigException, Exception { 1148 1149 refreshConfigContextForManagers(); 1150 1151 ApplicationContentOrigin result = new ApplicationContentOrigin(application); 1152 1153 1157 SignedStaticContent jarFileContent = addAppclientJarContent(result); 1158 1159 String jarHrefs = jarFileContent.asJNLPJarElement(); 1160 1161 String earDirectory = appsManager.getLocation(application.getRegistrationName()); 1162 1163 1168 for (ModuleDescriptor md : moduleDescrs) { 1169 1173 Manifest mf = getManifest(earDirectory, md); 1174 Attributes mainAttrs = mf.getMainAttributes(); 1175 String mainClassName = mainAttrs.getValue(Attributes.Name.MAIN_CLASS); 1176 String appclientJarURI = md.getArchiveUri(); 1177 1178 1187 File appclientJar = new File (appclientJarURI); 1188 File appclientJarDir = appclientJar.getParentFile(); 1189 1190 if ( ! appclientJar.isAbsolute()) { 1191 appclientJar = new File (earDirectory, appclientJarURI); 1192 } 1193 1194 1197 NestedAppclientContentOrigin nestedAppclient = prepareNestedAppclient( 1198 result, 1199 md, 1200 jarHrefs, 1201 mainClassName, 1202 mainAttrs, 1203 appclientJar.getParent(), 1204 jarFileContent); 1205 result.addNestedOrigin(nestedAppclient); 1206 } 1207 1208 return result; 1209 } 1210 1211 1217 private Manifest getManifest(String earDirectoryPath, ModuleDescriptor md) { 1218 1222 String submoduleDirSpec = FileUtils.makeFriendlyFileName(md.getArchiveUri()); 1223 File submoduleDir = new File (earDirectoryPath, submoduleDirSpec); 1224 Manifest mf = EJBClassPathUtils.getManifest(submoduleDir.getAbsolutePath()); 1225 return mf; 1226 } 1227 1228 1240 private AppclientContentOrigin prepareTopLevelAppclient(Application application, ModuleDescriptor moduleDescr) 1241 throws IOException , URISyntaxException , ConfigException, FileNotFoundException , SAXParseException , Exception { 1242 refreshConfigContextForManagers(); 1243 1244 String contextRoot = NamingConventions.TopLevelAppclient.defaultVirtualContextRoot(application); 1245 1246 AppclientContentOrigin result = new AppclientContentOrigin(application, moduleDescr, contextRoot); 1247 String regName = result.getTopLevelRegistrationName(); 1248 1249 1255 1256 String appclientJarPath = result.getAppclientJarPath(); 1257 1258 1262 StaticContent jarFileContent = addAppclientJarContent(result); 1263 1264 String jarHrefs = jarFileContent.asJNLPJarElement(); 1265 1266 String dirPath = appclientModulesManager.getLocation(regName); 1267 Manifest mf = EJBClassPathUtils.getManifest(dirPath); 1268 Attributes mainAttrs = mf.getMainAttributes(); 1269 String mainClassName = mainAttrs.getValue(Attributes.Name.MAIN_CLASS); 1270 1271 1274 prepareAppclient(result, application, moduleDescr, appclientModulesManager, jarHrefs, regName, mainClassName, mainAttrs, dirPath, jarFileContent); 1275 return result; 1276 } 1277 1278 1289 private void prepareAppclient( 1290 AppclientContentOrigin origin, 1291 Application application, 1292 ModuleDescriptor moduleDescr, 1293 BaseManager mgr, 1294 String jarHRefs, 1295 String modName, 1296 String mainClassName, 1297 Attributes mainAttrs, 1298 String dirPathForRelativeClassPathEntries, 1299 StaticContent appclientJarContent) 1300 throws FileNotFoundException , IOException , URISyntaxException , ConfigException { 1301 1302 1308 Properties tokenValues = prepareInitPlaceholders( 1309 origin, 1310 mainClassName 1311 ); 1312 1313 1324 1325 StringBuilder appserverJarElements = buildJarElements(appserverOrigins); 1326 StringBuilder signedAppserverJarElements = buildJarElements(signedAppserverOrigins); 1327 1328 1332 Set <ExtensionFileManager.Extension> earExtJars = findExtensions(mainAttrs, dirPathForRelativeClassPathEntries); 1333 1334 String earJarHrefs = prepareHrefsForFiles(earExtJars); 1335 1336 1337 tokenValues.setProperty("appserver.jar.elements", appserverJarElements.toString()); 1338 tokenValues.setProperty("appserver.jar.elements.signed", signedAppserverJarElements.toString()); 1339 tokenValues.put("appclient.jar.elements", jarHRefs); 1340 1341 1344 String mainJNLPPath = NamingConventions.Main.JNLPPath(modName); 1345 addDynamicContent( 1346 origin, 1347 mainJNLPPath, 1348 NamingConventions.APPCLIENT_MAIN_JNLP_TEMPLATE_NAME, 1349 tokenValues, 1350 JNLP_MIME_TYPE, 1351 true 1352 ); 1353 1354 1357 String mainExtJNLPPath = NamingConventions.Main.JNLPExtPath(modName); 1358 addDynamicContent( 1359 origin, 1360 mainExtJNLPPath, 1361 NamingConventions.APPCLIENT_MAIN_JNLP_EXT_TEMPLATE_NAME, 1362 tokenValues, 1363 JNLP_MIME_TYPE); 1364 1365 1368 String mainHTMLPath = NamingConventions.Main.HTMLPath(modName); 1369 addDynamicContent( 1370 origin, 1371 mainHTMLPath, 1372 NamingConventions.APPCLIENT_MAIN_HTML_TEMPLATE_NAME, 1373 tokenValues, 1374 HTML_MIME_TYPE); 1375 1376 1379 String clientHTMLPath = NamingConventions.Client.HTMLPath(modName); 1380 addDynamicContent( 1381 origin, 1382 clientHTMLPath, 1383 NamingConventions.APPCLIENT_CLIENT_HTML_TEMPLATE_NAME, 1384 tokenValues, 1385 HTML_MIME_TYPE); 1386 1387 1392 String clientJNLPPath = NamingConventions.Client.JNLPPath(modName); 1393 1394 String contentKey = origin.getContentKeyPrefix() + clientJNLPPath; 1395 String docText = Util.replaceTokens( 1396 templateCache.getTemplate(NamingConventions.APPCLIENT_CLIENT_JNLP_TEMPLATE_NAME), 1397 tokenValues); 1398 1399 DynamicContent clientJNLPContent = new DynamicContent( 1400 origin, 1401 contentKey, 1402 clientJNLPPath, 1403 docText, 1404 JNLP_MIME_TYPE, 1405 true 1406 ); 1407 1408 1413 addDynamicContent(origin, clientJNLPContent); 1414 } 1415 1416 1422 private NestedAppclientContentOrigin prepareNestedAppclient( 1423 ApplicationContentOrigin parent, 1424 ModuleDescriptor moduleDescr, 1425 String jarHRefs, 1426 String mainClassName, 1427 Attributes mainAttrs, 1428 String dirPathForRelativeClassPathEntries, 1429 StaticContent appclienJarContent) 1430 throws FileNotFoundException , IOException , URISyntaxException , ConfigException { 1431 1432 String contextRoot = NamingConventions.NestedAppclient.defaultVirtualContextRoot(parent.getApplication(), moduleDescr); 1433 1434 NestedAppclientContentOrigin result = new NestedAppclientContentOrigin(parent, moduleDescr, contextRoot); 1435 1436 prepareAppclient( 1437 result, 1438 parent.getApplication(), 1439 moduleDescr, 1440 appsManager, 1441 jarHRefs, 1442 result.getName(), 1443 mainClassName, 1444 mainAttrs, 1445 dirPathForRelativeClassPathEntries, 1446 appclienJarContent 1447 ); 1448 1449 return result; 1450 } 1451 1452 1459 private void refreshConfigContextForManagers() throws ConfigException { 1460 appsManager.refreshConfigContext(); 1461 appclientModulesManager.refreshConfigContext(); 1462 } 1463 1464 1475 private Set <ExtensionFileManager.Extension> findExtensions(Attributes attrs, String appDirPath) throws IOException , ConfigException { 1476 Set <ExtensionFileManager.Extension> result = null; 1477 1478 File appDir = new File (appDirPath); 1479 result = extensionFileManager.findExtensionTransitiveClosure(appDir, attrs); 1480 return result; 1481 } 1482 1483 1488 private Attributes getMainAttributesForApplication(Application application) throws ConfigException, IOException { 1489 Attributes result = null; 1490 ModuleType type = application.getModuleType(); 1491 BaseManager mgr = null; 1492 if (type.equals(type.EAR) ) { 1493 mgr = appsManager; 1494 } else { 1495 mgr = appclientModulesManager; 1496 } 1497 1498 String dirPath = mgr.getLocation(application.getRegistrationName()); 1499 Manifest mf = loadManifestFromFile(dirPath); 1500 result = mf.getMainAttributes(); 1501 1502 return result; 1503 } 1504 1505 private Manifest loadManifestFromFile(String dirPath) throws IOException { 1506 Manifest result = null; 1507 InputStream is = null; 1508 try { 1509 File manifestFile = new File (dirPath, JarFile.MANIFEST_NAME); 1510 if (manifestFile.exists() && manifestFile.canRead()) { 1511 is = new FileInputStream (manifestFile); 1512 result = new Manifest (is); 1513 } 1514 return result; 1515 } finally { 1516 if (is != null) { 1517 is.close(); 1518 } 1519 } 1520 } 1521 1522 1528 private String prepareHrefsForFiles(Set <ExtensionFileManager.Extension> extJarInfo) { 1529 ContentOrigin extJarsOrigin = extJarAppserverOrigins.get(NamingConventions.APPSERVER_EXTJAR_FILES); 1530 StringBuilder result = new StringBuilder (); 1531 for (ExtensionFileManager.Extension e : extJarInfo) { 1532 String path = NamingConventions.extJarFilePath(e.getExtDirectoryNumber(), e.getFile()); 1533 String contentKey = extJarsOrigin.getContentKeyPrefix() + path; 1534 StaticContent content = (StaticContent) extJarsOrigin.getContent(contentKey); 1535 result.append(content.asJNLPJarElement()).append(lineSep); 1536 } 1537 return result.toString(); 1538 } 1539 1540 1552 private DynamicContent addDynamicContent( 1553 ContentOrigin origin, 1554 String path, 1555 String templateName, 1556 Properties tokenValues, 1557 String mimeType, 1558 boolean requiresElevatedPrivs) throws IOException { 1559 1560 DynamicContent content = origin.addDynamicContent( 1561 path, 1562 templateCache.getTemplate(templateName), 1563 tokenValues, 1564 mimeType, 1565 requiresElevatedPrivs); 1566 contentMap.put(content.getContentKey(), content); 1567 return content; 1568 } 1569 1570 1581 private DynamicContent addDynamicContent( 1582 ContentOrigin origin, 1583 String path, 1584 String templateName, 1585 Properties tokenValues, 1586 String mimeType) throws IOException { 1587 return addDynamicContent(origin, path, templateName, tokenValues, mimeType, false ); 1588 } 1589 1590 private DynamicContent addDynamicContent( 1591 ContentOrigin origin, 1592 DynamicContent content) { 1593 1594 origin.addDynamicContent(content); 1595 contentMap.put(content.getContentKey(), content); 1596 return content; 1597 } 1598 1599 1608 private StaticContent addStaticContent( 1609 ContentOrigin origin, 1610 String path, 1611 File file) throws URISyntaxException { 1612 1613 StaticContent content = origin.addStaticContent(path, installRootURI, file); 1614 contentMap.put(content.getContentKey(), content); 1615 return content; 1616 } 1617 1618 1625 private StaticContent addStaticContent( 1626 ContentOrigin origin, 1627 StaticContent content) throws URISyntaxException { 1628 1629 origin.addStaticContent(content); 1630 contentMap.put(content.getContentKey(), content); 1631 return content; 1632 } 1633 1634 1640 private SignedStaticContent addAppclientJarContent( 1641 ApplicationContentOrigin origin) throws FileNotFoundException , URISyntaxException , Exception { 1642 1643 return addAppclientJarContent(origin, origin.getAppclientJarPath(), appsManager); 1644 } 1645 1646 1652 private SignedStaticContent addAppclientJarContent( 1653 AppclientContentOrigin origin) throws FileNotFoundException , URISyntaxException , Exception { 1654 1655 return addAppclientJarContent(origin, origin.getAppclientJarPath(), appclientModulesManager); 1656 } 1657 1658 1666 private SignedStaticContent addAppclientJarContent( 1667 UserContentOrigin origin, 1668 String appclientJarPath, 1669 BaseManager manager) throws FileNotFoundException , URISyntaxException , Exception { 1670 1671 File generatedJar = origin.locateGeneratedAppclientJarFile(manager); 1672 File signedGeneratedJar = 1673 NamingConventions.SignedJar.signedGeneratedAppclientJarFile( 1674 origin, 1675 instEnv, 1676 generatedJar); 1677 String contentKey = origin.getContentKeyPrefix() + "/" + signedGeneratedJar.getName(); 1678 1679 SignedStaticContent content = new SignedStaticContent( 1680 origin, 1681 contentKey, 1682 appclientJarPath, 1683 signedGeneratedJar, 1684 generatedJar, 1685 installRootURI, 1686 localStrings, 1687 false ); 1688 1689 addAppclientJarContent(origin, content); 1690 return content; 1691 } 1692 1693 1702 private SignedStaticContent addAppclientJarContent(UserContentOrigin origin, SignedStaticContent content) throws URISyntaxException { 1703 addStaticContent(origin, content); 1704 return content; 1706 1707 } 1708 1709 1720 private StringBuilder buildJarElements(Map <String ,ContentOrigin> origins) { 1721 1722 StringBuilder appserverJarElements = new StringBuilder (); 1723 1726 for (ContentOrigin origin : origins.values()) { 1727 1730 for (Content c : origin.pathToContent.values()) { 1731 if (c instanceof StaticContent) { 1732 StaticContent sc = (StaticContent) c; 1733 appserverJarElements.append(sc.asJNLPJarElement()); 1734 } 1735 } 1736 } 1737 return appserverJarElements; 1738 } 1739 1740} 1741 | Popular Tags |