KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > admingui > handlers > WebServiceHandler


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  * WebServiceHandler.java
25  *
26  * Created on May 6, 2005, 12:27 PM
27  */

28
29 package com.sun.enterprise.tools.admingui.handlers;
30
31 import java.io.File JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.HashMap JavaDoc;
34 import java.util.Map JavaDoc;
35 import java.util.Set JavaDoc;
36 import java.util.List JavaDoc;
37 import java.util.Iterator JavaDoc;
38 import java.text.NumberFormat JavaDoc;
39
40 import javax.servlet.http.HttpSession JavaDoc;
41 import javax.management.Attribute JavaDoc;
42 import javax.management.AttributeList JavaDoc;
43 import javax.management.ObjectName JavaDoc;
44
45 import com.iplanet.jato.RequestContext;
46 import com.iplanet.jato.model.DefaultModel;
47 import com.iplanet.jato.model.ModelControlException;
48 import com.iplanet.jato.view.html.OptionList;
49 import com.iplanet.jato.view.View;
50 import com.iplanet.jato.view.ViewBase;
51
52 import com.sun.enterprise.tools.admingui.util.MBeanUtil;
53 import com.sun.enterprise.tools.admingui.util.Util;
54 import com.sun.enterprise.tools.admingui.util.AMXUtil;
55
56 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
57 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView;
58 import com.sun.enterprise.tools.guiframework.view.HandlerContext;
59 import com.sun.enterprise.tools.guiframework.view.descriptors.CCActionTableDescriptor;
60 import com.sun.enterprise.tools.guiframework.view.descriptors.CCAddRemoveDescriptor;
61 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor;
62 import com.sun.enterprise.tools.guiframework.view.event.BeforeCreateEvent;
63
64 import com.sun.web.ui.model.CCActionTableModelInterface;
65 import com.sun.web.ui.model.CCAddRemoveModelInterface;
66 import com.sun.web.ui.taglib.pagetitle.CCPageTitleTag;
67 import com.sun.web.ui.view.addremove.CCAddRemove;
68
69
70 //AMX dynamic proxies
71
import com.sun.appserv.management.base.AMX;
72 import com.sun.appserv.management.base.QueryMgr;
73 import com.sun.appserv.management.config.EJBModuleConfig;
74 import com.sun.appserv.management.config.J2EEApplicationConfig;
75 import com.sun.appserv.management.config.RegistryLocationConfig;
76 import com.sun.appserv.management.config.TransformationRuleConfig;
77 import com.sun.appserv.management.config.WebModuleConfig;
78 import com.sun.appserv.management.config.WebServiceEndpointConfig;
79 import com.sun.appserv.management.ext.wsmgmt.WebServiceEndpointInfo;
80 import com.sun.appserv.management.ext.wsmgmt.WebServiceMgr;
81 import com.sun.appserv.management.j2ee.WebServiceEndpoint;
82
83 public class WebServiceHandler {
84     
85    public void loadWebServiceGeneralTableModel(RequestContext ctx, HandlerContext handlerCtx) {
86        CCActionTableDescriptor ccDesc = (CCActionTableDescriptor)((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor();
87        CCActionTableModelInterface model = ccDesc.getModel();
88         ((DefaultModel)model).clear();
89         
90         ArrayList JavaDoc displayNamesList = (ArrayList JavaDoc)handlerCtx.getInputValue("displayNames");
91         ArrayList JavaDoc modelNamesList = (ArrayList JavaDoc)handlerCtx.getInputValue("attributeNames");
92         ObjectName JavaDoc webServiceMgr = (ObjectName JavaDoc)handlerCtx.getInputValue("webServiceMgrObjectName");
93         String JavaDoc getWSNames = (String JavaDoc)handlerCtx.getInputValue("getWSNamesMethodName");
94         Map JavaDoc wsNames = (Map JavaDoc)handlerCtx.getInputValue("wsNamesMap");
95         String JavaDoc[] fullName = (String JavaDoc[])wsNames.keySet().toArray(new String JavaDoc[wsNames.size()]);
96         
97         if (wsNames == null || wsNames.isEmpty()) {
98             return; //nothing to load..
99
}
100         
101         String JavaDoc[] modelNames = null;
102         if (modelNamesList != null) {
103             modelNames = (String JavaDoc[])modelNamesList.toArray(new String JavaDoc[modelNamesList.size()]);
104         }
105          
106         for (int i = 0; i < fullName.length; i++) {
107             model.appendRow();
108             Object JavaDoc[] paramsArray = {fullName[i]};
109             String JavaDoc[] typesArray = {"java.lang.Object"};
110             Map JavaDoc wsiMap = (Map JavaDoc)MBeanUtil.invoke(webServiceMgr, getWSNames, paramsArray , typesArray);
111             for (int j=0; j< modelNames.length; j++) {
112                 String JavaDoc col = (String JavaDoc)displayNamesList.get(j);
113                 Object JavaDoc obj = wsiMap.get(modelNames[j]);
114                 String JavaDoc val = "";
115                 if (obj instanceof String JavaDoc) {
116                     val = (String JavaDoc)obj;
117                 } else if (obj instanceof Boolean JavaDoc) {
118                     val = obj.toString();
119                 }
120                 if (col.equals("name")) {
121                     val = (String JavaDoc)wsNames.get(fullName[i]); // get display name
122
} else if (col.equals("wsdl")) {
123                     val = new File JavaDoc(val).getName();
124                 } else if (col.equals("webServiceKey")) {
125                     val = fullName[i];
126                 }
127                 model.setValue(col, val);
128             }
129         }
130     }
131    
132     public void loadMessagesTableModel(RequestContext ctx, HandlerContext handlerCtx) {
133         CCActionTableModelInterface model = (CCActionTableModelInterface)handlerCtx.getInputValue("tableModel");
134         ((DefaultModel)model).clear();
135         
136         ArrayList JavaDoc displayNamesList = (ArrayList JavaDoc)handlerCtx.getInputValue("displayNames");
137         ArrayList JavaDoc modelNamesList = (ArrayList JavaDoc)handlerCtx.getInputValue("attributeNames");
138         Set JavaDoc epSet = (Set JavaDoc)handlerCtx.getInputValue("endpointObjNameSet");
139         String JavaDoc filterValue = (String JavaDoc)handlerCtx.getInputValue("filterValue");
140         if (filterValue == null) {
141             filterValue = com.sun.web.ui.view.table.CCActionTable.FILTER_ALL_ITEMS_OPTION;
142         }
143         
144         if (epSet == null || epSet.isEmpty()) {
145             return; //no runtime endpoints to load
146
}
147         ObjectName JavaDoc endpointObjName = (ObjectName JavaDoc)epSet.toArray()[0];
148         Map JavaDoc[] msgsMap = (Map JavaDoc[])MBeanUtil.getAttribute(endpointObjName, "MessagesInHistory");
149         
150         if (msgsMap == null || msgsMap.length == 0) {
151             return; //nothing to load..
152
}
153         
154         String JavaDoc[] modelNames = null;
155         if (modelNamesList != null) {
156             modelNames = (String JavaDoc[])modelNamesList.toArray(new String JavaDoc[modelNamesList.size()]);
157         }
158         
159         String JavaDoc success = Util.getMessage("common.Success");
160         String JavaDoc failed = Util.getMessage("common.Failed");
161         
162         for (int i=0; i < msgsMap.length; i++) {
163             Object JavaDoc ob = msgsMap[i].get("FaultCode");
164             if (ob == null && filterValue.equals("Success") //match the value in the table xml
165
|| ob != null && filterValue.equals("Failed")
166             || filterValue.equals(com.sun.web.ui.view.table.CCActionTable.FILTER_ALL_ITEMS_OPTION)) {
167            
168                 model.appendRow();
169                 
170                 for (int j=0; j< modelNames.length; j++) {
171                     String JavaDoc col = (String JavaDoc)displayNamesList.get(j);
172                     Object JavaDoc obj = msgsMap[i].get(modelNames[j]);
173                     String JavaDoc val = "";
174                     if (obj instanceof String JavaDoc) {
175                         val = (String JavaDoc)obj;
176                     } else if (obj instanceof Integer JavaDoc) {
177                         val = obj.toString();
178                     }
179                     if (col.equals("timeStampFormatted")) {
180                         Long JavaDoc L = new Long JavaDoc(val);
181                         long l = L.longValue();
182                         java.util.Date JavaDoc date = new java.util.Date JavaDoc(l);
183                         val = date.toString();
184                     } else if (col.equals("size")) {
185                         val = msgsMap[i].get("RequestSize") + "b / " + msgsMap[i].get("ResponseSize") + "b";
186                     } else if (col.equals("response")) {
187                         val = obj == null ? success : failed;
188                     } else if (col.endsWith("endpointObjName")) {
189                         val = endpointObjName.toString();
190                     } else if (col.endsWith("callFlow")) {
191                         String JavaDoc callFlow = (String JavaDoc)msgsMap[i].get("CallFlowEnabled");
192                         Boolean JavaDoc isCallFlowEnabled = Boolean.valueOf(callFlow);
193                         if (isCallFlowEnabled) {
194                             val = Util.getMessage("webServiceMessages.callFlow");
195                         } else {
196                             val = "";
197                         }
198                     }
199                     model.setValue(col, val);
200                 }
201             }
202         }
203     }
204     
205     public void getMsgContent(RequestContext ctx, HandlerContext handlerCtx) {
206         String JavaDoc endpointObjName = (String JavaDoc)handlerCtx.getInputValue("endpointObjName");
207         String JavaDoc msgID = (String JavaDoc)handlerCtx.getInputValue("msgID");
208         String JavaDoc type = (String JavaDoc)handlerCtx.getInputValue("type");
209         Map JavaDoc[] msgsMap = (Map JavaDoc[])MBeanUtil.getAttribute(endpointObjName, "MessagesInHistory");
210         String JavaDoc content = null;
211         for (int i=0; i < msgsMap.length; i++) {
212             String JavaDoc id = msgsMap[i].get("MessageID").toString();
213             if (id.equals(msgID)) {
214                 if (type.equals("request")) {
215                     content = (String JavaDoc)msgsMap[i].get("RequestContent");
216                 } else {
217                     content = (String JavaDoc)msgsMap[i].get("ResponseContent");
218                 }
219                 break;
220             }
221         }
222         handlerCtx.setOutputValue("content", content);
223     }
224     
225     public void beginMsgViewerTitleDisplay(RequestContext ctx, HandlerContext handlerCtx) {
226         CCPageTitleTag tag = (CCPageTitleTag)handlerCtx.getEvent().getSource();
227         String JavaDoc type = (String JavaDoc)handlerCtx.getInputValue("type");
228         String JavaDoc title = "";
229         if (type.equals("request")) {
230             title = Util.getMessage("webServiceMessageDetail.Request");
231         } else {
232             title = Util.getMessage("webServiceMessageDetail.Response");
233         }
234         tag.setPageTitleText(title);
235     }
236     
237     public void getApplicationLinkNextPage(RequestContext ctx, HandlerContext handlerCtx) {
238         String JavaDoc isStandAlone = (String JavaDoc)handlerCtx.getInputValue("isStandAlone");
239         String JavaDoc type = (String JavaDoc)handlerCtx.getInputValue("type");
240         if (isStandAlone.equals("false")) {
241             handlerCtx.setOutputValue("nextPage", "enterpriseApplicationsEdit");
242         } else {
243             if (type.equals("SERVLET")) {
244                 handlerCtx.setOutputValue("nextPage", "webApplicationsEdit");
245             } else {
246                 handlerCtx.setOutputValue("nextPage", "ejbModulesEdit");
247             }
248         }
249     }
250     
251     public void displayWebServiceInfo(RequestContext ctx, HandlerContext handlerCtx) {
252         ArrayList JavaDoc displayNamesList = (ArrayList JavaDoc)handlerCtx.getInputValue("displayNames");
253         ArrayList JavaDoc modelNamesList = (ArrayList JavaDoc)handlerCtx.getInputValue("attributeNames");
254         ObjectName JavaDoc webServiceMgr = (ObjectName JavaDoc)handlerCtx.getInputValue("webServiceMgrObjectName");
255         String JavaDoc getWSNames = (String JavaDoc)handlerCtx.getInputValue("getWSNamesMethodName");
256         String JavaDoc webServiceKey = (String JavaDoc)handlerCtx.getInputValue("webServiceKey");
257         Map JavaDoc wsNames = (Map JavaDoc)handlerCtx.getInputValue("wsNamesMap");
258         String JavaDoc displayName = (String JavaDoc)wsNames.get((Object JavaDoc)webServiceKey);
259         String JavaDoc[] paramsArray = {webServiceKey};
260         String JavaDoc[] typesArray = {"java.lang.Object"};
261         
262         Map JavaDoc wsiMap = (Map JavaDoc)MBeanUtil.invoke(webServiceMgr, getWSNames, paramsArray , typesArray);
263
264         String JavaDoc[] modelNames = null;
265         if (modelNamesList != null) {
266             modelNames = (String JavaDoc[])modelNamesList.toArray(new String JavaDoc[modelNamesList.size()]);
267         }
268     DescriptorContainerView view = (DescriptorContainerView)handlerCtx.getView();
269         String JavaDoc type = (String JavaDoc)wsiMap.get("ServiceImplType");
270
271         for (int j=0; j< modelNames.length; j++) {
272                 String JavaDoc displayField = (String JavaDoc)displayNamesList.get(j);
273                 Object JavaDoc obj = wsiMap.get(modelNames[j]);
274                 String JavaDoc val = null;
275                 if (obj instanceof String JavaDoc) {
276                     val = (String JavaDoc)obj;
277                 } else if (obj instanceof Boolean JavaDoc) {
278                     val = obj.toString();
279                 }
280                 if (displayField.equals("name")) {
281                     val = displayName;
282                 } else if (displayField.equals("wsdl")||displayField.equals("mapping")) {
283                     if (val != null) {
284                         val = new File JavaDoc(val).getName();
285                     }
286                 } else if (displayField.equals("webservices")) {
287                     val = "webservices.xml";
288                 } else if (displayField.equals("j2eeDescriptor")) {
289                     if (type.equals("SERVLET")) {
290                         val = "web.xml";
291                     } else {
292                         val= "ejb-jar.xml";
293                     }
294                 } else if (displayField.equals("sunDescriptor")) {
295                     if (type.equals("SERVLET")) {
296                         val = "sun-web.xml";
297                     } else {
298                         val = "sun-ejb-jar.xml";
299                     }
300                 } else if (displayField.equals("implClass")) {
301                     if (val == null) {
302                         val = (String JavaDoc)wsiMap.get("ServiceImplName");
303                     }
304                 }
305                view.setDisplayFieldValue(displayField, val);
306         }
307        
308     }
309     
310     public void getDeploymentDescriptorLocation(RequestContext ctx, HandlerContext handlerCtx) {
311     String JavaDoc appName = (String JavaDoc)handlerCtx.getInputValue("application");
312         String JavaDoc moduleName = (String JavaDoc)handlerCtx.getInputValue("moduleName");
313         String JavaDoc isStandAlone = (String JavaDoc)handlerCtx.getInputValue("isStandAlone");
314         String JavaDoc implType = (String JavaDoc)handlerCtx.getInputValue("implType");
315         String JavaDoc descriptorType = (String JavaDoc)handlerCtx.getInputValue("descriptorType");
316         String JavaDoc descriptor = null;
317         
318         if (implType.equals("SERVLET")) {
319             if (descriptorType.equals("j2ee")) {
320                 descriptor = "web.xml";
321             } else {
322                 descriptor = "sun-web.xml";
323             }
324         } else {
325             if (descriptorType.equals("j2ee")) {
326                 descriptor = "ejb-jar.xml";
327             } else {
328                 descriptor = "sun-ejb-jar.xml";
329             }
330         }
331     
332     String JavaDoc[] descriptors = null;
333         String JavaDoc location = null;
334     
335         //load subcomponent descriptors for ear file
336
if(isStandAlone.equals("false")) {
337             String JavaDoc[] modules = (String JavaDoc[])MBeanUtil.invoke(
338                             "com.sun.appserv:type=applications,category=config",
339                             "getModuleComponents",
340                             new Object JavaDoc[]{appName},
341                             new String JavaDoc[]{"java.lang.String"});
342             if(modules != null) {
343                 for (int i=0; i < modules.length; i++) {
344                     try {
345                         String JavaDoc subComponentName = new ObjectName JavaDoc(modules[i]).getKeyProperty("name");
346                         
347                         if (subComponentName.equals(moduleName)) {
348                             descriptors = getDescriptors(appName, subComponentName);
349                             
350                             for(int j=0; descriptors != null && j < descriptors.length; j++) {
351                                 int index = descriptors[j].lastIndexOf(File.separator) +1;
352                                 String JavaDoc name = descriptors[j].substring(index);
353                                 if (name.equals(descriptor)) {
354                                     location = descriptors[j];
355                                     break;
356                                 }
357                             }
358                             break;
359                         }
360                     } catch (javax.management.MalformedObjectNameException JavaDoc e){
361                         e.printStackTrace();
362                     }
363                 }
364             }
365         } else {
366             descriptors = getDescriptors(appName, null);
367             for(int j=0; descriptors != null && j < descriptors.length; j++) {
368                 int index = descriptors[j].lastIndexOf(File.separator) +1;
369                 String JavaDoc name = descriptors[j].substring(index);
370                 if (name.equals(descriptor)) {
371                     location = descriptors[j];
372                     break;
373                 }
374             }
375         }
376         handlerCtx.setOutputValue("location", location);
377     }
378     
379     private String JavaDoc[] getDescriptors(String JavaDoc appName, String JavaDoc subComponent) {
380     String JavaDoc[] descriptors = (String JavaDoc[])MBeanUtil.invoke(
381                             "com.sun.appserv:type=applications,category=config",
382                             "getDeploymentDescriptorLocations",
383                             new Object JavaDoc[]{appName, subComponent},
384                             new String JavaDoc[]{"java.lang.String",
385                             "java.lang.String"});
386     return descriptors;
387     }
388
389     public void getWsEndpointObjectName(RequestContext ctx, HandlerContext handlerCtx) {
390         String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue("webServiceKeyName");
391         ObjectName JavaDoc webServiceMgr = (ObjectName JavaDoc)MBeanUtil.getAttribute(DOMAIN_ROOT_OBJ_NAME, WS_MGR_ATTR_NAME);
392         Object JavaDoc[] paramsArray = {key};
393         String JavaDoc[] typesArray = {"java.lang.Object"};
394         Map JavaDoc wsiMap = (Map JavaDoc)MBeanUtil.invoke(webServiceMgr, GETWSNAMES_METHOD, paramsArray , typesArray);
395         Boolean JavaDoc isStandAlone = (Boolean JavaDoc)wsiMap.get(IS_STANDALONE);
396         String JavaDoc appName = (String JavaDoc)wsiMap.get(APP_NAME);
397         String JavaDoc implType = (String JavaDoc)wsiMap.get(TYPE);
398         String JavaDoc type = "";
399         if (isStandAlone.booleanValue()) {
400             if (implType.equals(SERVLET_TYPE)) {
401                 type = WEB_MODULE;
402             } else {
403                 type = EJB_MODULE;
404             }
405         } else {
406             type = J2EE_APPLICATION;
407         }
408         String JavaDoc name = key.substring(key.indexOf('#') + 1);
409         String JavaDoc wsEndpointObjName = "com.sun.appserv:type=web-service-endpoint,name="
410                                     +name+","+type+"="+appName+",category=config";
411         handlerCtx.setOutputValue("wsEndpointObjectName", wsEndpointObjName);
412         
413         //create web-service-endpoint element if it doesn't exist
414
if (!MBeanUtil.isValidMBean(wsEndpointObjName)) {
415             AttributeList JavaDoc list = new AttributeList JavaDoc();
416             list.add(new Attribute JavaDoc("jbi-enabled", "true"));
417             list.add(new Attribute JavaDoc("max-history-size", "25"));
418             list.add(new Attribute JavaDoc("monitoring", "OFF"));
419             list.add(new Attribute JavaDoc("name", name));
420             Object JavaDoc[] params = {list};
421             String JavaDoc[] signature = {"javax.management.AttributeList"};
422             String JavaDoc objName = "com.sun.appserv:type="+type+",name="+appName+",category=config";
423             MBeanUtil.invoke(objName, "createWebServiceEndpoint", params, signature);
424         }
425     }
426     
427     public void getServerList(RequestContext ctx, HandlerContext handlerCtx) {
428     Set JavaDoc wsEndpointSet = (Set JavaDoc) handlerCtx.getInputValue("wsEndpointSet");
429         ArrayList JavaDoc serverRootList = new ArrayList JavaDoc();
430         Iterator JavaDoc it = wsEndpointSet.iterator();
431         while (it.hasNext()){
432             ObjectName JavaDoc wsEndpoint = (ObjectName JavaDoc) it.next();
433             ObjectName JavaDoc wsMonitor = (ObjectName JavaDoc) MBeanUtil.getAttribute(wsEndpoint, "MonitoringPeerObjectName");
434             if (wsMonitor != null){
435                 String JavaDoc serverRoot = wsMonitor.getKeyProperty("X-ServerRootMonitor");
436                 serverRootList.add(serverRoot);
437             }
438         }
439         String JavaDoc[] servers = (String JavaDoc[])(serverRootList.toArray(new String JavaDoc[serverRootList.size()]));
440         handlerCtx.setOutputValue("serverList", servers);
441     }
442     
443     public void getWsMonitorsList(RequestContext ctx, HandlerContext handlerCtx) {
444         
445     Set JavaDoc wsEndpointSet = (Set JavaDoc) handlerCtx.getInputValue("wsEndpointSet");
446         String JavaDoc selectedServer = (String JavaDoc) handlerCtx.getInputValue("selectedServer");
447         ArrayList JavaDoc wsMonitorsList = new ArrayList JavaDoc();
448         ArrayList JavaDoc serverRootList = new ArrayList JavaDoc();
449         Iterator JavaDoc it = wsEndpointSet.iterator();
450         while (it.hasNext()){
451             ObjectName JavaDoc wsEndpoint = (ObjectName JavaDoc) it.next();
452             ObjectName JavaDoc wsMonitor = (ObjectName JavaDoc) MBeanUtil.getAttribute(wsEndpoint, "MonitoringPeerObjectName");
453             if (wsMonitor != null){
454                 String JavaDoc serverRoot = wsMonitor.getKeyProperty("X-ServerRootMonitor");
455                 wsMonitorsList.add(wsMonitor);
456                 serverRootList.add(serverRoot);
457             }
458         }
459         
460         if (wsMonitorsList.size() != 0){
461             handlerCtx.setOutputValue("displayServer", (selectedServer==null) ? (String JavaDoc) serverRootList.get(0) : selectedServer);
462         }
463         handlerCtx.setOutputValue("wsMonitorsList", wsMonitorsList);
464         String JavaDoc[] test = (String JavaDoc[])(serverRootList.toArray(new String JavaDoc[serverRootList.size()]));
465         handlerCtx.setOutputValue("serverRoot", test);
466         handlerCtx.setOutputValue("hasMonitors", wsMonitorsList.size()==0 ? new Boolean JavaDoc("false") : new Boolean JavaDoc("true"));
467         
468     }
469     
470
471 public void loadWsStatisticsTable(RequestContext ctx, HandlerContext handlerCtx) {
472     
473     View view = handlerCtx.getView();
474         ViewDescriptor desc = null;
475         if (handlerCtx.getEvent() instanceof BeforeCreateEvent) {
476             desc = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor();
477     } else {
478             DescriptorContainerView descView = (DescriptorContainerView)
479                 (((ViewBase)view).getParentViewBean());
480             desc = descView.getViewDescriptor();
481         }
482         String JavaDoc bundle = "com.sun.enterprise.tools.admingui.resources.Resources";
483         List JavaDoc wsMonitorsList = (List JavaDoc)handlerCtx.getInputValue("wsMonitorsList");
484         String JavaDoc filter = (String JavaDoc) handlerCtx.getInputValue("filterValue");
485         
486         if (wsMonitorsList.size() == 0){
487             return;
488         }
489         
490         //filter out the preferred instance. If none is specified, just use DAS
491

492         if (Util.isEmpty(filter)){
493             filter = "server";
494         }
495         ObjectName JavaDoc wsMonitor = null;
496         for(int i=0; i<wsMonitorsList.size(); i++){
497             wsMonitor = (ObjectName JavaDoc) wsMonitorsList.get(i);
498             String JavaDoc nm = wsMonitor.getKeyProperty("X-ServerRootMonitor");
499             if (nm.equals(filter)){
500                 break;
501             }
502         }
503         if (wsMonitor == null) {
504             //can't find the one specified, Just use the first one.
505
wsMonitor = (ObjectName JavaDoc) wsMonitorsList.get(0);
506         }
507         
508         try {
509             CCActionTableModelInterface model = (CCActionTableModelInterface)handlerCtx.getInputValue("model");
510             if (model == null) {
511                 throw new FrameworkException("WebSErviceHandler.loadWsStatisticsTable: No Model Specified.", desc, view);
512             }
513             ((DefaultModel)model).clear();
514             model.beforeFirst();
515            
516             //Avg Response time
517
model.appendRow();
518             model.setValue("statistic", Util.getMessage("webServiceMonitorStatistics.lastRespTime"));
519             String JavaDoc[] lastR = { ""+MBeanUtil.getAttribute(wsMonitor, "ResponseTime_Count")};
520             model.setValue("value", Util.getMessage("webServiceMonitorStatistics.ms", lastR ));
521             
522             model.appendRow();
523             model.setValue("statistic", Util.getMessage("webServiceMonitorStatistics.avgRespTime"));
524             String JavaDoc[] tt = { ""+MBeanUtil.getAttribute(wsMonitor, "AverageResponseTime_Count")};
525             model.setValue("value", Util.getMessage("webServiceMonitorStatistics.ms", tt ));
526             
527             model.appendRow();
528             model.setValue("statistic", Util.getMessage("webServiceMonitorStatistics.minRespTime"));
529             String JavaDoc[] min = { ""+MBeanUtil.getAttribute(wsMonitor, "MinResponseTime_Count")};
530             model.setValue("value", Util.getMessage("webServiceMonitorStatistics.ms", min ));
531             
532             model.appendRow();
533             model.setValue("statistic", Util.getMessage("webServiceMonitorStatistics.maxRespTime"));
534             String JavaDoc[] max = { ""+MBeanUtil.getAttribute(wsMonitor, "MaxResponseTime_Count")};
535             model.setValue("value", Util.getMessage("webServiceMonitorStatistics.ms", max ));
536             
537             model.appendRow();
538             model.setValue("statistic", Util.getMessage("webServiceMonitorStatistics.Throughput"));
539             
540             Double JavaDoc dd = (Double JavaDoc) MBeanUtil.getAttribute(wsMonitor,"Throughput_Current");
541             NumberFormat JavaDoc numberformat = NumberFormat.getInstance();
542             numberformat.setMinimumFractionDigits(2);
543             String JavaDoc [] put = {numberformat.format(dd.doubleValue())};
544             model.setValue("value", Util.getMessage("webServiceMonitorStatistics.reqPerSec", put ));
545             
546             /* commented out for now till backend can give the correct data.
547             model.appendRow();
548             model.setValue("statistic", Util.getMessage("webServiceMonitorStatistics.AuthSuccess"));
549             model.setValue("value", ""+MBeanUtil.getAttribute(wsMonitor, "TotalAuthSuccesses_Count"));
550             
551             model.appendRow();
552             model.setValue("statistic", Util.getMessage("webServiceMonitorStatistics.AuthFailure"));
553             model.setValue("value", ""+MBeanUtil.getAttribute(wsMonitor, "TotalAuthFailures_Count"));
554             
555              */

556             model.appendRow();
557             model.setValue("statistic", Util.getMessage("webServiceMonitorStatistics.Faults"));
558             model.setValue("value", ""+MBeanUtil.getAttribute(wsMonitor, "TotalFaults_Count"));
559             
560             model.appendRow();
561             model.setValue("statistic", Util.getMessage("webServiceMonitorStatistics.totalSuccess"));
562             model.setValue("value", ""+MBeanUtil.getAttribute(wsMonitor, "TotalNumSuccess_Count"));
563             
564             
565         } catch (Exception JavaDoc ex) {
566             throw new FrameworkException("loadWsStatisticsTable: Loading error. ", ex, desc, view);
567         }
568     }
569
570     public void wsResetData(RequestContext ctx, HandlerContext handlerCtx) {
571         
572     String JavaDoc webServiceKey = (String JavaDoc) handlerCtx.getInputValue("webServiceKey");
573         String JavaDoc serverName = (String JavaDoc) handlerCtx.getInputValue("serverName");
574         ObjectName JavaDoc wsEndpoint = getWsEndpoint(webServiceKey, serverName);
575         
576         //If we invoke the method, there will be mbean exception without any stack trace or cause.
577
//we have to use dynamic proxies to get this to work.
578

579         /*
580         if (wsEndpoint != null){
581             MBeanUtil.invoke(wsEndpoint, RESET_STATS_METHOD, null, null);
582         }
583          */

584         
585         WebServiceMgr wsm = AMXUtil.getAMXProxyFactory().getDomainRoot().getWebServiceMgr();
586         Set JavaDoc endpointSet = wsm.getWebServiceEndpointSet((Object JavaDoc)webServiceKey, serverName);
587         if (!endpointSet.isEmpty()){ // should be only one.
588
Iterator JavaDoc it = endpointSet.iterator();
589             WebServiceEndpoint endpoint = (WebServiceEndpoint) it.next();
590             endpoint.resetStats();
591         }
592     }
593     
594     public void getWsLastResetTime(RequestContext ctx, HandlerContext handlerCtx) {
595     String JavaDoc webServiceKey = (String JavaDoc) handlerCtx.getInputValue("webServiceKey");
596         String JavaDoc serverName = (String JavaDoc) handlerCtx.getInputValue("serverName");
597         ObjectName JavaDoc wsEndpoint = (ObjectName JavaDoc) getWsEndpoint(webServiceKey, serverName);
598         if (wsEndpoint != null){
599             Long JavaDoc lastResetTime = (Long JavaDoc) MBeanUtil.getAttribute(wsEndpoint, "LastResetTime");
600             handlerCtx.setOutputValue("time", lastResetTime.toString());
601         }else
602             handlerCtx.setOutputValue("time", "");
603     }
604     
605      public void removeWsRTGraphFromSession(RequestContext ctx, HandlerContext handlerCtx) {
606     String JavaDoc suffix = (String JavaDoc) handlerCtx.getInputValue("suffix");
607 // System.out.println ("!!!!!!!!! suffix = " + suffix);
608
HttpSession JavaDoc session = ctx.getRequest().getSession();
609         session.removeAttribute("wsResponseTimeRTChart" + suffix);
610         session.removeAttribute("wsThroughputRTChart" + suffix);
611         session.removeAttribute("wsAuthRTChart" + suffix);
612         session.removeAttribute("wsCountRTChart" + suffix);
613     }
614     
615             
616     public void loadPublishTableModel(RequestContext ctx, HandlerContext handlerCtx) {
617         CCActionTableModelInterface model = (CCActionTableModelInterface)handlerCtx.getInputValue("tableModel");
618         ((DefaultModel)model).clear();
619         String JavaDoc webServiceKey = (String JavaDoc)handlerCtx.getInputValue("webServiceKey");
620         String JavaDoc registryCol = (String JavaDoc)handlerCtx.getInputValue("registryCol");
621         Map JavaDoc registryMap = getRegistryLocationConfigMap(webServiceKey);
622         if (registryMap != null && !registryMap.isEmpty()) {
623             for (Iterator JavaDoc iter = registryMap.values().iterator(); iter.hasNext();) {
624                 RegistryLocationConfig registry = (RegistryLocationConfig)iter.next();
625                 model.appendRow();
626                 model.setValue(registryCol, registry.getConnectorResourceJNDIName());
627             }
628         }
629     }
630     
631     
632     public void processWebServiceKeyName(RequestContext ctx, HandlerContext handlerCtx) {
633     String JavaDoc webServiceKey = (String JavaDoc) handlerCtx.getInputValue("key");
634         String JavaDoc replaceWith = (String JavaDoc) handlerCtx.getInputValue("replaceWith");
635         String JavaDoc converted = webServiceKey.replaceAll("@", replaceWith);
636         handlerCtx.setOutputValue("converted", converted);
637     }
638     
639     
640     
641     public void publishToRegistry(RequestContext ctx, HandlerContext handlerCtx) {
642         Object JavaDoc webServiceKey = (Object JavaDoc)handlerCtx.getInputValue("webServiceKey");
643         String JavaDoc childName = (String JavaDoc)handlerCtx.getInputValue("addRemoveChildName");
644         
645         View view = handlerCtx.getView();
646     DescriptorContainerView descView = (DescriptorContainerView)
647         (((ViewBase)view).getParentViewBean());
648         
649     ViewDescriptor vd = descView.getViewDescriptor();
650         ViewDescriptor propSheet = vd.getChildDescriptor("webServicePublishToRegistry");
651         ViewDescriptor desc = propSheet.getChildDescriptor(childName);
652         
653         CCAddRemoveDescriptor addRemoveDesc = ((CCAddRemoveDescriptor)desc);
654         CCAddRemove addRemoveChild = (CCAddRemove)addRemoveDesc.getView(ctx);
655         CCAddRemoveModelInterface model = addRemoveDesc.getModel();
656         OptionList selectedOptions = model.getSelectedOptionList(addRemoveChild);
657         if (selectedOptions == null) {
658             selectedOptions = model.getSelectedOptionList();
659         }
660         String JavaDoc[] registries = null;
661         if (selectedOptions != null) {
662             registries = new String JavaDoc[selectedOptions.size()];
663             for (int i = 0; i < registries.length; i++) {
664                 registries[i] = selectedOptions.getValue(i);
665             }
666         }
667         
668         if (registries != null && registries.length > 0) {
669             String JavaDoc lbhost = (String JavaDoc)handlerCtx.getInputValue("lbhost");
670             String JavaDoc lbport = (String JavaDoc)handlerCtx.getInputValue("lbport");
671             String JavaDoc lbsslport = (String JavaDoc)handlerCtx.getInputValue("lbsslport");
672             String JavaDoc categories = (String JavaDoc)handlerCtx.getInputValue("categories");
673             String JavaDoc description = (String JavaDoc)handlerCtx.getInputValue("description");
674             String JavaDoc organization = (String JavaDoc)handlerCtx.getInputValue("organization");
675             HashMap JavaDoc map = new HashMap JavaDoc();
676             map.put(WebServiceMgr.LB_HOST_KEY, lbhost);
677             map.put(WebServiceMgr.LB_PORT_KEY, lbport);
678             map.put(WebServiceMgr.LB_SECURE_PORT, lbsslport);
679             map.put(WebServiceMgr.CATEGORIES_KEY, categories);
680             map.put(WebServiceMgr.DESCRIPTION_KEY, description);
681             map.put(WebServiceMgr.ORGANIZATION_KEY, organization);
682             WebServiceMgr wsm = (WebServiceMgr)AMXUtil.getDomainRoot().getWebServiceMgr();
683             wsm.publishToRegistry(registries, webServiceKey, map);
684         }
685     }
686     
687     public void unpublishFromRegistry(RequestContext ctx, HandlerContext handlerCtx) {
688         CCActionTableModelInterface model = (CCActionTableModelInterface)handlerCtx.getInputValue("tableModel");
689         Object JavaDoc webServiceKey = (Object JavaDoc)handlerCtx.getInputValue("webServiceKey");
690         String JavaDoc registryCol = (String JavaDoc)handlerCtx.getInputValue("registryCol");
691         String JavaDoc[] registries = null;
692         try {
693             registries = getSelectedRows(registryCol, model);
694         } catch (com.iplanet.jato.model.ModelControlException mce) {
695             ViewDescriptor vd = handlerCtx.getViewDescriptor();
696             String JavaDoc childName = (String JavaDoc)vd.getParameter("tableChildName");
697             ViewDescriptor tableDescriptor = vd.getChildDescriptor(childName);
698             throw new FrameworkException("Error while unpublishing: '"+
699         webServiceKey.toString()+"from " + model.getValue(registryCol).toString()+ "'", mce, tableDescriptor, null);
700         }
701         WebServiceMgr wsm = (WebServiceMgr)AMXUtil.getDomainRoot().getWebServiceMgr();
702         wsm.unpublishFromRegistry(registries, webServiceKey);
703     }
704     
705     public void setAddRemoveAvailableRegistriesList(RequestContext ctx, HandlerContext handlerCtx) {
706         ViewDescriptor vd = vd = handlerCtx.getViewDescriptor();
707         WebServiceMgr wsm = (WebServiceMgr)AMXUtil.getDomainRoot().getWebServiceMgr();
708         String JavaDoc[] registries = wsm.listRegistryLocations();
709         if (registries != null && registries.length > 0) {
710
711             CCAddRemoveDescriptor addRemoveDesc = (CCAddRemoveDescriptor)vd;
712             CCAddRemoveModelInterface model = addRemoveDesc.getModel();
713             model.setAvailableOptionList(new OptionList(registries, registries));
714         }
715     }
716     
717     public void loadRegistriesTableModel(RequestContext ctx, HandlerContext handlerCtx) {
718         CCActionTableModelInterface model = (CCActionTableModelInterface)handlerCtx.getInputValue("tableModel");
719         ((DefaultModel)model).clear();
720         WebServiceMgr wsm = (WebServiceMgr)AMXUtil.getDomainRoot().getWebServiceMgr();
721         
722         String JavaDoc[] registries = wsm.listRegistryLocations();
723         if (registries != null) {
724             for (int i=0; i < registries.length; i++) {
725                 model.appendRow();
726                 model.setValue("registryName", registries[i]);
727             }
728         }
729     }
730     
731     public void addRegistry(RequestContext ctx, HandlerContext handlerCtx) {
732         String JavaDoc jndiName = (String JavaDoc)handlerCtx.getInputValue("jndiName");
733         String JavaDoc registryType = (String JavaDoc)handlerCtx.getInputValue("registryType");
734         String JavaDoc publishURL = (String JavaDoc)handlerCtx.getInputValue("publishURL");
735         String JavaDoc queryURL = (String JavaDoc)handlerCtx.getInputValue("queryURL");
736         String JavaDoc userName = (String JavaDoc)handlerCtx.getInputValue("userName");
737         String JavaDoc password = (String JavaDoc)handlerCtx.getInputValue("password");
738         String JavaDoc description = (String JavaDoc)handlerCtx.getInputValue("description");
739         Map JavaDoc map = new HashMap JavaDoc();
740     String JavaDoc type = WebServiceMgr.EBXML_KEY;
741     if (registryType.equalsIgnoreCase (WebServiceMgr.UDDI_KEY)){
742         type = WebServiceMgr.UDDI_KEY;
743     } else {
744         type = WebServiceMgr.EBXML_KEY;
745     }
746         map.put(WebServiceMgr.PUBLISH_URL_KEY, publishURL);
747         if (!Util.isEmpty(queryURL)) {
748             map.put(WebServiceMgr.QUERY_URL_KEY, queryURL);
749         }
750         if (!Util.isEmpty(userName)) {
751             map.put(WebServiceMgr.USERNAME_KEY, userName);
752         }
753         if (!Util.isEmpty(password)) {
754             map.put(WebServiceMgr.PASSWORD_KEY, password);
755         }
756         WebServiceMgr wsm = (WebServiceMgr)AMXUtil.getDomainRoot().getWebServiceMgr();
757         wsm.addRegistryConnectionResources(jndiName, description, type, map);
758     }
759     
760     public void removeSelectedRegistries(RequestContext ctx, HandlerContext handlerCtx) throws ModelControlException {
761         CCActionTableModelInterface model = (CCActionTableModelInterface)handlerCtx.getInputValue("tableModel");
762         String JavaDoc[] selectedRegistries = getSelectedRows("registryName", model);
763         WebServiceMgr wsm = (WebServiceMgr)AMXUtil.getDomainRoot().getWebServiceMgr();
764         for (int i=0;i < selectedRegistries.length; i++) {
765             wsm.removeRegistryConnectionResources(selectedRegistries[i]); //TODO Pass String[] instead of String
766
}
767     }
768     
769     public void loadTransformationRulesTableModel(RequestContext ctx, HandlerContext handlerCtx) {
770         String JavaDoc webServiceKey = (String JavaDoc)handlerCtx.getInputValue("webServiceKey");
771         CCActionTableModelInterface model = (CCActionTableModelInterface)handlerCtx.getInputValue("tableModel");
772         ((DefaultModel)model).clear();
773         List JavaDoc ruleList = getTransformationRuleConfigList(webServiceKey);
774         if (ruleList != null && !ruleList.isEmpty()) {
775             for (Iterator JavaDoc iter = ruleList.iterator(); iter.hasNext();) {
776                 TransformationRuleConfig rule = (TransformationRuleConfig)iter.next();
777                 model.appendRow();
778                 model.setValue("ruleName", rule.getName());
779                 if (rule.getEnabled()) {
780                     model.setValue("ruleStatus", Util.getMessage("common.Enabled"));
781                 } else {
782                     model.setValue("ruleStatus", Util.getMessage("common.Disabled"));
783                 }
784                 model.setValue("ruleFile", rule.getRuleFileLocation());
785                 model.setValue("applyTo", rule.getApplyTo());
786             }
787         }
788     }
789     
790     public void applyTransformationRulesTableAction(RequestContext ctx, HandlerContext handlerCtx) {
791         String JavaDoc webServiceKey = (String JavaDoc)handlerCtx.getInputValue("webServiceKey");
792         String JavaDoc ruleNameCol = (String JavaDoc)handlerCtx.getInputValue("ruleNameCol");
793         String JavaDoc action = (String JavaDoc)handlerCtx.getInputValue("action");
794         CCActionTableModelInterface model = (CCActionTableModelInterface)handlerCtx.getInputValue("tableModel");
795         String JavaDoc[] rules = null;
796         try {
797             rules = getSelectedRows(ruleNameCol, model);
798         } catch (com.iplanet.jato.model.ModelControlException mce) {
799             ViewDescriptor vd = handlerCtx.getViewDescriptor();
800             String JavaDoc childName = (String JavaDoc)vd.getParameter("tableChildName");
801             ViewDescriptor tableDescriptor = vd.getChildDescriptor(childName);
802             throw new FrameworkException("Error while getting selected transformation rules: '"+
803         model.getValue(ruleNameCol).toString()+ "'", mce, tableDescriptor, null);
804         }
805         WebServiceEndpointConfig endpointConfig = getWebServiceEndpointConfig(webServiceKey);
806         if (endpointConfig != null) {
807             Map JavaDoc ruleMap = endpointConfig.getTransformationRuleConfigMap();
808             if (action.equals("enable")) {
809                 for (int i=0; i < rules.length; i++) {
810                     TransformationRuleConfig rule = (TransformationRuleConfig)ruleMap.get(rules[i]);
811                     rule.setEnabled(true);
812                 }
813             } else if (action.equals("disable")) {
814                 for (int i=0; i < rules.length; i++) {
815                     TransformationRuleConfig rule = (TransformationRuleConfig)ruleMap.get(rules[i]);
816                     rule.setEnabled(false);
817                 }
818             } else if (action.equals("remove")) {
819                 for (int i=0; i < rules.length; i++) {
820                     endpointConfig.removeTransformationRuleConfig(rules[i]);
821                 }
822             }
823         }
824     }
825     
826     private String JavaDoc[] getSelectedRows(String JavaDoc col, CCActionTableModelInterface model)
827             throws com.iplanet.jato.model.ModelControlException {
828         ArrayList JavaDoc arrList = new ArrayList JavaDoc();
829         model.setSelectionType("multiple");
830         model.beforeFirst();
831         while(model.next()) {
832             if (model.isRowSelected()) {
833                 arrList.add(model.getValue(col).toString());
834             }
835         }
836         return (String JavaDoc[])arrList.toArray(new String JavaDoc[arrList.size()]);
837     }
838     
839     public void getWebServiceDisplayName(RequestContext ctx, HandlerContext handlerCtx) {
840         Object JavaDoc webServiceKey = (Object JavaDoc)handlerCtx.getInputValue("webServiceKey");
841         WebServiceMgr wsm = (WebServiceMgr)AMXUtil.getDomainRoot().getWebServiceMgr();
842         String JavaDoc name = (String JavaDoc)wsm.getWebServiceEndpointKeys().get(webServiceKey);
843         handlerCtx.setOutputValue("webServiceName", name);
844     }
845     
846     public void isStandAlone(RequestContext ctx, HandlerContext handlerCtx) {
847         Object JavaDoc webServiceKey = (Object JavaDoc)handlerCtx.getInputValue("webServiceKey");
848         WebServiceMgr wsm = (WebServiceMgr)AMXUtil.getDomainRoot().getWebServiceMgr();
849         final WebServiceEndpointInfo wsi = wsm.getWebServiceEndpointInfo(webServiceKey);
850         handlerCtx.setOutputValue("isStandAlone", "" + wsi.isAppStandaloneModule() );
851     }
852     
853     public void getAppID(RequestContext ctx, HandlerContext handlerCtx) {
854         Object JavaDoc webServiceKey = (Object JavaDoc)handlerCtx.getInputValue("webServiceKey");
855         WebServiceMgr wsm = (WebServiceMgr)AMXUtil.getDomainRoot().getWebServiceMgr();
856         final WebServiceEndpointInfo info = wsm.getWebServiceEndpointInfo(webServiceKey);
857         handlerCtx.setOutputValue("appID", "" + info.getAppID());
858     }
859     
860     public void isSecure(RequestContext ctx, HandlerContext handlerCtx) {
861         Object JavaDoc webServiceKey = (Object JavaDoc)handlerCtx.getInputValue("webServiceKey");
862         WebServiceMgr wsm = (WebServiceMgr)AMXUtil.getDomainRoot().getWebServiceMgr();
863         final WebServiceEndpointInfo info = wsm.getWebServiceEndpointInfo(webServiceKey);
864         handlerCtx.setOutputValue("isSecure", info.isSecure());
865     }
866     
867     public void getFileContent(RequestContext ctx, HandlerContext handlerCtx) {
868         Object JavaDoc webServiceKey = (Object JavaDoc)handlerCtx.getInputValue("webServiceKey");
869         
870         final String JavaDoc fileKey = (String JavaDoc)handlerCtx.getInputValue("fileKey");
871         
872         final WebServiceMgr wsm = AMXUtil.getDomainRoot().getWebServiceMgr();
873         final WebServiceEndpointInfo info = wsm.getWebServiceEndpointInfo(webServiceKey);
874         
875         final Map JavaDoc<String JavaDoc,java.io.Serializable JavaDoc> wsiMap = info.asMap();
876         
877         String JavaDoc content = (String JavaDoc)wsiMap.get(fileKey);
878         String JavaDoc type = info.getServiceImplType();
879         if (fileKey.equals("j2eeDescriptorFile")) {
880             if (type.equals("SERVLET")) {
881                 content = info.getWebXML();
882             } else {
883                 content = info.getEJBXML();
884             }
885         } else if (fileKey.equals("sunDescriptorFile")) {
886             if (type.equals("SERVLET")) {
887                 content = info.getSunWebXML();
888             } else {
889                 content = info.getSunEJBXML();
890             }
891         }
892         handlerCtx.setOutputValue("fileContent", content);
893     }
894     
895     private ObjectName JavaDoc getWsEndpoint(String JavaDoc webServiceKey, String JavaDoc serverName){
896         Object JavaDoc[] params = {webServiceKey, serverName};
897         String JavaDoc[] types={"java.lang.Object", "java.lang.String"};
898         Set JavaDoc endpointSet = (Set JavaDoc) MBeanUtil.invoke(WS_MGR_OBJ_NAME, GETWSENDPOINTSET_METHOD, params, types );
899         Iterator JavaDoc it = endpointSet.iterator();
900         return (endpointSet.isEmpty() ? null : (ObjectName JavaDoc)it.next());
901         
902     }
903     
904     private static Map JavaDoc getWebServiceEndpointInfoMap(String JavaDoc key) {
905         ObjectName JavaDoc webServiceMgr = (ObjectName JavaDoc)MBeanUtil.getAttribute(DOMAIN_ROOT_OBJ_NAME, WS_MGR_ATTR_NAME);
906         Object JavaDoc[] paramsArray = {key};
907         String JavaDoc[] typesArray = {"java.lang.Object"};
908         Map JavaDoc wsiMap = (Map JavaDoc)MBeanUtil.invoke(webServiceMgr, GETWSNAMES_METHOD, paramsArray , typesArray);
909         return wsiMap;
910     }
911
912     private static Object JavaDoc getWebServiceAttribute(String JavaDoc key, String JavaDoc attribute) {
913         ObjectName JavaDoc webServiceMgr = (ObjectName JavaDoc)MBeanUtil.getAttribute(DOMAIN_ROOT_OBJ_NAME, WS_MGR_ATTR_NAME);
914         Object JavaDoc[] paramsArray = {key};
915         String JavaDoc[] typesArray = {"java.lang.Object"};
916         Map JavaDoc wsiMap = (Map JavaDoc)MBeanUtil.invoke(webServiceMgr, GETWSNAMES_METHOD, paramsArray , typesArray);
917         return wsiMap.get(attribute);
918     }
919     
920     private static RegistryLocationConfig getRegistryLocationConfig(String JavaDoc webServiceKey, String JavaDoc registryName) {
921         return (RegistryLocationConfig)getRegistryLocationConfigMap(webServiceKey).get(registryName);
922     }
923     
924     private static Map JavaDoc getRegistryLocationConfigMap(String JavaDoc webServiceKey) {
925         WebServiceEndpointConfig wseConfig = getWebServiceEndpointConfig(webServiceKey);
926         return wseConfig == null ? null : wseConfig.getRegistryLocationConfigMap();
927     }
928     
929     public static TransformationRuleConfig createTransformationRuleConfig(String JavaDoc webServiceKey, String JavaDoc ruleName, boolean enabled, String JavaDoc applyTo, String JavaDoc ruleFileLocation, Map JavaDoc map) {
930         WebServiceEndpointConfig wseConfig = getWebServiceEndpointConfig(webServiceKey);
931     if (wseConfig == null) {
932             wseConfig = createWebServiceEndpointConfig(webServiceKey);
933         }
934         
935         return wseConfig.createTransformationRuleConfig(ruleName, ruleFileLocation, enabled, applyTo, map);
936     }
937     
938     private static TransformationRuleConfig getTransformationRuleConfig(String JavaDoc webServiceKey, String JavaDoc ruleKey) {
939         return (TransformationRuleConfig)getTransformationRuleConfigMap(webServiceKey).get(ruleKey);
940     }
941     
942     private static Map JavaDoc getTransformationRuleConfigMap(String JavaDoc webServiceKey) {
943         WebServiceEndpointConfig wseConfig = getWebServiceEndpointConfig(webServiceKey);
944         return wseConfig == null ? null : wseConfig.getTransformationRuleConfigMap();
945     }
946     
947     private static List JavaDoc getTransformationRuleConfigList(String JavaDoc webServiceKey) {
948         WebServiceEndpointConfig wseConfig = getWebServiceEndpointConfig(webServiceKey);
949         return wseConfig == null ? null : wseConfig.getTransformationRuleConfigList();
950     }
951     
952     private static WebServiceEndpointConfig createWebServiceEndpointConfig(String JavaDoc webServiceKey) {
953         Map JavaDoc m = getAMXWebServiceInfo(webServiceKey);
954         String JavaDoc appJ2EEType = (String JavaDoc)m.get(J2EE_TYPE);
955         String JavaDoc appName = (String JavaDoc)m.get(APPL_NAME);
956         String JavaDoc name = (String JavaDoc)m.get(WS_NAME);
957         String JavaDoc appConfigObjName =
958             AMX.JMX_DOMAIN + ":" +
959             AMX.J2EE_TYPE_KEY + "=" + appJ2EEType + "," +
960             AMX.NAME_KEY + "=" + appName;
961         Set JavaDoc appConfigSet = null;
962         QueryMgr queryMgr = AMXUtil.getQueryMgr();
963         try {
964             appConfigSet = queryMgr.queryPatternSet(new ObjectName JavaDoc(appConfigObjName));
965         } catch (javax.management.MalformedObjectNameException JavaDoc e) {
966             e.printStackTrace();
967         }
968         if (appConfigSet.size() > 1) {
969             throw new RuntimeException JavaDoc("More than 1 MBean returned from QueryMgr.queryPatternSet("+appConfigObjName+")");
970         }
971         if (appConfigSet.size() == 0) {
972             throw new RuntimeException JavaDoc("No MBean returned from QueryMgr.queryPatternSet("+appConfigObjName+") for application " + appName);
973         }
974         Iterator JavaDoc it = appConfigSet.iterator();
975         Object JavaDoc config = null;
976         if (it.hasNext()) {
977             config = it.next();
978         }
979         WebServiceEndpointConfig wec = null;
980         if (config instanceof J2EEApplicationConfig) {
981             wec = ((J2EEApplicationConfig)config).createWebServiceEndpointConfig(name, null);
982         } else if (config instanceof WebModuleConfig) {
983             wec = ((WebModuleConfig)config).createWebServiceEndpointConfig(name, null);
984         } else if (config instanceof EJBModuleConfig) {
985             wec = ((EJBModuleConfig)config).createWebServiceEndpointConfig(name, null);
986         }
987         return wec;
988     }
989     
990     private static WebServiceEndpointConfig getWebServiceEndpointConfig(String JavaDoc webServiceKey) {
991         Map JavaDoc m = getAMXWebServiceInfo(webServiceKey);
992         String JavaDoc appJ2EEType = (String JavaDoc)m.get(J2EE_TYPE);
993         String JavaDoc appName = (String JavaDoc)m.get(APPL_NAME);
994         String JavaDoc name = (String JavaDoc)m.get(WS_NAME);
995         String JavaDoc wsEndpointConfigObjName =
996                 AMX.JMX_DOMAIN + ":" +
997                 appJ2EEType + "=" + appName + "," +
998                 AMX.J2EE_TYPE_KEY + "=" + WebServiceEndpointConfig.J2EE_TYPE + "," +
999                 AMX.NAME_KEY + "=" + name;
1000        QueryMgr queryMgr = AMXUtil.getQueryMgr();
1001        Set JavaDoc amxSet = null;
1002        try {
1003            amxSet = queryMgr.queryPatternSet(new ObjectName JavaDoc(wsEndpointConfigObjName));
1004        } catch (javax.management.MalformedObjectNameException JavaDoc e) {
1005            e.printStackTrace();
1006        }
1007        if (amxSet.size() > 1) {
1008            throw new RuntimeException JavaDoc("More than 1 MBean returned from QueryMgr.queryPatternSet("+wsEndpointConfigObjName+")");
1009        }
1010        Iterator JavaDoc it = amxSet.iterator();
1011        WebServiceEndpointConfig wec = null;
1012        if (it.hasNext()) {
1013            wec = (WebServiceEndpointConfig)it.next();
1014        }
1015        return wec;
1016    }
1017    
1018    private static Map JavaDoc getAMXWebServiceInfo(String JavaDoc webServiceKey) {
1019        Map JavaDoc m = getWebServiceEndpointInfoMap(webServiceKey);
1020        Boolean JavaDoc isStandAlone = (Boolean JavaDoc)m.get(WebServiceEndpointInfo.IS_STAND_ALONE_MODULE_KEY);
1021        String JavaDoc implType = (String JavaDoc)m.get(WebServiceEndpointInfo.SERVICE_IMPL_TYPE_KEY);
1022        String JavaDoc appName = (String JavaDoc)m.get(WebServiceEndpointInfo.APP_ID_KEY);
1023        String JavaDoc name = (String JavaDoc)webServiceKey.substring(webServiceKey.indexOf('#') + 1);
1024        String JavaDoc appJ2EEType = null;
1025        if (isStandAlone.booleanValue()) {
1026            if (implType.equals(WebServiceEndpointInfo.SERVLET_IMPL)) {
1027                appJ2EEType = WebModuleConfig.J2EE_TYPE;
1028            } else if (implType.equals(WebServiceEndpointInfo.EJB_IMPL)) {
1029                appJ2EEType = EJBModuleConfig.J2EE_TYPE;
1030            }
1031        } else {
1032            appJ2EEType = J2EEApplicationConfig.J2EE_TYPE;
1033        }
1034        Map JavaDoc map = new HashMap JavaDoc();
1035        map.put(APPL_NAME, appName);
1036        map.put(WS_NAME, name);
1037        map.put(J2EE_TYPE, appJ2EEType);
1038        return map;
1039    }
1040    
1041    public static final String JavaDoc DOMAIN_ROOT_OBJ_NAME = "amx:j2eeType=X-DomainRoot,name=amx";
1042    public static final String JavaDoc WS_MGR_ATTR_NAME = "WebServiceMgrObjectName";
1043    public static final String JavaDoc WS_MGR_OBJ_NAME = "amx:j2eeType=X-WebServiceMgr,name=na";
1044    public static final String JavaDoc GETWSNAMES_METHOD = "getWebServiceEndpointInfo";
1045    public static final String JavaDoc WSNAMESMAP_ATTR_NAME = "WebServiceEndpointKeys";
1046    public static final String JavaDoc GETWSENDPOINTSET_METHOD = "getWebServiceEndpointObjectNameSet";
1047    public static final String JavaDoc RESET_STATS_METHOD = "resetStats";
1048    
1049    public static final String JavaDoc APP_CONFIG_OBJ_NAME = "com.sun.appserv:type=applications,category=config";
1050    public static final String JavaDoc IS_STANDALONE = "IsAppStandAloneModule";
1051    public static final String JavaDoc TYPE = "ServiceImplType";
1052    public static final String JavaDoc APP_NAME = "AppID";
1053    public static final String JavaDoc SERVLET_TYPE = "SERVLET";
1054    public static final String JavaDoc J2EE_APPLICATION = "j2ee-application";
1055    public static final String JavaDoc WEB_MODULE = "web-module";
1056    public static final String JavaDoc EJB_MODULE = "ejb-module";
1057    
1058    private static final String JavaDoc J2EE_TYPE = "j2eeType";
1059    private static final String JavaDoc APPL_NAME = "appName";
1060    private static final String JavaDoc WS_NAME = "wsName";
1061}
1062
Popular Tags