KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > wsmgmt > registry > ConfigHelper


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
24 /*
25  * ConfigHelper.java
26  * @author Harpreet Singh
27  * Created on June 9, 2005, 11:04 AM
28  */

29
30 package com.sun.enterprise.admin.wsmgmt.registry;
31
32 import java.util.Enumeration JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.Map JavaDoc;
35 import java.util.List JavaDoc;
36 import java.util.ArrayList JavaDoc;
37 import java.util.HashMap JavaDoc;
38 import java.util.Properties JavaDoc;
39 import java.util.logging.Logger JavaDoc;
40 import java.util.logging.Level JavaDoc;
41 import javax.management.Attribute JavaDoc;
42 import javax.management.AttributeList JavaDoc;
43 import javax.management.InstanceNotFoundException JavaDoc;
44 import javax.management.MBeanException JavaDoc;
45 import javax.management.MBeanServer JavaDoc;
46
47 import com.sun.logging.LogDomains;
48 import com.sun.appserv.management.ext.wsmgmt.WebServiceMgr;
49 import com.sun.appserv.management.ext.wsmgmt.WebServiceEndpointInfo;
50 import com.sun.enterprise.util.io.FileUtils;
51 import com.sun.appserv.management.client.ProxyFactory;
52 import com.sun.appserv.management.config.DomainConfig;
53 import com.sun.appserv.management.DomainRoot;
54 import com.sun.enterprise.admin.common.MBeanServerFactory;
55 import com.sun.appserv.management.config.PropertiesAccess;
56 import com.sun.appserv.management.config.WebServiceEndpointConfig;
57 import com.sun.appserv.management.config.J2EEApplicationConfig;
58 import com.sun.appserv.management.config.EJBModuleConfig;
59 import com.sun.appserv.management.config.WebModuleConfig;
60 import com.sun.appserv.management.config.ConnectorResourceConfig;
61 import com.sun.appserv.management.config.ConnectorConnectionPoolConfig;
62 import com.sun.appserv.management.config.ResourceAdapterConfig;
63 import com.sun.appserv.management.config.ResourceRefConfig;
64 import com.sun.appserv.management.config.StandaloneServerConfig;
65 import com.sun.appserv.management.config.RegistryLocationConfig;
66 import javax.management.MalformedObjectNameException JavaDoc;
67 import javax.management.ObjectName JavaDoc;
68 import javax.management.ReflectionException JavaDoc;
69
70 /**
71  * Utility Class to update the domain xml
72  * @todo convert log messages from fine to appropriate levels
73  * @author Harpreet Singh
74  */

75 public class ConfigHelper {
76     
77     private static final Logger JavaDoc _logger =
78             Logger.getLogger(LogDomains.ADMIN_LOGGER);
79     
80     // Added as a suffix to the connector-resource jndiname to generate a pool name
81
// e.g. if a connector resource jndi name is eis/foo, the generated pool name
82
// will be eis_foo__pool
83
private static final String JavaDoc POOL_SUFFIX = "__pool";
84     private static final String JavaDoc DEFAULT_JAXR_RAR = "jaxr-ra";
85     private static final String JavaDoc ignore_ra = "jmsra";
86     /**
87      * Property to be set by Resource Adapter to signify it is a UDDI specific Resource Adapter
88      */

89     public static final String JavaDoc UDDI_PROPERTY = "com.sun.appserv.registry.uddi";
90     /**
91      * Property to be set by Resource Adapter to signify it is a EBXML specific Resource Adapter
92      */

93     public static final String JavaDoc EBXML_PROPERTY = "com.sun.appserv.registry.ebxml";
94     
95     // properties that a appserver specific rar may have.
96
public static final String JavaDoc APPSERVER_UDDI = "AppserverUDDI";
97     
98     public static final String JavaDoc APPSERVER_EBXML = "AppserverEBXML";
99     
100     /**
101      * A RegistryLocation is determined by the type of its connector connection
102      * definition.
103      * The connector-connection-definition-name is of the type
104      * <pre>
105      * javax.xml.registry.ConnectionFactory
106      * </pre>
107      * to be qualified as a valid RegistryLocation
108      */

109     public static final String JavaDoc JAXR_REGISTRY_TYPE =
110             "javax.xml.registry.ConnectionFactory";
111     
112     private static final String JavaDoc UDDI_JAXR_REGISTRY_TYPE
113             = "com.sun.connector.jaxr.JaxrConnectionFactory";
114     
115     private static final String JavaDoc LifeCycleManagerURL = "LifeCycleManagerURL";
116     private static final String JavaDoc QueryManagerURL = "QueryManagerURL";
117     private Map JavaDoc webServiceInfoMap = null;
118     /*
119      * Creates a new instance of ConfigHelper.
120      * This is used to create instances that update the domain.xml
121      */

122     private ConfigHelper(Map JavaDoc webServiceInfo) {
123         this.webServiceInfoMap = webServiceInfo;
124     }
125     
126     /**
127      * Creates a instance of ConfigHelper that is used to query domain.xml for
128      * RegistryLocations
129      */

130     private ConfigHelper(){
131     }
132     
133     
134     /**
135      * Creates an Instance of ConfigHelper that is used to update the domain.xml
136      * @param Map a map representation of WebServiceInfo object
137      * @return ConfigHelper
138      */

139     public static ConfigHelper getInstanceToUpdateConfig(Map JavaDoc webServiceInfo){
140         return new ConfigHelper(webServiceInfo);
141     }
142     
143     public static ConfigHelper getInstanceToDeleteRegistryResources() {
144         return new ConfigHelper();
145     }
146     /**
147      * Creates an instance of ConfigHelper that is used to query domain.xml to
148      * get to RegistryLocations. RegistryLocations are determined by the
149      * JAXR_REGISTRY_TYPE
150      */

151     public static ConfigHelper getInstanceToQueryRegistryLocations(){
152         return new ConfigHelper();
153     }
154     
155     /**
156      * Adds the list of RegistryLocations to the domain xml under
157      * webservice-endpoint element, sub element registry-location element
158      * @param String the name of the webservice
159      * @param String[] the list of the registry-location. Registry location
160      * is the jndi name of connection pool pointing to the registry
161      * @exception com.sun.enterprise.ConfigException if config information for
162      * this web service is not found in the domain xml
163      */

164     void addToConfig(String JavaDoc webServiceName, Map JavaDoc<String JavaDoc, String JavaDoc> published){//String[] registryLocations) {
165
if(webServiceInfoMap == null){
166             _logger.fine("ConfigHelper.addToConfig : Incorrect webServiceName ");
167             return;
168         }
169         final DomainConfig dc = this.getDomainConfig();
170         String JavaDoc appId = (String JavaDoc)webServiceInfoMap.get(
171                 WebServiceEndpointInfo.APP_ID_KEY);
172         
173         Boolean JavaDoc isStandAlone = (Boolean JavaDoc)webServiceInfoMap.get(
174                 WebServiceEndpointInfo.IS_STAND_ALONE_MODULE_KEY);
175         
176         String JavaDoc appName = appId;
177         String JavaDoc pureWebServiceName = dropAppNameFromWebServiceName(webServiceName);
178         String JavaDoc underScoredWebServiceName =
179                 convertHashesToUnderScores(webServiceName);
180         
181         WebServiceEndpointConfig wsec = null;
182         
183         if(!isStandAlone) {
184             Map JavaDoc <String JavaDoc, J2EEApplicationConfig> map =
185                     dc.getJ2EEApplicationConfigMap();
186             J2EEApplicationConfig appConfig = map.get(appName);
187             if (appConfig == null) {
188                 // this will never happen as this created by deployment
189
_logger.log(Level.FINE, "Could not find an application with " +
190                         " name = "+appName);
191             } else {
192                 Map JavaDoc <String JavaDoc, WebServiceEndpointConfig> wsmap =
193                         appConfig.getWebServiceEndpointConfigMap();
194                 wsec = wsmap.get(pureWebServiceName);
195                 if (wsec == null){
196                     wsec = appConfig.createWebServiceEndpointConfig(
197                             pureWebServiceName, null);
198                     wsec.setJBIEnabled(false);
199                 }
200                 for (String JavaDoc jndiname : published.keySet()){
201                     appConfig.createProperty(jndiname+"__"+
202                             underScoredWebServiceName,
203                             published.get(jndiname));
204                 }
205             }
206         } else {
207             String JavaDoc type = (String JavaDoc)webServiceInfoMap.
208                     get(WebServiceEndpointInfo.SERVICE_IMPL_TYPE_KEY);
209             if(type.equals(WebServiceEndpointInfo.EJB_IMPL)){
210                 Map JavaDoc <String JavaDoc, EJBModuleConfig> map
211                         = dc.getEJBModuleConfigMap();
212                 EJBModuleConfig ejbConfig = map.get(appName);
213                 if (ejbConfig == null) {
214                     // should never happen
215
_logger.log(Level.FINE, "Could not find a ejb module" +
216                             " with name = "+appName);
217                 } else{
218                     Map JavaDoc <String JavaDoc, WebServiceEndpointConfig> ejbmap =
219                             ejbConfig.getWebServiceEndpointConfigMap();
220                     wsec = ejbmap.get(pureWebServiceName);
221                     if (wsec == null){
222                         wsec = ejbConfig.createWebServiceEndpointConfig(
223                                 pureWebServiceName, null);
224                         wsec.setJBIEnabled(false);
225                     }
226                     for (String JavaDoc jndiname : published.keySet()){
227                         ejbConfig.createProperty(jndiname+"__"+
228                                 underScoredWebServiceName,
229                                 published.get(jndiname));
230                     }
231                 }
232             } else if(type.equals(WebServiceEndpointInfo.SERVLET_IMPL)){
233                 Map JavaDoc <String JavaDoc, WebModuleConfig> map =
234                         dc.getWebModuleConfigMap();
235                 WebModuleConfig webConfig = map.get(appName);
236                 if (webConfig == null){
237                     // should never happen
238
_logger.log(Level.FINE, "Could not find a web module" +
239                             " with name = "+appName);
240                 } else{
241                     Map JavaDoc <String JavaDoc, WebServiceEndpointConfig> webmap =
242                             webConfig.getWebServiceEndpointConfigMap();
243                     wsec = webmap.get(pureWebServiceName);
244                     if (wsec == null){
245                         wsec = webConfig.createWebServiceEndpointConfig(
246                                 pureWebServiceName, null);
247                         wsec.setJBIEnabled(false);
248                     }
249                     for (String JavaDoc jndiname : published.keySet()){
250                         webConfig.createProperty(jndiname+"__"+
251                                 underScoredWebServiceName,
252                                 published.get(jndiname));
253                     }
254                 }
255             }
256         }
257         if(wsec != null){
258             String JavaDoc[] registryLocations = new String JavaDoc[published.size()];
259             registryLocations = published.keySet().toArray(registryLocations);
260             populateWebServiceEndpointConfig(wsec, registryLocations);
261         }
262         return;
263     }
264     
265     void populateWebServiceEndpointConfig(WebServiceEndpointConfig wsec,
266             String JavaDoc[] registryLocations){
267         for (String JavaDoc jndi : registryLocations){
268             wsec.createRegistryLocationConfig(jndi);
269         }
270     }
271     /**
272      * Deletes the mapping of the RegistryLocation under the
273      * web-service-endpoint element. This is called when the user has
274      * unpublished a web service from the registries.
275      * @param String name of the web service
276      * @param String[] the list of the RegistryLocations. RegistryLocation is
277      * the jndi name of the connection pool pointing to the registry.
278      * @exception com.sun.enterprise.ConfigException if config information for
279      * this web service is not found in the domain xml
280      */

281     void deleteFromConfig(String JavaDoc webServiceName, String JavaDoc[] registryLocations) {
282         if(webServiceInfoMap == null){
283             _logger.fine("ConfigHelper.deletFromConfig : Incorrect " +
284                     "webServiceName. Exiting! ");
285             return;
286         }
287         final DomainConfig dc = getDomainConfig();
288         String JavaDoc appId = (String JavaDoc)webServiceInfoMap.get(
289                 WebServiceEndpointInfo.APP_ID_KEY);
290         
291         Boolean JavaDoc isStandAlone = (Boolean JavaDoc)webServiceInfoMap.get(
292                 WebServiceEndpointInfo.IS_STAND_ALONE_MODULE_KEY);
293         
294         String JavaDoc pureWebServiceName = dropAppNameFromWebServiceName(webServiceName);
295         String JavaDoc underScoredWebServiceName =
296                 convertHashesToUnderScores(webServiceName);
297         
298         WebServiceEndpointConfig wsec = null;
299         if (!isStandAlone) {
300             Map JavaDoc<String JavaDoc, J2EEApplicationConfig> appMap =
301                     dc.getJ2EEApplicationConfigMap();
302             J2EEApplicationConfig config = appMap.get(appId);
303             Map JavaDoc<String JavaDoc, WebServiceEndpointConfig> wsecMap =
304                     config.getWebServiceEndpointConfigMap();
305             wsec = wsecMap.get(pureWebServiceName);
306             for (int i=0; i<registryLocations.length; i++){
307                 String JavaDoc jndiname = registryLocations[i];
308                 config.removeProperty(jndiname+"__"+
309                         underScoredWebServiceName);
310             }
311         } else {
312             String JavaDoc type = (String JavaDoc)webServiceInfoMap.get(
313                     WebServiceEndpointInfo.SERVICE_IMPL_TYPE_KEY);
314             if (type.equals(WebServiceEndpointInfo.EJB_IMPL)){
315                 Map JavaDoc<String JavaDoc, EJBModuleConfig> ejbMap =
316                         dc.getEJBModuleConfigMap();
317                 EJBModuleConfig config = ejbMap.get(appId);
318                 Map JavaDoc<String JavaDoc, WebServiceEndpointConfig> wsecMap =
319                         config.getWebServiceEndpointConfigMap();
320                 wsec = wsecMap.get(pureWebServiceName);
321                 for (int i=0; i<registryLocations.length; i++){
322                     String JavaDoc jndiname = registryLocations[i];
323                     config.removeProperty(jndiname+"__"+
324                             underScoredWebServiceName);
325                 }
326                 
327             } else if (type.equals(WebServiceEndpointInfo.SERVLET_IMPL)){
328                 Map JavaDoc<String JavaDoc, WebModuleConfig> webMap =
329                         dc.getWebModuleConfigMap();
330                 WebModuleConfig config = webMap.get(appId);
331                 Map JavaDoc<String JavaDoc, WebServiceEndpointConfig> wsecMap =
332                         config.getWebServiceEndpointConfigMap();
333                 wsec = wsecMap.get(pureWebServiceName);
334                 for (int i=0; i<registryLocations.length; i++){
335                     String JavaDoc jndiname = registryLocations[i];
336                     config.removeProperty(jndiname+"__"+
337                             underScoredWebServiceName);
338                 }
339                 
340             }
341         }
342         if (wsec != null){
343             for (String JavaDoc jndiName : registryLocations )
344                 wsec.removeRegistryLocationConfig(jndiName);
345         }
346     }
347     
348     private String JavaDoc dropAppNameFromWebServiceName(String JavaDoc webServiceName){
349         String JavaDoc[] split = webServiceName.split("#");
350         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
351         for (int i=1; i<split.length; i++){
352             buf.append(split[i]);
353             if(i<(split.length-1)){
354                 buf.append("#");
355             }
356         }
357         return buf.toString();
358     }
359     
360     /**
361      * List the RegistryLocations. A registry location is the jndi name of a
362      * connection pool that points to a registry determined by the
363      * connector connection definition of the type JAXR_REGISTRY_TYPE
364      * @return String[] list of registry-location
365      * @exception com.sun.enterprise.ConfigException if config information for
366      * this web service is not found in the domain xml
367      */

368     String JavaDoc[] listRegistryLocations(){
369         final DomainConfig dc = this.getDomainConfig();
370         List JavaDoc<String JavaDoc> jndinames = new ArrayList JavaDoc<String JavaDoc>();
371         /**
372          * Get the names of resource-adapters for connection-pool of the type
373          * JAXR_REGISTRY_TYPE. Peek into the ResourceAdapterConfig to get the
374          * jndi name.
375          */

376         Map JavaDoc<String JavaDoc, ConnectorConnectionPoolConfig> ccpcMap =
377                 dc.getConnectorConnectionPoolConfigMap();
378         
379         Map JavaDoc<String JavaDoc, ConnectorResourceConfig> crcMap =
380                 dc.getConnectorResourceConfigMap();
381         
382         for (String JavaDoc poolName : ccpcMap.keySet() ){
383             ConnectorConnectionPoolConfig ccpc = ccpcMap.get(poolName);
384             String JavaDoc connectionDefnName = ccpc.getConnectionDefinitionName();
385             if (JAXR_REGISTRY_TYPE.equals(connectionDefnName) ||
386                     UDDI_JAXR_REGISTRY_TYPE.equals(connectionDefnName)){
387                 
388                 for (String JavaDoc resourceName:crcMap.keySet()){
389                     ConnectorResourceConfig crc = crcMap.get(resourceName);
390                     if (poolName.equals(crc.getPoolName()))
391                         jndinames.add(crc.getJNDIName());
392                 }
393             }
394         }
395         String JavaDoc[] retValue = new String JavaDoc[jndinames.size()];
396         retValue = jndinames.toArray(retValue);
397         return retValue;
398     }
399     
400     /**
401      * Removes the registry specific resources from the domain.
402      * Peeks at the connector-resource element to obtain the
403      * connector-connection-pool name. Using this pool name, removes the
404      * connector-connection-pool, proceeds further to remove the
405      * connector-resource
406      * @param jndiNameOfRegistry whose resources are to be removed from the domain
407      */

408     public void removeRegistryConnectionResources(String JavaDoc jndiNameOfRegistry) {
409         final DomainConfig dc = getDomainConfig();
410         Map JavaDoc<String JavaDoc, ConnectorResourceConfig> crcMap =
411                 dc.getConnectorResourceConfigMap();
412         ConnectorResourceConfig crc = crcMap.get(jndiNameOfRegistry);
413         String JavaDoc poolName = (crc != null)? crc.getPoolName(): null;
414         dc.removeConnectorResourceConfig(jndiNameOfRegistry);
415         if (poolName != null){
416             dc.removeConnectorConnectionPoolConfig(poolName);
417         }
418     }
419     
420     /**
421      * Adds registry specific resources to the domain.
422      * Adds a connector connection pool and then proceeds to add a connector
423      * resource
424      *
425      * @param jndiName of the connector-resource that points to the registry
426      *
427      * @param description of the connector-resource and the connector-connection
428      * -pool name
429      *
430      * @param type type of the registry
431      * {@link com.sun.appserv.management.WebServiceMgr#UDDI_KEY}
432      * {@link com.sun.appserv.management.WebServiceMgr#EBXML_KEY}
433      *
434      * @param properties a map of key, value pair that encapsulate the properties
435      * of the connection pool that connects to the registry. Properties are
436      *
437      * {@link com.sun.appserv.management.WebServiceMgr#PUBLISH_URL_KEY}
438      * {@link com.sun.appserv.management.WebServiceMgr#QUERY_URL_KEY}
439      * {@link com.sun.appserv.management.WebServiceMgr#USERNAME_KEY}
440      * {@link com.sun.appserv.management.WebServiceMgr#PASSWORD_KEY}
441      */

442     public void addRegistryConnectionResources(String JavaDoc jndiName,
443             String JavaDoc description, String JavaDoc type, Map JavaDoc<String JavaDoc, String JavaDoc> properties){
444         
445         final DomainConfig dc = getDomainConfig();
446         String JavaDoc registryType = null;
447         if (type == WebServiceMgr.UDDI_KEY) {
448             registryType = this.UDDI_PROPERTY;
449         } else if (type == WebServiceMgr.EBXML_KEY ){
450             registryType = this.EBXML_PROPERTY;
451         }
452         if (registryType == null) {
453             Object JavaDoc[] params = {UDDI_PROPERTY, EBXML_PROPERTY};
454             _logger.log(Level.WARNING, "registry.specify_registry_type", params);
455             throw new RuntimeException JavaDoc("Registry Type has to be "+
456                     UDDI_PROPERTY + " or "+ EBXML_PROPERTY);
457         }
458         // 1. get resource adapter config
459
Map JavaDoc <String JavaDoc, ResourceAdapterConfig> raConfMap = dc.getResourceAdapterConfigMap();
460         // 2. get the resourceAdapterName
461
String JavaDoc resourceAdapterName = null;
462         for (String JavaDoc ra : raConfMap.keySet()){
463             ResourceAdapterConfig rac = raConfMap.get(ra);
464             if (rac.existsProperty(registryType)){
465                 resourceAdapterName = rac.getResourceAdapterName();
466                 break;
467             }
468         }
469         if (resourceAdapterName == null){
470             // Now look in the system resource adapter.
471
resourceAdapterName = getSystemConnectorResources(registryType);
472         
473             if (resourceAdapterName == null){
474                 // could not find any resource adapter that is a jaxr resource adapter type
475
// log it
476
String JavaDoc msg =
477                         "Cannot locate JAXR Resource Adapter to add Connection pool" +
478                         " and Connector Resource. Please add connector resource " +
479                         "of type " + registryType;
480                 _logger.log(Level.SEVERE,
481                         "registry.deploy_registry_connector_resource", registryType);
482                 throw new RuntimeException JavaDoc(msg);
483             }
484         }
485         
486         // 3. generate a unique pool name
487
String JavaDoc poolName = FileUtils.makeFriendlyFileName(jndiName) + POOL_SUFFIX;
488         // 4. connectorDefinitionName
489
String JavaDoc connectorDefinitionName = JAXR_REGISTRY_TYPE;
490         if (registryType.equals(UDDI_PROPERTY)){
491             // jaxr-ri works only with a "/" appended to the URL
492
Properties JavaDoc props = new Properties JavaDoc ();
493             for (String JavaDoc property : properties.keySet()){
494                 String JavaDoc propValue = (String JavaDoc)properties.get(property);
495                 if (LifeCycleManagerURL.equals(property) ||
496                         QueryManagerURL.equals(property)){
497                     //jaxr-ri needs a backslash at the end of the URL
498
if (!propValue.endsWith("/")) {
499                         propValue = propValue + "/";
500                     }
501                     props.put(property, propValue);
502                 } else if (property.equalsIgnoreCase ("username")){
503                     props.put("UserName", propValue);
504                 } else if (property.equalsIgnoreCase ("password")){
505                     props.put ("UserPassword", propValue);
506                 } else
507                     props.put(property, propValue);
508             }
509             
510             connectorDefinitionName = UDDI_JAXR_REGISTRY_TYPE;
511             createConnectorConnectionPoolMBean(resourceAdapterName,
512                     connectorDefinitionName, poolName, props);
513         } else {
514             Map JavaDoc<String JavaDoc, String JavaDoc> optional = new HashMap JavaDoc <String JavaDoc, String JavaDoc> ();
515             for (String JavaDoc property : properties.keySet()){
516             optional.put(PropertiesAccess.PROPERTY_PREFIX + property,
517                                 properties.get (property));
518             }
519     
520             dc.createConnectorConnectionPoolConfig( poolName,
521                     resourceAdapterName, connectorDefinitionName, optional );
522         }
523         dc.createConnectorResourceConfig(jndiName, poolName, null);
524     }
525
526     private void createConnectorConnectionPoolMBean
527             (final String JavaDoc resourceAdapterName,
528             final String JavaDoc connectorDefinitionName,
529             final String JavaDoc poolName, final Properties JavaDoc props) {
530         try{
531             // system rars cannot used via AMX :-(
532
final MBeanServer JavaDoc server = MBeanServerFactory.getMBeanServer();
533             ObjectName JavaDoc obj = new ObjectName JavaDoc
534                     ("com.sun.appserv:type=resources,category=config");
535             AttributeList JavaDoc attrlist = new AttributeList JavaDoc();
536             attrlist.add(new Attribute JavaDoc("name", poolName));
537             attrlist.add(new Attribute JavaDoc("resource-adapter-name", resourceAdapterName));
538             attrlist.add(new Attribute JavaDoc("connection-definition-name", connectorDefinitionName));
539             Object JavaDoc[] params = new Object JavaDoc[3];
540             params[0] = attrlist;
541             params[1] = props;
542             params[2] = "server";
543             String JavaDoc[] signature = new String JavaDoc[3];
544             signature[0] = "javax.management.AttributeList";
545             signature[1] = "java.util.Properties";
546             signature[2] = "java.lang.String";
547             server.invoke(obj, "createConnectorConnectionPool",
548                     params, signature);
549         } catch (Exception JavaDoc e) {
550             _logger.log(Level.WARNING, "cannot create connection pool for " +
551                     "resource adapter ="+resourceAdapterName, e);
552         }
553     }
554     // This is not entirely baked as admin backend does not provide a clean
555
// way to handle system resource adapters. Look @ bug id: 6364653
556
// Commenting this out for now.
557
private String JavaDoc getSystemConnectorResources(String JavaDoc type){
558         String JavaDoc[] systemResources = null;
559         
560         final MBeanServer JavaDoc server = MBeanServerFactory.getMBeanServer();
561         try {
562             ObjectName JavaDoc objName =
563                     new ObjectName JavaDoc("com.sun.appserv:type=resources,category=config");
564             systemResources = (String JavaDoc[])server.invoke( objName,
565                     "getSystemConnectorsAllowingPoolCreation", null, null);
566             for (int i =0; i< systemResources.length; i++){
567                 if (ignore_ra.equals(systemResources[i]))// dont look at jms ra
568
continue;
569                 
570                 AttributeList JavaDoc attrList = new AttributeList JavaDoc();
571                 attrList.add(new Attribute JavaDoc("resource-adapter-name",
572                         systemResources[i]));
573                 if (UDDI_PROPERTY.equals (type))
574                     attrList.add(new Attribute JavaDoc("connection-definition-name",
575                         UDDI_JAXR_REGISTRY_TYPE));
576                 else
577                     attrList.add(new Attribute JavaDoc("connection-definition-name",
578                         JAXR_REGISTRY_TYPE));
579                     
580                 Object JavaDoc[] params = new Object JavaDoc[]{attrList};
581                 String JavaDoc[] types = new String JavaDoc[]{"javax.management.AttributeList"};
582                 Properties JavaDoc properties =
583                         (Properties JavaDoc)server.invoke(new ObjectName JavaDoc
584                         ("com.sun.appserv:type=resources,category=config"),
585                         "getMCFConfigProps",
586                         params, types );
587                 
588                 Enumeration JavaDoc propertyNames = properties.propertyNames();
589                 while(propertyNames.hasMoreElements()){
590                     String JavaDoc name = (String JavaDoc)propertyNames.nextElement();
591                     if (UDDI_PROPERTY.equals(type)){
592                         if (name.equals(APPSERVER_UDDI))
593                             return systemResources[i];
594                     } else if (EBXML_PROPERTY.equals(type)) { // we do not have this yet.
595
// Kept incase soar-rar goes as a system adapter in the
596
// futurre
597
if (name.equals(APPSERVER_EBXML))
598                             return systemResources[i];
599                     }
600                 }
601             }
602         } catch (Exception JavaDoc e) {
603             _logger.log (Level.FINE, "Cannot locate system connector resources");
604         }
605         
606         return null;
607     }
608     private DomainConfig getDomainConfig(){
609         final MBeanServer JavaDoc server = MBeanServerFactory.getMBeanServer();
610         final DomainRoot domainRoot =
611                 ProxyFactory.getInstance(server).getDomainRoot();
612         final DomainConfig domainConfig = domainRoot.getDomainConfig();
613         return domainConfig;
614     }
615     
616     public String JavaDoc[] listAlreadyPublishedRegistryLocations(String JavaDoc webServiceName,
617             String JavaDoc[] registryLocations) {
618         
619         String JavaDoc[] prePublished = null;
620         if(webServiceInfoMap == null){
621             _logger.fine("ConfigHelper.addToConfig : Incorrect webServiceName ");
622             return prePublished;
623         }
624         final DomainConfig dc = this.getDomainConfig();
625         String JavaDoc appId = (String JavaDoc)webServiceInfoMap.get(
626                 WebServiceEndpointInfo.APP_ID_KEY);
627         
628         Boolean JavaDoc isStandAlone = (Boolean JavaDoc)webServiceInfoMap.get(
629                 WebServiceEndpointInfo.IS_STAND_ALONE_MODULE_KEY);
630         
631         String JavaDoc appName = appId;
632         String JavaDoc pureWebServiceName = dropAppNameFromWebServiceName(webServiceName);
633         WebServiceEndpointConfig wsec = null;
634         
635         if(!isStandAlone) {
636             Map JavaDoc <String JavaDoc, J2EEApplicationConfig> map =
637                     dc.getJ2EEApplicationConfigMap();
638             J2EEApplicationConfig appConfig = map.get(appName);
639             if (appConfig == null) {
640                 // this will never happen as this created by deployment
641
_logger.log(Level.FINE, "Could not find an application with " +
642                         " name = "+appName);
643             } else {
644                 Map JavaDoc <String JavaDoc, WebServiceEndpointConfig> wsmap =
645                         appConfig.getWebServiceEndpointConfigMap();
646                 wsec = wsmap.get(pureWebServiceName);
647             }
648         } else {
649             String JavaDoc type = (String JavaDoc)webServiceInfoMap.
650                     get(WebServiceEndpointInfo.SERVICE_IMPL_TYPE_KEY);
651             if(type.equals(WebServiceEndpointInfo.EJB_IMPL)){
652                 Map JavaDoc <String JavaDoc, EJBModuleConfig> map
653                         = dc.getEJBModuleConfigMap();
654                 EJBModuleConfig ejbConfig = map.get(appName);
655                 if (ejbConfig == null) {
656                     // should never happen
657
_logger.log(Level.FINE, "Could not find a ejb module" +
658                             " with name = "+appName);
659                 } else{
660                     Map JavaDoc <String JavaDoc, WebServiceEndpointConfig> ejbmap =
661                             ejbConfig.getWebServiceEndpointConfigMap();
662                     wsec = ejbmap.get(pureWebServiceName);
663                 }
664             } else if(type.equals(WebServiceEndpointInfo.SERVLET_IMPL)){
665                 Map JavaDoc <String JavaDoc, WebModuleConfig> map =
666                         dc.getWebModuleConfigMap();
667                 WebModuleConfig webConfig = map.get(appName);
668                 if (webConfig == null){
669                     // should never happen
670
_logger.log(Level.FINE, "Could not find a web module" +
671                             " with name = "+appName);
672                 } else{
673                     Map JavaDoc <String JavaDoc, WebServiceEndpointConfig> webmap =
674                             webConfig.getWebServiceEndpointConfigMap();
675                     wsec = webmap.get(pureWebServiceName);
676                 }
677             }
678         }
679         if(wsec != null){
680             Map JavaDoc <String JavaDoc, RegistryLocationConfig> regMap =
681                     wsec.getRegistryLocationConfigMap();
682             prePublished = new String JavaDoc[regMap.size()];
683             int i = 0;
684             for (String JavaDoc regLoc : regMap.keySet()){
685                 RegistryLocationConfig rlc = regMap.get(regLoc);
686                 prePublished [i++] =
687                         new String JavaDoc(rlc.getConnectorResourceJNDIName());
688             }
689         }
690         return prePublished;
691     }
692     
693     String JavaDoc getOrganizationName(String JavaDoc webServiceName, String JavaDoc registryLocation){
694         String JavaDoc organization = null;
695         if(webServiceInfoMap == null){
696             _logger.fine("ConfigHelper.addToConfig : Incorrect webServiceName ");
697             return null;
698         }
699         final DomainConfig dc = this.getDomainConfig();
700         String JavaDoc appId = (String JavaDoc)webServiceInfoMap.get(
701                 WebServiceEndpointInfo.APP_ID_KEY);
702         
703         Boolean JavaDoc isStandAlone = (Boolean JavaDoc)webServiceInfoMap.get(
704                 WebServiceEndpointInfo.IS_STAND_ALONE_MODULE_KEY);
705         
706         String JavaDoc appName = appId;
707         String JavaDoc underScoredWebServiceName =
708                 convertHashesToUnderScores(webServiceName);
709         
710         if(!isStandAlone) {
711             Map JavaDoc <String JavaDoc, J2EEApplicationConfig> map =
712                     dc.getJ2EEApplicationConfigMap();
713             J2EEApplicationConfig appConfig = map.get(appName);
714             if (appConfig == null) {
715                 // this will never happen as this created by deployment
716
_logger.log(Level.FINE, "Could not find an application with " +
717                         " name = "+appName);
718             } else {
719                 organization =
720                         (String JavaDoc)appConfig.getPropertyValue(registryLocation+"__"+
721                         underScoredWebServiceName);
722             }
723         } else {
724             String JavaDoc type = (String JavaDoc)webServiceInfoMap.
725                     get(WebServiceEndpointInfo.SERVICE_IMPL_TYPE_KEY);
726             if(type.equals(WebServiceEndpointInfo.EJB_IMPL)){
727                 Map JavaDoc <String JavaDoc, EJBModuleConfig> map
728                         = dc.getEJBModuleConfigMap();
729                 EJBModuleConfig ejbConfig = map.get(appName);
730                 if (ejbConfig == null) {
731                     // should never happen
732
_logger.log(Level.FINE, "Could not find a ejb module" +
733                             " with name = "+appName);
734                 } else{
735                     organization =
736                             (String JavaDoc)ejbConfig.getPropertyValue(registryLocation+
737                             "__"+ underScoredWebServiceName);
738                 }
739             } else if(type.equals(WebServiceEndpointInfo.SERVLET_IMPL)){
740                 Map JavaDoc <String JavaDoc, WebModuleConfig> map =
741                         dc.getWebModuleConfigMap();
742                 WebModuleConfig webConfig = map.get(appName);
743                 if (webConfig == null){
744                     // should never happen
745
_logger.log(Level.FINE, "Could not find a web module" +
746                             " with name = "+appName);
747                 } else{
748                     organization =
749                             (String JavaDoc)webConfig.getPropertyValue(registryLocation+
750                             "__"+ underScoredWebServiceName);
751                 }
752             }
753         }
754         return organization;
755     }
756     /*
757      * Used for the key in domain.xml. The key, value is of the type
758      * registryjndiname__webservicename, Organization
759      * webservice name , is the FQN with # converted to __
760      */

761     
762     private String JavaDoc convertHashesToUnderScores(String JavaDoc hashed){
763         String JavaDoc returnValue = hashed.replaceAll("#", "__");
764         return returnValue;
765     }
766     
767     public String JavaDoc[] checkForDuplicateRegistries (String JavaDoc[] jndi) {
768         if (jndi.length <=1)
769             return null;
770         // plain comparision to see if the jndi names are duplicates
771
String JavaDoc[] duplicate = null;
772         for (int i = 0; i<jndi.length; i++){
773             for (int j=i+1; j<jndi.length; j++){
774                 if (jndi[i].equals (jndi[j])){
775                     duplicate = new String JavaDoc[1];
776                     duplicate[0] = jndi[i];
777                     this._logger.log (Level.SEVERE,
778                             "Duplicate Registry Jndi Names. Will not" +
779                             " publish the same " +
780                             "web service twice to the same registry. " +
781                             "Remove one jndi name ("+jndi[i]+")");
782                     return duplicate;
783                 }
784             }
785         }
786         if (duplicate == null){
787             final DomainConfig dc = this.getDomainConfig ();
788             Map JavaDoc<String JavaDoc, ConnectorResourceConfig> crcMap =
789                     dc.getConnectorResourceConfigMap ();
790             for (int i = 0; i<jndi.length; i++){
791                 ConnectorResourceConfig crc = crcMap.get (jndi[i]);
792                 String JavaDoc pool = crc.getPoolName ();
793                 for (int j=i+1; j<jndi.length; j++){
794                     ConnectorResourceConfig crcNew = crcMap.get (jndi[j]);
795                     if(pool.equals (crcNew.getPoolName())){
796                         duplicate = new String JavaDoc[2];
797                         duplicate[0] = jndi[i];
798                         duplicate[1] = jndi[j];
799                         this._logger.log (Level.SEVERE,
800                             "Registry Jndi Names point to the same registry. Will not" +
801                             " publish the same " +
802                             "web service twice to the same registry. " +
803                             "Remove one duplicate of ("+jndi[i]+")" +
804                                 " or ("+jndi[j]+")");
805                         return duplicate;
806                     }
807                 }
808             }
809         }
810         return null;
811     }
812 }
813
Popular Tags