1 23 package com.sun.enterprise.admin.wsmgmt.repository.impl; 24 25 import java.io.File ; 26 import java.io.FileInputStream ; 27 import java.util.Map ; 28 import java.util.HashMap ; 29 import java.util.Collection ; 30 import java.util.Iterator ; 31 import java.util.List ; 32 import com.sun.enterprise.util.io.FileUtils; 33 import com.sun.enterprise.util.RelativePathResolver; 34 import com.sun.enterprise.config.ConfigContext; 35 import com.sun.enterprise.config.serverbeans.EjbModule; 36 import com.sun.enterprise.config.serverbeans.WebModule; 37 import com.sun.enterprise.config.serverbeans.ApplicationHelper; 38 import com.sun.enterprise.admin.server.core.AdminService; 39 import com.sun.enterprise.deployment.Application; 40 import com.sun.enterprise.deployment.BundleDescriptor; 41 import com.sun.enterprise.deployment.util.ModuleDescriptor; 42 import com.sun.enterprise.util.SystemPropertyConstants; 43 import com.sun.enterprise.admin.servermgmt.pe.PEFileLayout; 44 import javax.enterprise.deploy.shared.ModuleType ; 45 import com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile; 46 import com.sun.enterprise.admin.wsmgmt.repository.spi.WebServiceInfoProvider; 47 import com.sun.enterprise.admin.wsmgmt.repository.spi.RepositoryProvider; 48 import com.sun.enterprise.admin.wsmgmt.repository.impl.cache.CacheMgr; 49 import com.sun.enterprise.admin.wsmgmt.repository.impl.cache.J2eeApplication; 50 import com.sun.enterprise.admin.wsmgmt.repository.spi.RepositoryException; 51 52 import java.util.logging.Logger ; 53 import java.util.logging.Level ; 54 import com.sun.logging.LogDomains; 55 56 64 public class AppServRepositoryProvider implements RepositoryProvider { 65 66 69 public AppServRepositoryProvider() { 70 if (instanceRoot == null) { 71 instanceRoot = System.getProperty( 72 SystemPropertyConstants.INSTANCE_ROOT_PROPERTY); 73 } 74 } 75 76 81 public String getProviderID() { 82 return PROVIDER_ID; 83 } 84 85 91 public Map getWebServiceModules() { 92 Map map = new HashMap (); 93 94 ConfigContext configCtx = AdminService.getAdminService(). 96 getAdminContext().getAdminConfigContext(); 97 98 CacheMgr mgr = CacheMgr.getInstance(); 99 100 Map apps = mgr.getJ2eeApplications(); 102 Collection aValues = apps.values(); 103 for (Iterator iter=aValues.iterator(); iter.hasNext();) { 104 J2eeApplication app = (J2eeApplication) iter.next(); 105 106 List ejbBundles = app.getEjbBundles(); 108 if (ejbBundles != null) { 109 for (Iterator itr=ejbBundles.iterator(); itr.hasNext();) { 110 String ejb = (String ) itr.next(); 111 try { 112 Map m = getEjbBundleInfo(configCtx, app.getName(), ejb); 113 map.put(m.get(WebServiceInfoProvider. 114 SUN_EJB_JAR_XML_LOCATION_PROP_NAME), m); 115 } catch (RepositoryException re) { } 116 } 117 } 118 119 List webBundles = app.getWebBundles(); 121 if (webBundles != null) { 122 for (Iterator itr=webBundles.iterator(); itr.hasNext();) { 123 String web = (String ) itr.next(); 124 try { 125 Map m = getWebBundleInfo(configCtx, app.getName(), web); 126 map.put(m.get(WebServiceInfoProvider. 127 SUN_WEB_XML_LOCATION_PROP_NAME), m); 128 } catch (RepositoryException re) { } 129 } 130 } 131 } 132 133 Map ejbs = mgr.getEjbModules(); 135 Collection eValues = ejbs.values(); 136 for (Iterator iter=eValues.iterator(); iter.hasNext();) { 137 String ejbMod = (String ) iter.next(); 138 try { 139 Map m = getEjbModuleInfo(configCtx, ejbMod); 140 map.put(m.get(WebServiceInfoProvider. 141 SUN_EJB_JAR_XML_LOCATION_PROP_NAME), m); 142 } catch (RepositoryException re) { } 143 } 144 145 Map webs = mgr.getWebModules(); 147 Collection wValues = webs.values(); 148 for (Iterator iter=wValues.iterator(); iter.hasNext();) { 149 String webMod = (String ) iter.next(); 150 151 try { 152 Map m = getWebModuleInfo(configCtx, webMod); 153 map.put(m.get(WebServiceInfoProvider. 154 SUN_WEB_XML_LOCATION_PROP_NAME), m); 155 } catch (RepositoryException re) { } 156 } 157 158 return map; 159 } 160 161 168 private String getAltDD(String bundleName, String appXML, 169 boolean ejbBundle) { 170 171 String altDD = null; 172 FileInputStream fis = null; 173 try { 174 File f = new File (appXML); 176 if (!f.exists() || (bundleName==null)) { 177 return null; 178 } 179 180 ApplicationDeploymentDescriptorFile addf = 181 new ApplicationDeploymentDescriptorFile(); 182 fis = new FileInputStream (f); 183 Application app = (Application) addf.read(fis); 184 for (Iterator itr=app.getModules();itr.hasNext();) { 185 ModuleDescriptor md = (ModuleDescriptor) itr.next(); 186 String uri = md.getArchiveUri(); 187 if (bundleName.equals(uri)) { 188 altDD = md.getAlternateDescriptor(); 189 break; 190 } 191 } 192 } catch (Exception e) { 193 _logger.log(Level.FINE, "Error while reading alt-dd", e); 194 } finally { 195 if (fis != null) { 196 try { 197 fis.close(); 198 } catch (Exception e) { } 199 } 200 } 201 202 return altDD; 203 } 204 205 215 private Map getEjbBundleInfo(ConfigContext ctx, String name, 216 String bundleName) throws RepositoryException { 217 218 if ( (bundleName == null) || (ctx == null) || (name == null) ) { 220 throw new IllegalArgumentException (); 221 } 222 223 Map map = new HashMap (); 224 225 try { 226 map.put(WebServiceInfoProvider.MOD_TYPE_PROP_NAME, 228 WebServiceInfoProvider.MOD_TYPE_EJB); 229 230 map.put(WebServiceInfoProvider.APP_ID_PROP_NAME, name); 232 233 map.put(WebServiceInfoProvider.BUNDLE_NAME_PROP_NAME, bundleName); 235 236 248 String xmlDir = instanceRoot 250 + File.separator + PEFileLayout.GENERATED_DIR 251 + File.separator + PEFileLayout.XML_DIR 252 + File.separator + PEFileLayout.J2EE_APPS_DIR 253 + File.separator + name; 254 255 String bundleRoot = xmlDir + File.separator 257 + FileUtils.makeFriendlyFileName(bundleName); 258 map.put(WebServiceInfoProvider.BUNDLE_ROOT_LOCATION_PROP_NAME, 259 bundleRoot); 260 261 String ejbXML = null; 262 String sunEjbXML = null; 263 264 String appXML = xmlDir +File.separator + META_INF 266 + File.separator + APPLICATION_XML; 267 map.put(WebServiceInfoProvider.APPLICATION_XML_PROP_NAME, 268 getFormattedFileContents(appXML)); 269 String altDD = getAltDD(bundleName, appXML, true); 270 271 if (altDD == null) { 273 ejbXML = bundleRoot + File.separator + META_INF 274 + File.separator + EJB_JAR_XML; 275 276 sunEjbXML = bundleRoot + File.separator + META_INF 277 + File.separator + SUN_EJB_JAR_XML; 278 } else { 279 ejbXML = xmlDir + File.separator + altDD; 280 sunEjbXML = xmlDir + File.separator + SUN_DASH 281 + new File (ejbXML).getName(); 282 } 283 284 285 map.put(WebServiceInfoProvider.EJB_JAR_XML_PROP_NAME, 287 getFormattedFileContents(ejbXML)); 288 289 map.put(WebServiceInfoProvider.SUN_EJB_JAR_XML_LOCATION_PROP_NAME, 291 sunEjbXML); 292 map.put(WebServiceInfoProvider.SUN_EJB_JAR_XML_PROP_NAME, 293 getFormattedFileContents(sunEjbXML)); 294 295 String wsXML = bundleRoot + File.separator 297 + META_INF + File.separator + WEBSERVICES_XML; 298 map.put(WebServiceInfoProvider.WS_XML_LOCATION_PROP_NAME, wsXML); 299 map.put(WebServiceInfoProvider.WS_XML_PROP_NAME, 300 getFormattedFileContents(wsXML)); 301 302 } catch (Exception e) { 303 throw new RepositoryException(e); 304 } 305 306 return map; 307 } 308 309 319 private Map getWebBundleInfo(ConfigContext ctx, String name, 320 String bundleName) throws RepositoryException { 321 322 if ( (bundleName == null) || (ctx == null) || (name == null) ) { 324 throw new IllegalArgumentException (); 325 } 326 327 Map map = new HashMap (); 328 329 try { 330 map.put(WebServiceInfoProvider.MOD_TYPE_PROP_NAME, 332 WebServiceInfoProvider.MOD_TYPE_WEB); 333 334 map.put(WebServiceInfoProvider.APP_ID_PROP_NAME, name); 336 337 map.put(WebServiceInfoProvider.BUNDLE_NAME_PROP_NAME, bundleName); 339 340 352 String xmlDir = instanceRoot 354 + File.separator + PEFileLayout.GENERATED_DIR 355 + File.separator + PEFileLayout.XML_DIR 356 + File.separator + PEFileLayout.J2EE_APPS_DIR 357 + File.separator + name; 358 359 String bundleRoot = xmlDir + File.separator 361 + FileUtils.makeFriendlyFileName(bundleName); 362 map.put(WebServiceInfoProvider.BUNDLE_ROOT_LOCATION_PROP_NAME, 363 bundleRoot); 364 365 String webXML = null; 366 String sunWebXML = null; 367 368 String appXML = xmlDir +File.separator + META_INF 370 + File.separator + APPLICATION_XML; 371 map.put(WebServiceInfoProvider.APPLICATION_XML_PROP_NAME, 372 getFormattedFileContents(appXML)); 373 String altDD = getAltDD(bundleName, appXML, false); 374 375 if (altDD == null) { 377 webXML = bundleRoot + File.separator + WEB_INF 378 + File.separator + WEB_XML; 379 380 sunWebXML = bundleRoot + File.separator + WEB_INF 381 + File.separator + SUN_WEB_XML; 382 } else { 383 webXML = xmlDir + File.separator + altDD; 384 sunWebXML = xmlDir + File.separator + SUN_DASH 385 + new File (webXML).getName(); 386 } 387 388 map.put(WebServiceInfoProvider.WEB_XML_PROP_NAME, 390 getFormattedFileContents(webXML)); 391 392 map.put(WebServiceInfoProvider.SUN_WEB_XML_LOCATION_PROP_NAME, 394 sunWebXML); 395 map.put(WebServiceInfoProvider.SUN_WEB_XML_PROP_NAME, 396 getFormattedFileContents(sunWebXML)); 397 398 String wsXML = bundleRoot + File.separator + WEB_INF 400 + File.separator + WEBSERVICES_XML; 401 map.put(WebServiceInfoProvider.WS_XML_LOCATION_PROP_NAME, wsXML); 402 map.put(WebServiceInfoProvider.WS_XML_PROP_NAME, 403 getFormattedFileContents(wsXML)); 404 405 } catch (Exception e) { 406 throw new RepositoryException(e); 407 } 408 409 return map; 410 } 411 412 420 private Map getEjbModuleInfo(ConfigContext ctx, String name) 421 throws RepositoryException { 422 423 if ( (ctx == null) || (name == null) ) { 425 throw new IllegalArgumentException (); 426 } 427 428 Map map = new HashMap (); 429 430 try { 431 map.put(WebServiceInfoProvider.MOD_TYPE_PROP_NAME, 433 WebServiceInfoProvider.MOD_TYPE_EJB); 434 435 map.put(WebServiceInfoProvider.APP_ID_PROP_NAME, name); 437 438 map.put(WebServiceInfoProvider.BUNDLE_NAME_PROP_NAME, null); 440 441 452 String xmlDir = instanceRoot 454 + File.separator + PEFileLayout.GENERATED_DIR 455 + File.separator + PEFileLayout.XML_DIR 456 + File.separator + PEFileLayout.J2EE_MODULES_DIR 457 + File.separator + name; 458 map.put(WebServiceInfoProvider.BUNDLE_ROOT_LOCATION_PROP_NAME, 459 xmlDir); 460 461 String ejbXML = xmlDir + File.separator + META_INF 463 + File.separator + EJB_JAR_XML; 464 map.put(WebServiceInfoProvider. 465 EJB_JAR_XML_PROP_NAME, getFormattedFileContents(ejbXML)); 466 467 String sunEjbXML = xmlDir + File.separator + META_INF 469 + File.separator + SUN_EJB_JAR_XML; 470 map.put(WebServiceInfoProvider.SUN_EJB_JAR_XML_LOCATION_PROP_NAME, 471 sunEjbXML); 472 map.put(WebServiceInfoProvider. 473 SUN_EJB_JAR_XML_PROP_NAME, getFormattedFileContents(sunEjbXML)); 474 475 String wsXML = xmlDir + File.separator + META_INF 477 + File.separator + WEBSERVICES_XML; 478 map.put(WebServiceInfoProvider.WS_XML_LOCATION_PROP_NAME, wsXML); 479 map.put(WebServiceInfoProvider.WS_XML_PROP_NAME, 480 getFormattedFileContents(wsXML)); 481 482 } catch (Exception e) { 483 throw new RepositoryException(e); 484 } 485 486 return map; 487 } 488 489 497 private Map getWebModuleInfo(ConfigContext ctx, String name) 498 throws RepositoryException { 499 500 if ( (ctx == null) || (name == null) ) { 502 throw new IllegalArgumentException (); 503 } 504 505 Map map = new HashMap (); 506 507 try { 508 map.put(WebServiceInfoProvider.MOD_TYPE_PROP_NAME, 510 WebServiceInfoProvider.MOD_TYPE_WEB); 511 512 map.put(WebServiceInfoProvider.APP_ID_PROP_NAME, name); 514 515 map.put(WebServiceInfoProvider.BUNDLE_NAME_PROP_NAME, null); 517 518 529 String xmlDir = instanceRoot 531 + File.separator + PEFileLayout.GENERATED_DIR 532 + File.separator + PEFileLayout.XML_DIR 533 + File.separator + PEFileLayout.J2EE_MODULES_DIR 534 + File.separator + name; 535 map.put(WebServiceInfoProvider.BUNDLE_ROOT_LOCATION_PROP_NAME, 536 xmlDir); 537 538 String webXML = xmlDir + File.separator + WEB_INF 540 + File.separator + WEB_XML; 541 map.put(WebServiceInfoProvider.WEB_XML_PROP_NAME, 542 getFormattedFileContents(webXML)); 543 544 String sunWebXML = xmlDir + File.separator + WEB_INF 546 + File.separator + SUN_WEB_XML; 547 map.put(WebServiceInfoProvider.SUN_WEB_XML_LOCATION_PROP_NAME, 548 sunWebXML); 549 map.put(WebServiceInfoProvider. 550 SUN_WEB_XML_PROP_NAME, getFormattedFileContents(sunWebXML)); 551 552 String wsXML = xmlDir + File.separator + WEB_INF 554 + File.separator + WEBSERVICES_XML; 555 map.put(WebServiceInfoProvider.WS_XML_LOCATION_PROP_NAME, wsXML); 556 map.put(WebServiceInfoProvider.WS_XML_PROP_NAME, 557 getFormattedFileContents(wsXML)); 558 559 } catch (Exception e) { 560 throw new RepositoryException(e); 561 } 562 563 return map; 564 } 565 566 private String getFormattedFileContents(String filePath) { 567 568 String str = null; 569 try { 570 str = FileUtils.getFileContents(filePath); 571 } catch (Exception e) { 572 _logger.log(Level.FINE, "Error reading dd file contents", e); 573 } 574 575 return str; 576 } 577 578 private static final String WEB_INF = "WEB-INF"; 580 private static final String META_INF = "META-INF"; 581 private static final String WEBSERVICES_XML = "webservices.xml"; 582 private static final String WEB_XML = "web.xml"; 583 private static final String SUN_WEB_XML = "sun-web.xml"; 584 private static final String EJB_JAR_XML = "ejb-jar.xml"; 585 private static final String SUN_EJB_JAR_XML = "sun-ejb-jar.xml"; 586 private static final String APPLICATION_XML = "application.xml"; 587 private static final String SUN_DASH = "sun-"; 588 private static String instanceRoot = null; 589 private static Logger _logger = Logger.getLogger(LogDomains.ADMIN_LOGGER); 590 591 592 public static final String PROVIDER_ID = 593 "com.sun.enterprise.admin.wsmgmt.repository.impl.AppServRepositoryProvider"; 594 } 595 | Popular Tags |