1 23 package com.sun.enterprise.admin.wsmgmt; 24 25 import java.util.Set ; 26 import java.util.List ; 27 import java.util.Map ; 28 import java.util.Iterator ; 29 import java.util.HashSet ; 30 import java.util.HashMap ; 31 import java.util.WeakHashMap ; 32 import java.util.Iterator ; 33 import java.util.Map.Entry; 34 import java.util.ArrayList ; 35 import java.io.File ; 36 import java.io.IOException ; 37 import javax.management.ObjectName ; 38 39 import com.sun.appserv.management.ext.wsmgmt.WebServiceEndpointInfo; 40 import com.sun.appserv.management.ext.wsmgmt.WebServiceEndpointInfoImpl; 41 import com.sun.appserv.management.ext.wsmgmt.WebServiceMgr; 42 import com.sun.enterprise.admin.wsmgmt.registry.RegistryAccessObject; 43 import com.sun.enterprise.admin.wsmgmt.registry.RegistryAccessObjectImpl; 44 import com.sun.enterprise.admin.wsmgmt.registry.ConfigHelper; 45 46 import com.sun.enterprise.admin.wsmgmt.repository.spi.RepositoryFactory; 47 import com.sun.enterprise.admin.wsmgmt.repository.spi.RepositoryProvider; 48 import com.sun.enterprise.admin.wsmgmt.repository.spi.WebServiceInfoProvider; 49 50 import com.sun.enterprise.util.io.FileUtils; 51 import com.sun.enterprise.config.ConfigContext; 52 import com.sun.enterprise.config.serverbeans.ApplicationHelper; 53 import com.sun.enterprise.config.serverbeans.J2eeApplication; 54 import com.sun.enterprise.config.serverbeans.WebModule; 55 import com.sun.enterprise.config.serverbeans.EjbModule; 56 import com.sun.enterprise.config.ConfigBean; 57 import com.sun.enterprise.admin.server.core.AdminService; 58 59 import com.sun.appserv.management.base.Util; 60 import com.sun.appserv.management.base.XTypes; 61 import com.sun.appserv.management.j2ee.J2EETypes; 62 import com.sun.appserv.management.base.AMX; 63 import com.sun.appserv.management.util.jmx.JMXUtil; 64 65 import java.util.logging.Logger ; 66 import java.util.logging.Level ; 67 import com.sun.logging.LogDomains; 68 import com.sun.enterprise.util.i18n.StringManager; 69 70 import com.sun.enterprise.deployment.BundleDescriptor; 71 import com.sun.enterprise.deployment.Application; 72 73 import com.sun.enterprise.config.serverbeans.ApplicationHelper; 74 import com.sun.enterprise.config.serverbeans.Applications; 75 import com.sun.enterprise.util.SystemPropertyConstants; 76 import com.sun.enterprise.admin.servermgmt.pe.PEFileLayout; 77 import com.sun.enterprise.config.serverbeans.TransformationRule; 78 import com.sun.enterprise.config.serverbeans.WebServiceEndpoint; 79 import com.sun.enterprise.webservice.monitoring.Endpoint; 80 81 import com.sun.enterprise.server.ApplicationServer; 82 import com.sun.enterprise.instance.AppsManager; 83 import com.sun.enterprise.instance.InstanceEnvironment; 84 import com.sun.enterprise.config.ConfigException; 85 import com.sun.enterprise.deployment.WebBundleDescriptor; 86 import java.util.regex.*; 87 88 93 public class WebServiceMgrBackEnd { 94 97 private WebServiceMgrBackEnd() { 98 try { 99 repPvdr = RepositoryFactory.getRepositoryProvider(); 100 wsInfoPvdr = RepositoryFactory.getWebServiceInfoProvider(); 101 } catch (Exception e) { 102 _logger.fine("WebServiceInfoProvider could not be instantiated: " + 103 e.getMessage()); 104 } 106 wsInfoMap = new WeakHashMap (); 107 try { 108 InstanceEnvironment ienv = 109 ApplicationServer.getServerContext().getInstanceEnvironment(); 110 appsMgr = new AppsManager(ienv); 111 } catch (Exception e) { 112 _logger.fine("AppsManager could not be instantiated: " + 113 e.getMessage()); 114 } 116 } 117 118 public synchronized static WebServiceMgrBackEnd getManager() { 119 if ( mgrImpl == null) { 120 mgrImpl = new WebServiceMgrBackEnd(); 121 } 122 return mgrImpl; 123 } 124 125 132 public Map getWebServicesMap() { 133 Map wsNameMap = new HashMap (); 134 135 Map wsModMap = repPvdr.getWebServiceModules(); 137 if ( wsModMap == null ){ 139 return wsNameMap; 140 } 141 142 Set wsModSet = wsModMap.entrySet(); 145 if ( wsModSet == null) { 146 return wsNameMap; 147 } 148 149 Iterator wsModItr = wsModSet.iterator(); 151 while (wsModItr.hasNext() ) { 152 Map.Entry wsMapEntry = (Map.Entry ) wsModItr.next(); 153 String descLoc = (String ) wsMapEntry.getKey(); 154 Map propMap = (Map ) wsMapEntry.getValue(); 155 List wsInfoListInMod = null; 156 String appName = (String ) 157 propMap.get(WebServiceInfoProvider.APP_ID_PROP_NAME); 158 String bundleName = (String ) 159 propMap.get(WebServiceInfoProvider.BUNDLE_NAME_PROP_NAME); 160 161 Map nMap = getFromCache(appName, bundleName); 162 if (nMap != null) { 163 wsNameMap.putAll(nMap); 164 continue; 165 } 166 167 try { 168 wsInfoListInMod = wsInfoPvdr.getWebServiceInfo(descLoc, 169 propMap); 170 } catch ( Exception e) { 171 String msg =_stringMgr.getString("ModInfoNotFound",appName 173 + " : " + e.getMessage()); 174 _logger.log(Level.WARNING, msg); 175 } 176 177 178 if ( wsInfoListInMod != null ) { 179 Iterator wsInfoItrInMod = wsInfoListInMod.iterator(); 180 181 while (wsInfoItrInMod.hasNext() ) { 182 WebServiceEndpointInfo wsInfo = 183 (WebServiceEndpointInfo) wsInfoItrInMod.next(); 184 185 188 String wsFQN = getFullyQualifiedName(appName, bundleName, 189 wsInfo.isAppStandaloneModule(), wsInfo.getName()); 190 wsNameMap.put(wsFQN, wsInfo.getName()); 191 192 updateCache(wsFQN, wsInfo); 194 } 195 } 196 } 197 return wsNameMap; 198 } 199 200 private synchronized void updateCache( String wsFQN, 201 WebServiceEndpointInfo wsInfo) { 202 wsInfoMap.put(wsFQN, wsInfo); 203 } 204 205 213 public synchronized void removeFromCache(String appName) { 214 215 Iterator itr = wsInfoMap.entrySet().iterator(); 216 217 if (itr == null) { 218 return; 219 } 220 while(itr.hasNext()) { 221 Map.Entry entry = (Map.Entry ) itr.next(); 222 String fqn = (String ) entry.getKey(); 223 WebServiceEndpointInfo wsInfo = 224 (WebServiceEndpointInfo) entry.getValue(); 225 if ( isFQNMatch( fqn, appName) ) { 226 itr.remove(); 227 } 228 } 229 } 230 231 private Map getFromCache(String appName, String bundleName) { 232 Iterator itr = wsInfoMap.entrySet().iterator(); 233 234 Map nMap = null; 235 if (itr == null) { 236 return null; 237 } 238 while(itr.hasNext()) { 239 Map.Entry entry = (Map.Entry ) itr.next(); 240 String fqn = (String ) entry.getKey(); 241 WebServiceEndpointInfo wsInfo = (WebServiceEndpointInfo) entry.getValue(); 242 if ( isFQNMatch( fqn, appName, bundleName) ) { 243 if ( nMap == null) { 244 nMap = new HashMap (); 245 } 246 nMap.put(fqn, wsInfo.getName()); 247 } 248 } 249 return nMap; 250 } 251 252 private boolean isFQNMatch(String fqn, String appName, String bundleName) { 253 String matchFqn; 254 255 if ( bundleName != null) { 256 matchFqn = appName + NAME_SEPERATOR + bundleName + NAME_SEPERATOR; 257 } else { 258 matchFqn = appName + NAME_SEPERATOR ; 259 } 260 261 return ( fqn.startsWith(matchFqn)); 262 } 263 264 private boolean isFQNMatch(String fqn, String appName) { 265 266 String matchFqn = appName + NAME_SEPERATOR ; 267 268 return ( fqn.startsWith(matchFqn)); 269 } 270 271 public String getFullyQualifiedName( String moduleID, String wsName) { 272 return moduleID + NAME_SEPERATOR + wsName; 273 } 274 275 public String getModuleName( String epName) { 276 String [] sStrs = epName.split(NAME_SEPERATOR); 277 if ( sStrs != null) { 278 return sStrs[0]; 279 } else { 280 return null; 281 } 282 } 283 284 public String getEndpointName( String epName) { 285 String [] sStrs = epName.split(NAME_SEPERATOR); 286 if ( sStrs != null) { 287 return sStrs[sStrs.length -1]; 288 } else { 289 return null; 290 } 291 } 292 293 public String getFullyQualifiedName( String appName, String bundleName, 294 boolean isStandAlone, String wsName) { 295 296 if (isStandAlone) { 297 return appName + NAME_SEPERATOR + 298 wsName; 299 } else { 300 return appName + NAME_SEPERATOR + bundleName + NAME_SEPERATOR + 301 wsName; 302 } 303 } 304 305 public String getFullyQualifiedName( String appName, String bundleName, 306 String wsName) { 307 308 if (appName == null) { 309 return bundleName + NAME_SEPERATOR + 310 wsName; 311 } else { 312 return appName + NAME_SEPERATOR + bundleName + NAME_SEPERATOR + 313 wsName; 314 } 315 } 316 317 public String getFullyQualifiedName(Endpoint ep) { 318 319 com.sun.enterprise.deployment.WebServiceEndpoint wse=ep.getDescriptor(); 320 String epName = null; 321 if (wse != null) { 322 epName = wse.getEndpointName(); 323 } 324 BundleDescriptor bundle = wse.getBundleDescriptor(); 325 Application app = bundle.getApplication(); 326 327 String fqn = getFullyQualifiedName( app.getRegistrationName() , 328 bundle.getModuleDescriptor().getArchiveUri(), 329 app.isVirtual(), epName); 330 return fqn; 331 } 332 333 340 public Map getWebServiceInfoMap(String name) { 341 WebServiceEndpointInfo wsInfo = getWebServiceInfo(name); 342 if (wsInfo == null) { 343 return null; 344 } else { 345 return ((WebServiceEndpointInfoImpl)wsInfo).asMap(); 346 } 347 } 348 355 356 public String getEndpointURI(String name) { 357 java.util.Map endpointInfoMap = getWebServiceInfoMap(name); 358 if(endpointInfoMap != null) 359 return (String )endpointInfoMap.get(WebServiceEndpointInfo.END_POINT_URI_KEY); 360 else 361 return null; 362 } 363 364 private WebServiceEndpointInfo getWebServiceInfo(String name) { 365 WebServiceEndpointInfo wsInfo = (WebServiceEndpointInfo) wsInfoMap.get(name); 366 if (wsInfo == null) { 369 getWebServicesMap(); 370 wsInfo = (WebServiceEndpointInfo) wsInfoMap.get(name); 371 } 372 return wsInfo; 373 } 374 375 380 public RegistryAccessObject getRegistryAccessObject() { 381 return new RegistryAccessObjectImpl(); 382 } 383 384 393 public String getWebServiceEndpointObjectNames(Object key, 394 String serverName) { 395 if ((key == null) || !( key instanceof String ) ) { 396 String msg = 397 "Key passed to WebServiceEndpointObjectNames must be of type String"; 398 _logger.log(Level.FINE, msg); 399 return null; 400 } 401 402 WebServiceEndpointInfo wsInfo = getWebServiceInfo( (String )key); 403 if ( wsInfo == null) { 404 return null; 405 } else { 406 String implType = wsInfo.getServiceImplType(); 407 boolean isEjb = false; 408 if ( implType.equals("EJB")) { 409 isEjb = true; 410 } 411 String appName = wsInfo.getAppID(); 412 String modName = wsInfo.getBundleName(); 413 if(wsInfo.isAppStandaloneModule() == true) { 414 modName = appName; 416 appName = null; 418 } 419 return getWSObjectNames(appName, 420 modName, wsInfo.getName(), 421 getWebServiceEndpointContextRoot( (String )key),isEjb, serverName); 422 } 423 } 424 425 private String getWebServiceEndpointContextRoot(String wsFQN) { 426 427 String [] fqns = wsFQN.split(NAME_SEPERATOR); 428 ConfigContext configCtx = AdminService.getAdminService(). 429 getAdminContext().getAdminConfigContext(); 430 ConfigBean cb = null; 431 432 try { 433 cb = ApplicationHelper.findApplication(configCtx, fqns[0]); 434 } catch( Exception e) { 435 String msg = "Could not find a deployed application/module by name " 436 + fqns[0] + " : " + e.getMessage(); 437 _logger.log(Level.FINE, msg); 438 return null; 439 } 440 441 boolean isStandalone = false, isEjb = false; 442 String appId = null, modId = null, epName = null,ctxRoot = null; 443 444 if (cb instanceof J2eeApplication) { 445 assert( fqns.length == 3); 446 return null; 447 } else if (cb instanceof EjbModule) { 448 assert( fqns.length == 2); 449 return null; 450 } else if (cb instanceof WebModule) { 451 assert( fqns.length == 2); 452 return ((WebModule)cb).getContextRoot(); 453 } else { 454 return null; 455 } 456 } 457 458 private String getWSObjectNames(String appId, String modId, 459 String epName, String ctxRoot, boolean isEjb, String serverName) { 460 461 String requiredProps = 462 Util.makeRequiredProps( J2EETypes.WEB_SERVICE, epName ); 463 464 String vsProps = null; 465 if ( !isEjb) { 466 String secPart = ctxRoot; 467 if ( secPart == null) { 468 Application app = null; 469 try { 470 app = appsMgr.getDescriptor(appId); 471 } catch (ConfigException ce) { 472 _logger.fine("The descriptor for application " + appId + 474 " could not be loaded: " + ce.getMessage()); 475 } 476 if (app != null) { 477 WebBundleDescriptor wbd 478 = app.getWebBundleDescriptorByUri(modId); 479 if (wbd != null) { 480 secPart = wbd.getContextRoot(); 481 } 482 } 483 } 484 if (secPart == null) { 485 return null; 488 } 489 if (secPart.charAt(0) != '/') { 490 secPart = "/" + secPart; 491 } 492 String compositeName="//"+ DEFAULT_VIRTUAL_SERVER + secPart; 493 vsProps = Util.makeProp( J2EETypes.WEB_MODULE, compositeName ); 494 } else { 495 vsProps = Util.makeProp( J2EETypes.EJB_MODULE, modId ); 496 } 497 498 requiredProps = Util.concatenateProps(requiredProps, vsProps); 499 500 String serverProp = null; 501 502 if (( serverName != null) && ( !serverName.equals("*"))) { 503 serverProp = Util.makeProp( J2EETypes.J2EE_SERVER, serverName ); 504 } 505 506 String props = serverProp; 507 508 if ( appId == null ) { 509 appId = AMX.NULL_NAME; 510 } 511 final String applicationProp = Util.makeProp( 512 J2EETypes.J2EE_APPLICATION, appId ); 513 514 if ( props != null) { 515 props = Util.concatenateProps( props, applicationProp ); 516 } else { 517 props = applicationProp; 518 } 519 520 String finalProps = Util.concatenateProps(requiredProps, props); 521 522 return finalProps; 523 } 524 525 public String [] listRegistryLocations(){ 526 RegistryAccessObject rao = this.getRegistryAccessObject(); 527 return rao.listRegistryLocations(); 528 } 529 530 public void publishToRegistry(String [] registryLocations, 531 Object webServiceEndpointKey, Map optional){ 532 533 String webServiceName = (String )webServiceEndpointKey; 534 boolean published = false; 535 try{ 536 RegistryAccessObject rao = this.getRegistryAccessObject(); 537 _logger.fine("WebServiceMgrBackEnd.publishToRegistry: publishing" + 538 "WebService "+webServiceName); 539 540 String lbhost = (String )optional.get(WebServiceMgr.LB_HOST_KEY); 541 542 if (lbhost == null){ 543 lbhost = getHostAddress(); 544 _logger.fine("WebServiceMgrBackend.publishToRegistry: Load " + 545 "Balancer Host is unspecified setting to "+ lbhost); 546 } 547 548 String lbport = (String )optional.get(WebServiceMgr.LB_PORT_KEY); 549 String lbsslport = (String )optional.get(WebServiceMgr.LB_SECURE_PORT); 550 551 if (lbport == null && lbsslport == null) { 552 lbport = getPort(webServiceName, true); 553 if (lbport == null) 554 lbport = MINUS_ONE; 555 lbsslport = getPort(webServiceName, false); 556 if (lbsslport == null) 557 lbsslport = MINUS_ONE; 558 _logger.fine("WebServiceMgrBackend.publishToRegistry: Load " + 559 "Balancer Port Unspecified setting to default values " + 560 "LoadBalancer Port = "+ lbport + 561 " LoadBalancer SSL Port = "+lbsslport); 562 } else if (lbsslport == null){ 563 _logger.fine("WebServiceMgrBackend.publishToRegistry: Load " + 564 "Balancer SSL Port is unspecified setting to "+ MINUS_ONE); 565 lbsslport = MINUS_ONE; 566 } else if (lbport == null){ 567 _logger.fine("WebServiceMgrBackend.publishToRegistry: Load " + 568 "Balancer Host is unspecified setting to "+ MINUS_ONE); 569 lbport = MINUS_ONE; 570 } 571 int ilbport = -1; 572 int ilbsslport = -1; 573 try{ 574 ilbport = Integer.valueOf(lbport); 575 } catch (NumberFormatException e){ 576 _logger.fine("WebServiceMgrBackend.publishToRegistry: Load " + 577 "Balancer Port is not a number. Setting to "+ MINUS_ONE); 578 ilbport = -1; 579 } 580 try{ 581 if(lbsslport !=null) 582 ilbsslport = Integer.valueOf(lbsslport); 583 }catch (NumberFormatException e){ 584 _logger.fine("WebServiceMgrBackend.publishToRegistry: Load " + 585 "Balancer SSL Port is not a number. Setting to "+ MINUS_ONE); 586 ilbsslport = -1; 587 } 588 String categoriesList = (String )optional.get(WebServiceMgr.CATEGORIES_KEY); 589 String [] categories = null; 590 if (categoriesList != null){ 591 java.util.StringTokenizer tokenizer = 592 new java.util.StringTokenizer (categoriesList, ","); 593 List <String > list = new ArrayList <String >(); 594 while (tokenizer.hasMoreElements()){ 595 list.add((String )tokenizer.nextToken()); 596 } 597 categories = new String [list.size()]; 598 categories = list.toArray(categories); 599 } 600 String organization = (String ) optional.get(WebServiceMgr.ORGANIZATION_KEY); 601 if (organization == null){ 602 _logger.fine("WebServiceMgrBackend.publishToRegistry: Organization " + 603 " unspecified. Setting a default organization "+ 604 DEFAULT_ORGANIZATION); 605 organization = DEFAULT_ORGANIZATION; 606 } 607 String description = (String ) optional.get(WebServiceMgr.DESCRIPTION_KEY); 608 if (description == null){ 609 _logger.fine("WebServiceMgrBackend.publishToRegistry: Web Service " + 610 " Description unspecified. Setting a default description: "+ 611 DEFAULT_DESCRIPTION); 612 description = DEFAULT_DESCRIPTION; 613 } 614 published = rao.publish(registryLocations, webServiceName, lbhost, 615 ilbport, ilbsslport, categories, organization, description); 616 if (published == false){ 617 String errorMessage = 618 _stringMgr.getString("WebServiceMgrBackend.PublishFailure", 619 webServiceName); 620 _logger.log(Level.SEVERE, "registry.publish_failure", webServiceName); 621 throw new RuntimeException (errorMessage); 622 } else { 623 String message = 624 _stringMgr.getString("WebServiceMgrBackend.PublishSuccess", 625 webServiceName); 626 _logger.log(Level.INFO, message); 627 } 628 } catch (RuntimeException re){ 629 _logger.log(Level.SEVERE, "registry.publish_failure_exception", re); 630 throw re; 631 } catch (Exception e) { 632 _logger.log(Level.SEVERE, "registry.publish_failure", webServiceName); 633 _logger.log(Level.SEVERE, "registry.publish_failure_exception", e); 634 RuntimeException r = new RuntimeException (e); 635 throw r; 636 } 637 638 } 639 643 String getPort(String webServiceName, boolean unsecure) { 644 String port = null; 645 String wsdlFile = 646 (String )((Map )this.getWebServiceInfoMap(webServiceName)).get 647 (WebServiceEndpointInfo.WSDL_FILE_KEY); 648 String http = (unsecure == true)? "http":"https"; 650 String pattern = "soap:address.*location.*"+http+":.*:[0-9][0-9][0-9][0-9]"; 651 Pattern soap_address_pattern = Pattern.compile(pattern); 652 Matcher soap_address_matcher = soap_address_pattern.matcher(wsdlFile); 653 boolean soapAddress = soap_address_matcher.find(); 654 if (soapAddress){ 655 String soap_address = soap_address_matcher.group(); 656 Pattern port_pattern = Pattern.compile("[0-9][0-9][0-9][0-9]"); 657 Matcher port_matcher = port_pattern.matcher(soap_address); 658 port_matcher.find(); 659 port = port_matcher.group(); 660 } else 661 port = null; 662 663 return port; 664 } 665 private String getHostAddress() { 666 try { 667 java.net.InetAddress iaddr = java.net.InetAddress.getLocalHost(); 668 return iaddr.getHostAddress(); 669 } catch (Exception e) { 670 return LOCAL_HOST; 671 } 672 } 673 public void unpublishFromRegistry(String [] registryLocations, 674 Object webServiceEndpointKey){ 675 676 String webServiceName = (String )webServiceEndpointKey; 677 boolean unpublished = false; 678 try{ 679 RegistryAccessObject rao = this.getRegistryAccessObject(); 680 _logger.fine("WebServiceMgrBackEnd.unpublishFromRegistry:" + 681 "unpublishing web service = "+ webServiceName); 682 unpublished = rao.unpublishFromRegistry(registryLocations, webServiceName); 683 if(unpublished == false){ 684 String errorMessage = 685 _stringMgr.getString("WebServiceMgrBackend.UnpublishFailure", 686 webServiceName); 687 688 _logger.log(Level.SEVERE, "registry.unpublish_failure", webServiceName); 689 throw new RuntimeException (errorMessage); 690 } else{ 691 _logger.log(Level.INFO, "registry.unpublish_success", webServiceName); 692 } 693 } catch (RuntimeException re){ 694 _logger.log(Level.SEVERE, "registry.unpublish_failure_exception", re); 695 throw re; 696 }catch (Exception e){ 697 String errorMessage = 698 _stringMgr.getString("WebServiceMgrBackend.UnpublishFailure", 699 webServiceName); 700 701 _logger.log(Level.SEVERE, "registry.unpublish_failure", webServiceName); 702 _logger.log(Level.SEVERE, "registry.unpublish_failure_exception",e); 703 throw new RuntimeException (e); 704 } 705 } 706 714 public void removeRegistryConnectionResources(String jndiNameOfRegistry) { 715 ConfigHelper configHelper = ConfigHelper.getInstanceToDeleteRegistryResources(); 716 configHelper.removeRegistryConnectionResources(jndiNameOfRegistry); 717 return; 718 } 719 720 743 public void addRegistryConnectionResources(String jndiName, 744 String description, String type, Map <String , String > properties){ 745 ConfigHelper configHelper = ConfigHelper.getInstanceToDeleteRegistryResources(); 746 configHelper.addRegistryConnectionResources(jndiName, description, type, 747 properties); 748 } 749 750 751 760 public void removeFileFromRepository(String appId,String epName, String 761 ruleName) { 762 763 if (( appId == null) || ( epName == null) || (ruleName == null)) { 764 String msg = "Either appId or epName or ruleName passed is null " 765 + appId; 766 _logger.log(Level.FINE, msg); 767 throw new IllegalArgumentException (); 768 } 769 770 ConfigContext configCtx = AdminService.getAdminService(). 771 getAdminContext().getAdminConfigContext(); 772 773 TransformationRule tRule = null; 774 try { 775 tRule = ApplicationHelper.findTransformationRule(configCtx, 776 appId,epName, ruleName); 777 } catch( Exception e) { 778 String msg = "Could not find a deployed application/module type " 779 + appId; 780 _logger.log(Level.FINE, msg); 781 throw new RuntimeException (e); 782 } 783 784 File ruleFile = new File (tRule.getRuleFileLocation()); 785 FileUtils.liquidate(ruleFile); 786 } 787 788 798 public String moveFileToRepository(String curLocation, String appId) 799 throws IOException { 800 801 if (( curLocation == null) || ( appId == null)) { 802 String msg = "Either rule location or appId passed is null " 803 + appId; 804 _logger.log(Level.FINE, msg); 805 throw new IllegalArgumentException (); 806 } 807 808 String appType = null; 809 ConfigContext configCtx = AdminService.getAdminService(). 810 getAdminContext().getAdminConfigContext(); 811 812 try { 813 appType = ApplicationHelper.getApplicationType(configCtx, appId); 814 } catch( Exception e) { 815 String msg = "Could not find a deployed application/module type " 816 + appId; 817 _logger.log(Level.FINE, msg); 818 throw new RuntimeException (e); 819 } 820 821 String rootDir = System.getProperty( 822 SystemPropertyConstants.INSTANCE_ROOT_PROPERTY); 823 String finalLoc = null; 824 825 File fin = new File (curLocation); 826 if ( appType.equals(Applications.J2EE_APPLICATION) ) { 827 finalLoc = rootDir + File.separator + PEFileLayout.GENERATED_DIR + 828 File.separator + PEFileLayout.XML_DIR + File.separator + 829 PEFileLayout.J2EE_APPS_DIR + 830 File.separator + appId + File.separator ; 831 } else if (( appType.equals(Applications.EJB_MODULE)) || 832 ( appType.equals(Applications.WEB_MODULE) )) { 833 finalLoc = rootDir + File.separator + PEFileLayout.GENERATED_DIR + 834 File.separator + PEFileLayout.XML_DIR + File.separator + 835 PEFileLayout.J2EE_MODULES_DIR + 836 File.separator + appId + File.separator; 837 } 838 839 840 File fout = new File (finalLoc + fin.getName()); 841 842 int fileIdx = 0; 844 while ( fout.exists() ) { 845 fout = new File ( finalLoc + fileIdx + fin.getName()); 846 fileIdx++; 847 } 848 849 FileUtils.copy(fin, fout); 850 FileUtils.liquidate(fin); 851 852 return finalLoc + fin.getName(); 853 } 854 855 public List getTransformationRuleConfigObjectNameList( 856 String appId, String wsepName,Map <String ,ObjectName > oNameMap) { 857 858 if (oNameMap == null) { 859 return null; 860 } 861 862 ArrayList retList = new ArrayList (oNameMap.size()); 863 ConfigContext configCtx = AdminService.getAdminService(). 864 getAdminContext().getAdminConfigContext(); 865 ConfigBean cb = null; 866 867 try { 868 cb = ApplicationHelper.findApplication(configCtx, appId); 869 } catch( Exception e) { 870 String msg = "Could not find a deployed application/module by name " 871 + appId; 872 _logger.log(Level.FINE, msg); 873 return null; 874 } 875 876 TransformationRule[] tRules = null; 877 WebServiceEndpoint wsep = null; 878 if (cb instanceof J2eeApplication) { 879 wsep = ((J2eeApplication)cb).getWebServiceEndpointByName(wsepName); 880 } else if (cb instanceof EjbModule) { 881 wsep = ((EjbModule)cb).getWebServiceEndpointByName(wsepName); 882 } else if (cb instanceof WebModule) { 883 wsep = ((WebModule)cb).getWebServiceEndpointByName(wsepName); 884 } else { 885 return null; 886 } 887 if (wsep != null) { 888 tRules = wsep.getTransformationRule(); 889 } 890 for(int index=0; index < tRules.length; index++) { 891 retList.add(oNameMap.get(tRules[index].getName())); 892 } 893 return retList; 894 } 895 896 897 898 902 public static final String DEFAULT_VIRTUAL_SERVER = "server"; 903 904 905 906 private AppsManager appsMgr = null; 907 private RepositoryProvider repPvdr; 908 private WebServiceInfoProvider wsInfoPvdr; 909 private WeakHashMap wsInfoMap; 910 private final static String NAME_SEPERATOR = "#"; 911 private static WebServiceMgrBackEnd mgrImpl = null; 912 913 private static final Logger _logger = 914 Logger.getLogger(LogDomains.ADMIN_LOGGER); 915 916 private static final StringManager _stringMgr = 917 StringManager.getManager(WebServiceMgrBackEnd.class); 918 919 private static final String LOCAL_HOST = "localhost"; 920 private static final String MINUS_ONE = "-1"; 921 private static final String DEFAULT_ORGANIZATION = "Sun Microsystems Inc"; 922 private static final String DEFAULT_DESCRIPTION = "Sun Java Application Server Web Service Default Description"; 923 private static final String DEFAULT_PORT = "8080"; 924 } 925 | Popular Tags |