1 23 package com.sun.enterprise.admin.wsmgmt.lifecycle; 24 25 import java.util.Set ; 26 import java.util.Collection ; 27 import java.util.HashSet ; 28 import java.util.Iterator ; 29 30 import com.sun.enterprise.admin.monitor.WSMonitorLifeCycleProvider; 31 import com.sun.enterprise.admin.monitor.WSMonitorLifeCycleFactory; 32 33 import com.sun.enterprise.admin.wsmgmt.config.spi.WebServiceConfig; 34 import com.sun.enterprise.admin.wsmgmt.config.spi.ConfigFactory; 35 import com.sun.enterprise.admin.wsmgmt.config.spi.ConfigProvider; 36 import com.sun.enterprise.admin.wsmgmt.config.impl.WebServiceConfigImpl; 37 import com.sun.enterprise.admin.wsmgmt.config.impl.AppServConfigProvider; 38 39 import com.sun.enterprise.admin.wsmgmt.transform.TransformMgr; 40 41 import com.sun.enterprise.deployment.Application; 42 import com.sun.enterprise.deployment.BundleDescriptor; 43 import com.sun.enterprise.deployment.WebBundleDescriptor; 44 import com.sun.enterprise.deployment.EjbBundleDescriptor; 45 import com.sun.enterprise.deployment.WebService; 46 import com.sun.enterprise.config.serverbeans.WebServiceEndpoint; 47 import com.sun.enterprise.config.serverbeans.J2eeApplication; 48 import com.sun.enterprise.config.serverbeans.ServerHelper; 49 import com.sun.enterprise.config.serverbeans.Server; 50 import com.sun.enterprise.config.serverbeans.EjbModule; 51 import com.sun.enterprise.config.serverbeans.WebModule; 52 import com.sun.enterprise.config.serverbeans.ApplicationRef; 53 import com.sun.enterprise.config.ConfigBean; 54 import com.sun.enterprise.config.ConfigException; 55 import com.sun.enterprise.admin.wsmgmt.WebServiceMgrBackEnd; 56 import com.sun.enterprise.admin.monitor.registry.MonitoringLevel; 57 import com.sun.enterprise.admin.monitor.registry.MonitoringRegistrationException; 58 import com.sun.enterprise.server.ApplicationServer; 59 import com.sun.enterprise.server.ServerContext; 60 import com.sun.enterprise.instance.AppsManager; 61 import com.sun.enterprise.instance.InstanceEnvironment; 62 63 import java.util.logging.Logger ; 64 import java.util.logging.Level ; 65 import com.sun.logging.LogDomains; 66 import com.sun.enterprise.util.i18n.StringManager; 67 68 72 public class AppServWSMonitorLifeCycleProvider implements WSMonitorLifeCycleProvider { 73 74 public AppServWSMonitorLifeCycleProvider() { 75 try { 76 cfgProv = ConfigFactory.getConfigFactory().getConfigProvider(); 77 InstanceEnvironment ienv = 78 ApplicationServer.getServerContext().getInstanceEnvironment(); 79 appsMgr = new AppsManager(ienv); 80 } catch (Exception e) { 81 _logger.fine(" Exception during initialization of AppServWSMonitorLifeCycleProvider " + e.getMessage()); 82 } 84 } 85 86 91 public String getProviderID() { 92 return WSMonitorLifeCycleFactory.WSMGMT_DEFAULT_PROVIDER; 93 } 94 95 100 void instrumentWebServiceEndpoints(String appId, BundleDescriptor bd, 101 boolean shouldRegister) { 102 103 boolean isEjb = false; 104 boolean isStandAlone = false; 105 String modName = null; 106 String ctxRoot = null; 107 String vs = WebServiceMgrBackEnd.DEFAULT_VIRTUAL_SERVER; 108 Server server = null; 109 try { 110 ServerContext sCtx = ApplicationServer.getServerContext(); 111 server = ServerHelper.getServerByName(sCtx.getConfigContext(), 112 sCtx.getInstanceName()); 113 ApplicationRef aRef = server.getApplicationRefByRef(appId); 114 if (aRef != null) { 115 vs = aRef.getVirtualServers(); 116 if ((vs == null) || ( vs.length() == 0)) { 117 vs = WebServiceMgrBackEnd.DEFAULT_VIRTUAL_SERVER; 118 } 119 } else { 120 throw new IllegalArgumentException (); 121 } 122 } catch( Exception e) { 123 throw new RuntimeException (e); 124 } 125 126 modName = bd.getModuleDescriptor().getArchiveUri(); 127 128 if ( bd instanceof EjbBundleDescriptor ) { 129 isEjb = true; 130 } else if ( bd instanceof WebBundleDescriptor ) { 131 isEjb = false; 132 ctxRoot = ((WebBundleDescriptor) bd).getContextRoot(); 133 } else { 134 return; 135 } 136 137 Application app = bd.getApplication(); 138 if ( app == null) { 139 String msg = _stringMgr.getString("Application_NotFound", appId); 140 throw new RuntimeException (msg); 141 } 142 isStandAlone = app.isVirtual(); 143 144 Collection wsCollec = bd.getWebServices().getWebServices(); 145 Set wsSet = new HashSet (); 146 for (Iterator i1 = wsCollec.iterator(); i1.hasNext();) { 147 WebService ws = (WebService) i1.next(); 148 wsSet.addAll(ws.getEndpoints()); 149 } 150 for (Iterator i2 = wsSet.iterator(); i2.hasNext();) { 151 com.sun.enterprise.deployment.WebServiceEndpoint wse = 152 (com.sun.enterprise.deployment.WebServiceEndpoint) i2.next(); 153 String epName = wse.getEndpointName(); 154 if ( shouldRegister == true ) { 155 instrument( epName, modName, ctxRoot, isStandAlone, appId, 156 isEjb, vs); 157 } else { 158 uninstrument( epName, modName, ctxRoot, isStandAlone, appId, 159 isEjb, vs); 160 } 161 } 162 } 163 164 169 public void unregisterWebServiceEndpoints(String appId, 170 BundleDescriptor bd) { 171 instrumentWebServiceEndpoints(appId, bd, false); 172 } 173 174 179 public void registerWebServiceEndpoints(String appId,BundleDescriptor bd) { 180 instrumentWebServiceEndpoints(appId, bd, true); 181 } 182 183 190 void instrument(String endpoint, String modName, String ctxRoot, 191 boolean isStandAlone, String appId, boolean isEjbModule, String vs) { 192 193 WebServiceConfigImpl wsConfig = (WebServiceConfigImpl) cfgProv. 194 getWebServiceConfig( appId, modName, isStandAlone, endpoint) ; 195 196 if (wsConfig == null) { 197 return; 198 } 199 if (isStandAlone) { 200 modName = appId; 201 appId = null; 202 } 203 204 TransformMgr.getInstance().init(appId, wsConfig); 205 206 try { 207 new MonitoringLifeCycleImpl().initializeMonitoring(appId, 208 modName, ctxRoot, isStandAlone, isEjbModule, vs, wsConfig); 209 } catch ( Exception e) { 210 _logger.fine("Exception during monitoring initialization " + 212 e.getMessage()); 213 } 214 } 215 216 223 void uninstrument(String endpoint, String modName, String ctxRoot, 224 boolean isStandAlone, 225 String appId, boolean isEjbModule, String vs) { 226 227 WebServiceConfigImpl wsConfig = (WebServiceConfigImpl) cfgProv. 228 getWebServiceConfig(appId, modName, isStandAlone, endpoint) ; 229 230 if (wsConfig == null) { 231 return; 232 } 233 if (isStandAlone) { 234 modName = appId; 235 appId = null; 236 } 237 238 TransformMgr.getInstance().stop(appId, wsConfig); 239 240 try { 241 new MonitoringLifeCycleImpl().uninitializeMonitoring(appId, 242 modName, ctxRoot, isStandAlone, isEjbModule, vs, wsConfig); 243 } catch ( Exception e) { 244 _logger.fine("Exception during monitoring shutdown " + 246 e.getMessage()); 247 } 248 } 249 250 public void reconfigureMonitoring(WebServiceEndpoint ep, String appId, 251 MonitoringLevel oldLevel, MonitoringLevel newLevel) throws MonitoringRegistrationException { 252 253 if ( ep == null) { 254 return; 255 } 256 257 boolean isEjb = false; 258 boolean isStandAlone = false; 259 String modName = null; 260 String ctxRoot = null; 261 String appName = null; 262 String epName = null; 263 String vs = WebServiceMgrBackEnd.DEFAULT_VIRTUAL_SERVER; 264 265 ConfigBean parent = (ConfigBean) ep.parent(); 266 if (parent instanceof J2eeApplication) { 267 isStandAlone = false; 268 appName = appId; 269 modName = 270 WebServiceMgrBackEnd.getManager().getModuleName(ep.getName()); 271 if (modName.endsWith("jar")) { 273 isEjb = true; 274 } else { 275 if (appsMgr != null) { 276 Application app = null; 277 try { 278 app = appsMgr.getDescriptor(appId); 279 } catch (ConfigException ce) { 280 } 282 if (app != null) { 283 WebBundleDescriptor wbd 284 = app.getWebBundleDescriptorByUri(modName); 285 if (wbd != null) { 286 ctxRoot = wbd.getContextRoot(); 287 } 288 } 289 } 290 } 291 } else if (parent instanceof WebModule) { 292 isStandAlone = true; 293 appName = null; 294 modName = appId; 295 ctxRoot = ((WebModule) parent).getContextRoot(); 296 } else if (parent instanceof EjbModule) { 297 isStandAlone = true; 298 isEjb = true; 299 appName = null; 300 modName = appId; 301 } 302 epName= WebServiceMgrBackEnd.getManager().getEndpointName(ep.getName()); 303 304 new MonitoringLifeCycleImpl().instrumentMonitoring(epName, 305 modName, ctxRoot, isStandAlone, vs, appName, 306 oldLevel, newLevel, isEjb); 307 308 } 309 310 311 private AppsManager appsMgr = null; 313 private ConfigProvider cfgProv = null; 314 private static final StringManager _stringMgr = 315 StringManager.getManager(AppServWSMonitorLifeCycleProvider.class); 316 private static final Logger _logger = 317 Logger.getLogger(LogDomains.ADMIN_LOGGER); 318 319 320 } 321 | Popular Tags |