KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > wsmgmt > WebServiceMgrBackEnd


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.admin.wsmgmt;
24
25 import java.util.Set JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.HashSet JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.WeakHashMap JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.Map.Entry;
34 import java.util.ArrayList JavaDoc;
35 import java.io.File JavaDoc;
36 import java.io.IOException JavaDoc;
37 import javax.management.ObjectName JavaDoc;
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 JavaDoc;
66 import java.util.logging.Level JavaDoc;
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 /**
89  * Manager MBean for web services. This enumerates the list of the web services
90  * deployed in the domain. For each web service, detailed information can be
91  * obtained.
92  */

93 public class WebServiceMgrBackEnd {
94     /**
95      * Default constructor for WebServiceMgrBackEnd
96      */

97     private WebServiceMgrBackEnd() {
98         try {
99             repPvdr = RepositoryFactory.getRepositoryProvider();
100             wsInfoPvdr = RepositoryFactory.getWebServiceInfoProvider();
101         } catch (Exception JavaDoc e) {
102             _logger.fine("WebServiceInfoProvider could not be instantiated: " +
103                     e.getMessage());
104             // log warning
105
}
106         wsInfoMap = new WeakHashMap JavaDoc();
107         try {
108             InstanceEnvironment ienv =
109                     ApplicationServer.getServerContext().getInstanceEnvironment();
110             appsMgr = new AppsManager(ienv);
111         } catch (Exception JavaDoc e) {
112             _logger.fine("AppsManager could not be instantiated: " +
113                     e.getMessage());
114             // log exception in FINE level. This excpetion should never occur.
115
}
116     }
117     
118     public synchronized static WebServiceMgrBackEnd getManager() {
119         if ( mgrImpl == null) {
120             mgrImpl = new WebServiceMgrBackEnd();
121         }
122         return mgrImpl;
123     }
124     
125     /**
126      * Returns a Map containing web services and the fully qualified name for
127      * each web service. This fully qualified name must be used to get more
128      * details about this web service.
129      *
130      * @return Map of web service name and its fully qualified name
131      */

132     public Map JavaDoc getWebServicesMap() {
133         Map JavaDoc wsNameMap = new HashMap JavaDoc();
134         
135         // Getting all the modules containing web service end points
136
Map JavaDoc wsModMap = repPvdr.getWebServiceModules();
137         // no modules found, return empty map
138
if ( wsModMap == null ){
139             return wsNameMap;
140         }
141         
142         // If underlying Set can not be retrieved return
143
// return empty map
144
Set JavaDoc wsModSet = wsModMap.entrySet();
145         if ( wsModSet == null) {
146             return wsNameMap;
147         }
148         
149         // iterate through each module and add web services to the map
150
Iterator JavaDoc wsModItr = wsModSet.iterator();
151         while (wsModItr.hasNext() ) {
152             Map.Entry JavaDoc wsMapEntry = (Map.Entry JavaDoc) wsModItr.next();
153             String JavaDoc descLoc = (String JavaDoc) wsMapEntry.getKey();
154             Map JavaDoc propMap = (Map JavaDoc) wsMapEntry.getValue();
155             List JavaDoc wsInfoListInMod = null;
156             String JavaDoc appName = (String JavaDoc)
157             propMap.get(WebServiceInfoProvider.APP_ID_PROP_NAME);
158             String JavaDoc bundleName = (String JavaDoc)
159             propMap.get(WebServiceInfoProvider.BUNDLE_NAME_PROP_NAME);
160             
161             Map JavaDoc 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 JavaDoc e) {
171                 // log warnin
172
String JavaDoc msg =_stringMgr.getString("ModInfoNotFound",appName
173                         + " : " + e.getMessage());
174                 _logger.log(Level.WARNING, msg);
175             }
176             
177             
178             if ( wsInfoListInMod != null ) {
179                 Iterator JavaDoc wsInfoItrInMod = wsInfoListInMod.iterator();
180                 
181                 while (wsInfoItrInMod.hasNext() ) {
182                     WebServiceEndpointInfo wsInfo =
183                             (WebServiceEndpointInfo) wsInfoItrInMod.next();
184                     
185                     // add this web service name and its fully qualified name
186
// the map that is being returned
187

188                     String JavaDoc wsFQN = getFullyQualifiedName(appName, bundleName,
189                             wsInfo.isAppStandaloneModule(), wsInfo.getName());
190                     wsNameMap.put(wsFQN, wsInfo.getName());
191                     
192                     // update the internal weak hashmap
193
updateCache(wsFQN, wsInfo);
194                 }
195             }
196         }
197         return wsNameMap;
198     }
199     
200     private synchronized void updateCache( String JavaDoc wsFQN,
201             WebServiceEndpointInfo wsInfo) {
202         wsInfoMap.put(wsFQN, wsInfo);
203     }
204     
205     /**
206      * Removes the web service end point informationt that is cached by the
207      * Web Services Management module. This should be only used during
208      * un-deploy. The only expeced user of this method is AppServDELImpl java
209      * class.
210      *
211      * @param appName application this being un-deployed
212      */

213     public synchronized void removeFromCache(String JavaDoc appName) {
214         
215         Iterator JavaDoc itr = wsInfoMap.entrySet().iterator();
216         
217         if (itr == null) {
218             return;
219         }
220         while(itr.hasNext()) {
221             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) itr.next();
222             String JavaDoc fqn = (String JavaDoc) entry.getKey();
223             WebServiceEndpointInfo wsInfo =
224                     (WebServiceEndpointInfo) entry.getValue();
225             if ( isFQNMatch( fqn, appName) ) {
226                 itr.remove();
227             }
228         }
229     }
230     
231     private Map JavaDoc getFromCache(String JavaDoc appName, String JavaDoc bundleName) {
232         Iterator JavaDoc itr = wsInfoMap.entrySet().iterator();
233         
234         Map JavaDoc nMap = null;
235         if (itr == null) {
236             return null;
237         }
238         while(itr.hasNext()) {
239             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) itr.next();
240             String JavaDoc fqn = (String JavaDoc) entry.getKey();
241             WebServiceEndpointInfo wsInfo = (WebServiceEndpointInfo) entry.getValue();
242             if ( isFQNMatch( fqn, appName, bundleName) ) {
243                 if ( nMap == null) {
244                     nMap = new HashMap JavaDoc();
245                 }
246                 nMap.put(fqn, wsInfo.getName());
247             }
248         }
249         return nMap;
250     }
251     
252     private boolean isFQNMatch(String JavaDoc fqn, String JavaDoc appName, String JavaDoc bundleName) {
253         String JavaDoc 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 JavaDoc fqn, String JavaDoc appName) {
265         
266         String JavaDoc matchFqn = appName + NAME_SEPERATOR ;
267         
268         return ( fqn.startsWith(matchFqn));
269     }
270     
271     public String JavaDoc getFullyQualifiedName( String JavaDoc moduleID, String JavaDoc wsName) {
272         return moduleID + NAME_SEPERATOR + wsName;
273     }
274     
275     public String JavaDoc getModuleName( String JavaDoc epName) {
276         String JavaDoc[] sStrs = epName.split(NAME_SEPERATOR);
277         if ( sStrs != null) {
278             return sStrs[0];
279         } else {
280             return null;
281         }
282     }
283     
284     public String JavaDoc getEndpointName( String JavaDoc epName) {
285         String JavaDoc[] 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 JavaDoc getFullyQualifiedName( String JavaDoc appName, String JavaDoc bundleName,
294             boolean isStandAlone, String JavaDoc 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 JavaDoc getFullyQualifiedName( String JavaDoc appName, String JavaDoc bundleName,
306             String JavaDoc 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 JavaDoc getFullyQualifiedName(Endpoint ep) {
318         
319         com.sun.enterprise.deployment.WebServiceEndpoint wse=ep.getDescriptor();
320         String JavaDoc epName = null;
321         if (wse != null) {
322             epName = wse.getEndpointName();
323         }
324         BundleDescriptor bundle = wse.getBundleDescriptor();
325         Application app = bundle.getApplication();
326         
327         String JavaDoc fqn = getFullyQualifiedName( app.getRegistrationName() ,
328                 bundle.getModuleDescriptor().getArchiveUri(),
329                 app.isVirtual(), epName);
330         return fqn;
331     }
332     
333     /**
334      * Return WebServiceEndpointInfo for a web service.
335      *
336      * @param name Fully qualified name of the web service
337      *
338      * @return WebServiceEndpointInfo for a web service
339      */

340     public Map JavaDoc getWebServiceInfoMap(String JavaDoc name) {
341         WebServiceEndpointInfo wsInfo = getWebServiceInfo(name);
342         if (wsInfo == null) {
343             return null;
344         } else {
345             return ((WebServiceEndpointInfoImpl)wsInfo).asMap();
346         }
347     }
348     /**
349      * Return WebServiceEndpointInfo for a web service.
350      *
351      * @param name Fully qualified name of the web service
352      *
353      * @return EndpointURI for a endpoint
354      */

355     
356     public String JavaDoc getEndpointURI(String JavaDoc name) {
357         java.util.Map JavaDoc endpointInfoMap = getWebServiceInfoMap(name);
358         if(endpointInfoMap != null)
359             return (String JavaDoc)endpointInfoMap.get(WebServiceEndpointInfo.END_POINT_URI_KEY);
360         else
361             return null;
362     }
363     
364     private WebServiceEndpointInfo getWebServiceInfo(String JavaDoc name) {
365         WebServiceEndpointInfo wsInfo = (WebServiceEndpointInfo) wsInfoMap.get(name);
366         // call expired, load its descriptors
367
// XXX this should be optimized
368
if (wsInfo == null) {
369             getWebServicesMap();
370             wsInfo = (WebServiceEndpointInfo) wsInfoMap.get(name);
371         }
372         return wsInfo;
373     }
374     
375     /**
376      * Returns RegistryAccessObject; RegistryAccessObject encapsulates access
377      * to the underlying registries
378      * @return RegistryAccessObject
379      */

380     public RegistryAccessObject getRegistryAccessObject() {
381         return new RegistryAccessObjectImpl();
382     }
383     
384     /**
385      * Returns the object names of the mbeans matching the criteria specified
386      * for WebServiceEndpoint MBeans.
387      *
388      * @param endpointKey Fully qualified key for web service endpoint
389      * @param serverName Name of the server instance
390      *
391      * @return Properties of WebServiceEndpoint MBean object names.
392      */

393     public String JavaDoc getWebServiceEndpointObjectNames(Object JavaDoc key,
394             String JavaDoc serverName) {
395         if ((key == null) || !( key instanceof String JavaDoc) ) {
396             String JavaDoc 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 JavaDoc)key);
403         if ( wsInfo == null) {
404             return null;
405         } else {
406             String JavaDoc implType = wsInfo.getServiceImplType();
407             boolean isEjb = false;
408             if ( implType.equals("EJB")) {
409                 isEjb = true;
410             }
411             String JavaDoc appName = wsInfo.getAppID();
412             String JavaDoc modName = wsInfo.getBundleName();
413             if(wsInfo.isAppStandaloneModule() == true) {
414                 // appId is the module name
415
modName = appName;
416                 // J2EE application name is null for stand alone modules
417
appName = null;
418             }
419             return getWSObjectNames(appName,
420                     modName, wsInfo.getName(),
421                     getWebServiceEndpointContextRoot( (String JavaDoc)key),isEjb, serverName);
422         }
423     }
424     
425     private String JavaDoc getWebServiceEndpointContextRoot(String JavaDoc wsFQN) {
426         
427         String JavaDoc[] 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 JavaDoc e) {
435             String JavaDoc 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 JavaDoc 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 JavaDoc getWSObjectNames(String JavaDoc appId, String JavaDoc modId,
459             String JavaDoc epName, String JavaDoc ctxRoot, boolean isEjb, String JavaDoc serverName) {
460         
461         String JavaDoc requiredProps =
462                 Util.makeRequiredProps( J2EETypes.WEB_SERVICE, epName );
463         
464         String JavaDoc vsProps = null;
465         if ( !isEjb) {
466             String JavaDoc secPart = ctxRoot;
467             if ( secPart == null) {
468                 Application app = null;
469                 try {
470                     app = appsMgr.getDescriptor(appId);
471                 } catch (ConfigException ce) {
472                     // log a warning
473
_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                 // not getting the context root from the descriptor
486
// Descriptor must not be loaded
487
return null;
488             }
489             if (secPart.charAt(0) != '/') {
490                 secPart = "/" + secPart;
491             }
492             String JavaDoc 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 JavaDoc serverProp = null;
501         
502         if (( serverName != null) && ( !serverName.equals("*"))) {
503             serverProp = Util.makeProp( J2EETypes.J2EE_SERVER, serverName );
504         }
505         
506         String JavaDoc props = serverProp;
507         
508         if ( appId == null ) {
509             appId = AMX.NULL_NAME;
510         }
511         final String JavaDoc 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 JavaDoc finalProps = Util.concatenateProps(requiredProps, props);
521         
522         return finalProps;
523     }
524     
525     public String JavaDoc[] listRegistryLocations(){
526         RegistryAccessObject rao = this.getRegistryAccessObject();
527         return rao.listRegistryLocations();
528     }
529     
530     public void publishToRegistry(String JavaDoc[] registryLocations,
531             Object JavaDoc webServiceEndpointKey, Map JavaDoc optional){
532         
533         String JavaDoc webServiceName = (String JavaDoc)webServiceEndpointKey;
534         boolean published = false;
535         try{
536             RegistryAccessObject rao = this.getRegistryAccessObject();
537             _logger.fine("WebServiceMgrBackEnd.publishToRegistry: publishing" +
538                     "WebService "+webServiceName);
539             
540             String JavaDoc lbhost = (String JavaDoc)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 JavaDoc lbport = (String JavaDoc)optional.get(WebServiceMgr.LB_PORT_KEY);
549             String JavaDoc lbsslport = (String JavaDoc)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 JavaDoc 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 JavaDoc 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 JavaDoc categoriesList = (String JavaDoc)optional.get(WebServiceMgr.CATEGORIES_KEY);
589             String JavaDoc[] categories = null;
590             if (categoriesList != null){
591                 java.util.StringTokenizer JavaDoc tokenizer =
592                         new java.util.StringTokenizer JavaDoc(categoriesList, ",");
593                 List JavaDoc<String JavaDoc> list = new ArrayList JavaDoc<String JavaDoc>();
594                 while (tokenizer.hasMoreElements()){
595                     list.add((String JavaDoc)tokenizer.nextToken());
596                 }
597                 categories = new String JavaDoc[list.size()];
598                 categories = list.toArray(categories);
599             }
600             String JavaDoc organization = (String JavaDoc) 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 JavaDoc description = (String JavaDoc) 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 JavaDoc errorMessage =
618                         _stringMgr.getString("WebServiceMgrBackend.PublishFailure",
619                         webServiceName);
620                 _logger.log(Level.SEVERE, "registry.publish_failure", webServiceName);
621                 throw new RuntimeException JavaDoc(errorMessage);
622             } else {
623                 String JavaDoc message =
624                         _stringMgr.getString("WebServiceMgrBackend.PublishSuccess",
625                         webServiceName);
626                 _logger.log(Level.INFO, message);
627             }
628         } catch (RuntimeException JavaDoc re){
629             _logger.log(Level.SEVERE, "registry.publish_failure_exception", re);
630             throw re;
631         } catch (Exception JavaDoc e) {
632             _logger.log(Level.SEVERE, "registry.publish_failure", webServiceName);
633             _logger.log(Level.SEVERE, "registry.publish_failure_exception", e);
634             RuntimeException JavaDoc r = new RuntimeException JavaDoc(e);
635             throw r;
636         }
637         
638     }
639     /*
640      * boolean unsecure if true, will search for http address in the webservice
641      * else will search for https in the webservice
642      */

643     String JavaDoc getPort(String JavaDoc webServiceName, boolean unsecure) {
644         String JavaDoc port = null;
645         String JavaDoc wsdlFile =
646                 (String JavaDoc)((Map JavaDoc)this.getWebServiceInfoMap(webServiceName)).get
647                 (WebServiceEndpointInfo.WSDL_FILE_KEY);
648         // Extract web service port from the WSDL file.
649
String JavaDoc http = (unsecure == true)? "http":"https";
650         String JavaDoc 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 JavaDoc 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 JavaDoc getHostAddress() {
666         try {
667             java.net.InetAddress JavaDoc iaddr = java.net.InetAddress.getLocalHost();
668             return iaddr.getHostAddress();
669         } catch (Exception JavaDoc e) {
670             return LOCAL_HOST;
671         }
672     }
673     public void unpublishFromRegistry(String JavaDoc[] registryLocations,
674             Object JavaDoc webServiceEndpointKey){
675         
676         String JavaDoc webServiceName = (String JavaDoc)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 JavaDoc errorMessage =
685                         _stringMgr.getString("WebServiceMgrBackend.UnpublishFailure",
686                         webServiceName);
687                 
688                 _logger.log(Level.SEVERE, "registry.unpublish_failure", webServiceName);
689                 throw new RuntimeException JavaDoc(errorMessage);
690             } else{
691                 _logger.log(Level.INFO, "registry.unpublish_success", webServiceName);
692             }
693         } catch (RuntimeException JavaDoc re){
694             _logger.log(Level.SEVERE, "registry.unpublish_failure_exception", re);
695             throw re;
696         }catch (Exception JavaDoc e){
697             String JavaDoc 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 JavaDoc(e);
704         }
705     }
706     /**
707      * Removes the registry specific resources from the domain.
708      * Peeks at the connector-resource element to obtain the
709      * connector-connection-pool name. Using this pool name, removes the
710      * connector-connection-pool, proceeds further to remove the
711      * connector-resource
712      * @param jndiNameOfRegistry whose resources are to be removed from the domain
713      */

714     public void removeRegistryConnectionResources(String JavaDoc jndiNameOfRegistry) {
715         ConfigHelper configHelper = ConfigHelper.getInstanceToDeleteRegistryResources();
716         configHelper.removeRegistryConnectionResources(jndiNameOfRegistry);
717         return;
718     }
719     
720     /**
721      * Adds registry specific resources to the domain.
722      * Adds a connector connection pool and then proceeds to add a connector
723      * resource
724      *
725      * @param jndiName of the connector-resource that points to the registry
726      *
727      * @param description of the connector-resource and the connector-connection
728      * -pool name
729      *
730      * @param type of the registry
731      * {@link com.sun.appserv.management.WebServiceMgr#UDDI_KEY}
732      * {@link com.sun.appserv.management.WebServiceMgr#EBXML_KEY}
733      *
734      * @param properties a map of key, value pair that encapsulate the properties
735      * of the connection pool that connects to the registry. Properties are
736      *
737      * {@link com.sun.appserv.management.WebServiceMgr#PUBLISH_URL_KEY}
738      * {@link com.sun.appserv.management.WebServiceMgr#QUERY_URL_KEY}
739      * {@link com.sun.appserv.management.WebServiceMgr#USERNAME_KEY}
740      * {@link com.sun.appserv.management.WebServiceMgr#PASSWORD_KEY}
741      *
742      */

743     public void addRegistryConnectionResources(String JavaDoc jndiName,
744             String JavaDoc description, String JavaDoc type, Map JavaDoc<String JavaDoc, String JavaDoc> properties){
745         ConfigHelper configHelper = ConfigHelper.getInstanceToDeleteRegistryResources();
746         configHelper.addRegistryConnectionResources(jndiName, description, type,
747                 properties);
748     }
749     
750     
751     /**
752      * This method removes the transformation rule file from the repository
753      * directory.
754      *
755      * @param appId application or module Id
756      * @param epName End point's name
757      * @param ruleName Transformation rule's name
758      *
759      */

760     public void removeFileFromRepository(String JavaDoc appId,String JavaDoc epName, String JavaDoc
761             ruleName) {
762         
763         if (( appId == null) || ( epName == null) || (ruleName == null)) {
764             String JavaDoc msg = "Either appId or epName or ruleName passed is null "
765                     + appId;
766             _logger.log(Level.FINE, msg);
767             throw new IllegalArgumentException JavaDoc();
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 JavaDoc e) {
778             String JavaDoc msg = "Could not find a deployed application/module type "
779                     + appId;
780             _logger.log(Level.FINE, msg);
781             throw new RuntimeException JavaDoc(e);
782         }
783         
784         File JavaDoc ruleFile = new File JavaDoc(tRule.getRuleFileLocation());
785         FileUtils.liquidate(ruleFile);
786     }
787     
788     /**
789      * This method moves the transformation rule file from the curLocation
790      * (in some temp dir location) to generated/xml/<appormod>/<app_or_mod_name
791      * directory.
792      *
793      * @param curLocation current temp location of rule file
794      * @param appId application or module Id
795      *
796      * @return the new location of the rule file.
797      */

798     public String JavaDoc moveFileToRepository(String JavaDoc curLocation, String JavaDoc appId)
799     throws IOException JavaDoc {
800         
801         if (( curLocation == null) || ( appId == null)) {
802             String JavaDoc msg = "Either rule location or appId passed is null "
803                     + appId;
804             _logger.log(Level.FINE, msg);
805             throw new IllegalArgumentException JavaDoc();
806         }
807         
808         String JavaDoc appType = null;
809         ConfigContext configCtx = AdminService.getAdminService().
810                 getAdminContext().getAdminConfigContext();
811         
812         try {
813             appType = ApplicationHelper.getApplicationType(configCtx, appId);
814         } catch( Exception JavaDoc e) {
815             String JavaDoc msg = "Could not find a deployed application/module type "
816                     + appId;
817             _logger.log(Level.FINE, msg);
818             throw new RuntimeException JavaDoc(e);
819         }
820         
821         String JavaDoc rootDir = System.getProperty(
822                 SystemPropertyConstants.INSTANCE_ROOT_PROPERTY);
823         String JavaDoc finalLoc = null;
824         
825         File JavaDoc fin = new File JavaDoc(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 JavaDoc fout = new File JavaDoc(finalLoc + fin.getName());
841         
842         // check if the named file already exists, then choose a different name
843
int fileIdx = 0;
844         while ( fout.exists() ) {
845             fout = new File JavaDoc( 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 JavaDoc getTransformationRuleConfigObjectNameList(
856             String JavaDoc appId, String JavaDoc wsepName,Map JavaDoc<String JavaDoc,ObjectName JavaDoc> oNameMap) {
857         
858         if (oNameMap == null) {
859             return null;
860         }
861         
862         ArrayList JavaDoc retList = new ArrayList JavaDoc(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 JavaDoc e) {
870             String JavaDoc 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     /** PUBLIC VARIABLES */
897     
898     /**
899      * Default virtual server, under which all the web service monitoring stats
900      * are maintained
901      **/

902     public static final String JavaDoc DEFAULT_VIRTUAL_SERVER = "server";
903     
904     /** PRIVATE VARIABLES */
905     
906     private AppsManager appsMgr = null;
907     private RepositoryProvider repPvdr;
908     private WebServiceInfoProvider wsInfoPvdr;
909     private WeakHashMap JavaDoc wsInfoMap;
910     private final static String JavaDoc NAME_SEPERATOR = "#";
911     private static WebServiceMgrBackEnd mgrImpl = null;
912     
913     private static final Logger JavaDoc _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 JavaDoc LOCAL_HOST = "localhost";
920     private static final String JavaDoc MINUS_ONE = "-1";
921     private static final String JavaDoc DEFAULT_ORGANIZATION = "Sun Microsystems Inc";
922     private static final String JavaDoc DEFAULT_DESCRIPTION = "Sun Java Application Server Web Service Default Description";
923     private static final String JavaDoc DEFAULT_PORT = "8080";
924 }
925
Popular Tags