1 23 package com.sun.enterprise.appclient.jws; 24 import com.sun.enterprise.config.ConfigException; 25 import com.sun.enterprise.deployment.Application; 26 import com.sun.enterprise.deployment.ApplicationClientDescriptor; 27 import com.sun.enterprise.deployment.BundleDescriptor; 28 import com.sun.enterprise.deployment.interfaces.DeploymentImplConstants; 29 import com.sun.enterprise.deployment.runtime.JavaWebStartAccessDescriptor; 30 import com.sun.enterprise.deployment.util.ModuleDescriptor; 31 import com.sun.enterprise.instance.AppclientModulesManager; 32 import com.sun.enterprise.instance.ApplicationEnvironment; 33 import com.sun.enterprise.instance.AppsManager; 34 import com.sun.enterprise.instance.BaseManager; 35 import com.sun.enterprise.instance.InstanceEnvironment; 36 import com.sun.enterprise.server.ApplicationServer; 37 import com.sun.enterprise.server.ServerContext; 38 import com.sun.enterprise.util.i18n.StringManager; 39 import com.sun.enterprise.web.WebContainer; 40 import com.sun.logging.LogDomains; 41 import java.io.File ; 42 import java.io.FileFilter ; 43 import java.io.FilenameFilter ; 44 import java.net.URI ; 45 import java.net.URISyntaxException ; 46 import java.util.Iterator ; 47 import java.util.Vector ; 48 import java.util.logging.Level ; 49 import java.util.logging.Logger ; 50 import javax.enterprise.deploy.shared.ModuleType ; 51 import javax.servlet.ServletConfig ; 52 import javax.servlet.http.HttpServletRequest ; 53 54 63 public class NamingConventions { 64 65 66 67 71 public static final String SYSTEM_WEBAPP_URL = "/__JWSappclients"; 72 73 79 public static String pathToContentKey(String requestPath) { 80 return requestPath; 81 } 82 83 88 public static String contentKeyToPath(String contentKey) { 89 return contentKey; 90 } 91 92 117 118 119 public static final String APPCLIENT_CATEGORY = "__appclient"; 120 public static final String APPLICATION_CATEGORY = "__application"; 121 public static final String APPSERVER_CATEGORY = "__appserver"; 122 public static final String APPSERVER_SIGNED_CATEGORY = "__appserverS"; 123 124 125 126 public static final String APPSERVER_LIB_FILES = "aslib"; public static final String APPSERVER_MQLIB_FILES = "mqlib"; public static final String APPSERVER_JMSRALIB_FILES = "jmsralib"; public static final String APPSERVER_EXTJAR_FILES = "extjar"; public static final String APPSERVER_DERBY_FILES = "derby"; 135 public static final String APPCLIENT_MAIN_JNLP_TEMPLATE_NAME = "appclientMainDocumentTemplate.jnlp"; 136 public static final String APPCLIENT_CLIENT_JNLP_TEMPLATE_NAME = "appclientClientDocumentTemplate.jnlp"; 137 public static final String APPCLIENT_MAIN_HTML_TEMPLATE_NAME = "appclientMainDocumentTemplate.html"; 138 public static final String APPCLIENT_CLIENT_HTML_TEMPLATE_NAME = "appclientClientDocumentTemplate.html"; 139 public static final String APPCLIENT_MAIN_JNLP_EXT_TEMPLATE_NAME = "appclientMainExtDocumentTemplate.jnlp"; 140 141 145 private static final String MAIN_JNLP_SUFFIX = ".jnlp"; 146 private static final String MAIN_HTML_SUFFIX = "-jnlp.html"; 147 private static final String CLIENT_JNLP_SUFFIX = "-client.jnlp"; 148 private static final String CLIENT_HTML_SUFFIX = "-client-jnlp.html"; 149 private static final String MAIN_EXT_JNLP_SUFFIX = "-ext.jnlp"; 150 151 152 public static final String JWS_LOGGER = LogDomains.DPL_LOGGER; 153 154 162 163 164 private AppsManager appsManager = null; 165 166 167 private AppclientModulesManager appclientModulesManager = null; 168 169 175 public NamingConventions() throws ConfigException { 176 ServerContext appServerContext; 177 InstanceEnvironment instEnv; 178 179 if ((appServerContext = ApplicationServer.getServerContext()) == null) { 180 throw new ConfigException("Error getting current app server context; ApplicationServer.getServerContext() returned null"); 181 } 182 if ((instEnv = appServerContext.getInstanceEnvironment()) == null) { 183 throw new ConfigException("Error getting current instance environment; appServercontext.getInstanceEnvironment() returned null"); 184 } 185 appsManager = new AppsManager(instEnv, false); 186 appclientModulesManager = new AppclientModulesManager(instEnv, false); 187 } 188 189 194 public NamingConventions(AppsManager appsManager, AppclientModulesManager appclientModulesManager) { 195 this.appsManager = appsManager; 196 this.appclientModulesManager = appclientModulesManager; 197 } 198 199 public static String webAppURI() { 200 return SYSTEM_WEBAPP_URL; 201 } 202 203 public static String appServerCodebasePath() { 204 return SYSTEM_WEBAPP_URL + "/" + APPSERVER_CATEGORY; 205 } 206 207 public static String fullJarPath(String contentKey) { 208 return SYSTEM_WEBAPP_URL + contentKeyToPath(contentKey); 209 } 210 211 public static String relativeFilePath(URI instanceRootDirURI, File targetFile) { 212 URI targetURI = targetFile.toURI(); 213 URI relativeURI = instanceRootDirURI.relativize(targetURI); 214 return relativeURI.toString(); 215 } 216 217 public static String extJarFilePath(int extDirNumber, File extJarFile) { 218 String path = "/" + extDirNumber + "/" + extJarFile.getName(); 219 return path; 220 } 221 222 227 private static String getExplicitContextRoot(ModuleDescriptor moduleDescr) { 228 231 String result = null; 232 233 BundleDescriptor bd = moduleDescr.getDescriptor(); 234 if (bd instanceof ApplicationClientDescriptor) { 235 ApplicationClientDescriptor acd = (ApplicationClientDescriptor) bd; 236 JavaWebStartAccessDescriptor jwsAD = acd.getJavaWebStartAccessDescriptor(); 237 if (jwsAD != null) { 238 result = jwsAD.getContextRoot(); 239 } 240 } 241 return result; 242 } 243 244 248 private static String chooseContextRoot(String explicitValue, String defaultValue) { 249 return (explicitValue == null) ? defaultValue : explicitValue; 250 } 251 252 public static String appclientCodebasePath(AppclientContentOrigin origin) { 253 String result = SYSTEM_WEBAPP_URL + "/" + APPCLIENT_CATEGORY + origin.getContextRoot(); 254 return result; 255 } 256 257 private static String appclientJarFilename(String regName) { 258 return regName + DeploymentImplConstants.ClientJarSuffix; 259 } 260 261 262 265 public static class TopLevelAppclient { 266 267 public static String virtualContextRoot(Application application, ModuleDescriptor moduleDescr) { 268 return chooseContextRoot(getExplicitContextRoot(moduleDescr), defaultVirtualContextRoot(application)); 269 } 270 271 public static String actualContextRoot(Application application) { 272 String regName = application.getRegistrationName(); 273 return "/" + APPCLIENT_CATEGORY + "/" + regName + NamingConventions.Main.JNLPPath(regName); 274 } 275 276 public static String defaultVirtualContextRoot(Application application) { 277 return "/" + application.getRegistrationName(); 278 } 279 280 public static String contentKeyPrefix(AppclientContentOrigin origin) { 281 return "/" + APPCLIENT_CATEGORY + "/" + origin.getTopLevelRegistrationName(); 282 } 283 284 public static String appclientJarPath(AppclientContentOrigin origin) { 285 return "/" + appclientJarFilename(origin.getTopLevelRegistrationName()); 286 } 287 } 288 289 292 public static class NestedAppclient { 293 294 public static String virtualContextRoot(Application parentApplication, ModuleDescriptor moduleDescr) { 295 return chooseContextRoot(getExplicitContextRoot(moduleDescr), defaultVirtualContextRoot(parentApplication, moduleDescr)); 296 } 297 298 public static String actualContextRoot(NestedAppclientContentOrigin origin) { 299 String regName = origin.getTopLevelRegistrationName(); 300 String clientName = origin.getName(); 301 return "/" + APPCLIENT_CATEGORY + "/" + regName + "/" + clientName + NamingConventions.Main.JNLPPath(clientName); 302 } 303 304 public static String defaultVirtualContextRoot(Application parentApplication, ModuleDescriptor moduleDescr) { 305 return "/" + parentApplication.getRegistrationName() + "/" + trimJarFileType(moduleDescr.getArchiveUri(),""); 306 } 307 308 public static String contentKeyPrefix(NestedAppclientContentOrigin origin) { 309 return "/" + APPCLIENT_CATEGORY + "/" + origin.getTopLevelRegistrationName() + "/" + origin.getName(); 310 } 311 312 316 317 327 public static String archiveURIToName(String archiveURI) { 328 return trimJarFileType(archiveURI, ""); 329 } 330 } 331 332 public static class TopLevelApplication { 333 334 public static String contextRoot(Application application) { 335 return "/" + application.getRegistrationName(); 336 } 337 338 public static String contentKeyPrefix(ApplicationContentOrigin origin) { 339 return "/" + APPLICATION_CATEGORY + "/" + origin.getTopLevelRegistrationName(); 340 } 341 342 public static String appclientJarPath(ApplicationContentOrigin origin) { 343 return "/" + appclientJarFilename(origin.getTopLevelRegistrationName()); 344 } 345 } 346 347 public static class Appserver { 348 public static String contentKeyPrefix(AppserverContentOrigin origin) { 349 return "/" + APPSERVER_CATEGORY + "/" + origin.getSubcategory(); 350 } 351 } 352 353 357 public static class Main { 358 359 private static final String name = "main"; 360 361 public static String JNLPFilename(String regName) { 362 return name + MAIN_JNLP_SUFFIX; 363 } 364 365 public static String JNLPPath(String regName) { 366 return "/" + JNLPFilename(regName); 367 } 368 369 public static String JNLPExtFilename(String regName) { 370 return name + MAIN_EXT_JNLP_SUFFIX; 371 } 372 373 public static String JNLPExtPath(String regName) { 374 return "/" + JNLPExtFilename(regName); 375 } 376 377 public static String HTMLPath(String regName) { 378 return "/" + HTMLFilename(regName); 379 } 380 381 public static String HTMLFilename(String regName) { 382 return name + MAIN_HTML_SUFFIX; 383 } 384 } 385 386 390 public static class Client { 391 392 private static final String name = "client"; 393 394 public static String JNLPFilename(String regName) { 395 return name + CLIENT_JNLP_SUFFIX; 396 } 397 398 public static String JNLPPath(String regName) { 399 return "/" + JNLPFilename(regName); 400 } 401 402 public static String HTMLFilename(String regName) { 403 return name + CLIENT_HTML_SUFFIX; 404 } 405 406 public static String HTMLPath(String regName) { 407 return "/" + HTMLFilename(regName); 408 } 409 } 410 411 412 418 private static String trimJarFileType(String jarURI, String replacement) { 419 int startOfType = jarURI.lastIndexOf(".jar"); 420 if (startOfType == -1) { 421 startOfType = jarURI.length(); 422 } 423 String result = jarURI.substring(0, startOfType) + replacement; 424 return result; 425 } 426 427 434 public String getLaunchURLPath(String appclientModuleID) { 435 String result = null; 436 try { 437 Application app = appclientModulesManager.getDescriptor(appclientModuleID, Thread.currentThread().getContextClassLoader(), false); 438 441 ModuleDescriptor[] moduleDescrs = getEligibleAppclientModuleDescriptors(app); 442 if (moduleDescrs.length == 1) { 443 447 result = TopLevelAppclient.virtualContextRoot(app, moduleDescrs[0]); 448 } 449 } catch (ConfigException ce) { 450 453 } 454 return result; 455 } 456 457 466 public String getLaunchURLPath(String appModuleID, String appclientArchiveURI) { 467 String result = null; 468 try { 469 Application app = appsManager.getDescriptor(appModuleID, Thread.currentThread().getContextClassLoader(), false); 470 ModuleDescriptor[] moduleDescrs = getEligibleAppclientModuleDescriptors(app); 471 475 for (ModuleDescriptor m : moduleDescrs) { 476 String archiveURI = m.getArchiveUri(); 477 if (archiveURI != null && archiveURI.equals(appclientArchiveURI)) { 478 result = NestedAppclient.virtualContextRoot(app, m); 479 break; 480 } 481 } 482 } catch (ConfigException ce) { 483 486 } 487 return result; 488 } 489 490 496 public static ModuleDescriptor[] getEligibleAppclientModuleDescriptors(Application app) { 497 return getEligibleAppclientModuleDescriptors(app, null); 498 } 499 500 501 509 public static ModuleDescriptor[] getEligibleAppclientModuleDescriptors(Application app, Logger logger) { 510 Vector <ModuleDescriptor> mds = new Vector <ModuleDescriptor>(); 511 512 520 for (Iterator it = app.getModulesByType(ModuleType.CAR); it.hasNext();) { 521 Object o = it.next(); 522 if (o instanceof ModuleDescriptor) { 523 ModuleDescriptor moduleDescriptor = (ModuleDescriptor) o; 524 BundleDescriptor bd = moduleDescriptor.getDescriptor(); 525 if (bd instanceof ApplicationClientDescriptor) { 526 ApplicationClientDescriptor appclientDescriptor = (ApplicationClientDescriptor) bd; 527 JavaWebStartAccessDescriptor jwsAD = appclientDescriptor.getJavaWebStartAccessDescriptor(); 528 if (jwsAD == null || jwsAD.isEligible()) { 529 mds.add(moduleDescriptor); 530 } 531 } else { 532 if (logger != null) { 533 logger.warning("During app/app client loading, expected bundleDescriptor for app client module to be of type ApplicationClientDescriptor but it is " + bd.getClass().getName() + "; ignoring it and continuing"); 534 } 535 } 536 } else { 537 if (logger != null) { 538 logger.warning("During app/app client loading, expected descriptor of type ModuleDescriptor but found " + o.getClass().getName() + " instead; ignoring it and continuing"); 539 } 540 } 541 } 542 return mds.toArray(new ModuleDescriptor[mds.size()]); 543 } 544 545 549 public static class SignedJar { 550 551 private static String SIGNED_JAR_FILENAME_SUFFIX = "-signed"; 552 553 560 public static File signedGeneratedAppclientJarFile( 561 UserContentOrigin origin, 562 InstanceEnvironment instEnv, 563 File generatedAppclientFile) { 564 String regName = origin.getTopLevelRegistrationName(); 565 ApplicationEnvironment appEnv = instEnv.getApplicationEnvironment(regName); 566 File result = new File (appEnv.getJavaWebStartPath(), signedJarPath(generatedAppclientFile.getName())); 567 return result; 568 } 569 570 575 public static String signedJarPath(String unsignedJarPath) { 576 return unsignedJarPath; 583 } 584 585 591 private static File getAppJWSDir(InstanceEnvironment instEnv, String regName) { 592 ApplicationEnvironment appEnv = instEnv.getApplicationEnvironment(regName); 593 String appJWSDirPath = appEnv.getJavaWebStartPath(); 594 File appJWSDir = new File (appJWSDirPath); 595 return appJWSDir; 596 } 597 } 598 } 599 | Popular Tags |