1 23 24 package com.sun.enterprise.tools.admingui.handlers; 25 26 import java.util.EventObject ; 27 import java.lang.Thread ; 28 import java.util.Properties ; 29 30 import javax.management.MBeanException ; 31 import javax.management.ObjectName ; 32 import javax.management.AttributeList ; 33 import javax.management.Attribute ; 34 import javax.servlet.http.HttpServletRequest ; 35 36 import com.iplanet.jato.RequestContext; 37 import com.iplanet.jato.RequestManager; 38 import com.iplanet.jato.view.View; 39 import com.iplanet.jato.view.ViewBase; 40 import com.iplanet.jato.view.ViewBean; 41 import com.iplanet.jato.util.NonSyncStringBuffer; 42 import com.iplanet.jato.model.DefaultModel; 43 import com.sun.web.ui.model.CCActionTableModelInterface; 44 45 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 46 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView; 47 import com.sun.enterprise.tools.guiframework.view.HandlerContext; 48 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 49 import com.sun.enterprise.tools.admingui.util.MBeanUtil; 50 import com.sun.enterprise.tools.admingui.util.Util; 51 import com.sun.enterprise.tools.admingui.AdminGUIConstants; 52 53 import com.sun.enterprise.admin.servermgmt.RuntimeStatus; 54 import com.sun.enterprise.admin.common.Status; 55 56 57 public class ServerInstGeneralHandlers { 58 59 62 public String endPortsDisplay(RequestContext ctx, HandlerContext handlerCtx) { 63 String ports = ""; 64 String objectName = (String )handlerCtx.getViewDescriptor().getParameter("objectName"); 65 String methodName = (String )handlerCtx.getViewDescriptor().getParameter("methodName"); 68 try { 70 ObjectName [] listeners = (ObjectName []) MBeanUtil.invoke( 71 new ObjectName (objectName), methodName, null, null); 72 73 for (int i=0; i<listeners.length; i++) { 74 Object port = MBeanUtil.getAttribute(listeners[i], "port"); 75 if (i != 0) 76 ports += ", "; 77 if (port != null){ 78 String pn = port.toString(); 79 if (pn.startsWith("$")){ 80 String serverName = (String )handlerCtx.getViewDescriptor().getParameter("serverName"); 81 port = resolveToken( (pn.substring(2, pn.length()-1) ), serverName); 82 } 83 ports += port.toString(); 84 } 85 } 86 87 } catch (Exception ex) { 88 if (Util.isLoggableINFO()) { 89 Util.logINFO("Exception thrown in getting HTTP ports.", ex); 90 } 91 } 92 93 return ports; 94 } 95 96 97 100 public String endConfigDirDisplay(RequestContext ctx, HandlerContext handlerCtx) { 101 String objectName = (String )handlerCtx.getViewDescriptor().getParameter("objectName"); 102 String methodName = (String )handlerCtx.getViewDescriptor().getParameter("methodName"); 103 String dir = ""; 104 try { 105 Object configDir = MBeanUtil.invoke( 106 new ObjectName (objectName), methodName, null, null); 107 dir += configDir.toString(); 108 } catch (Exception ex) { 109 if (Util.isLoggableINFO()) { 110 Util.logINFO("Exception thrown in getting config directory.", ex); 111 } 112 } 113 return dir; 114 } 115 116 117 120 public String endDebugDisplay(RequestContext ctx, HandlerContext handlerCtx) { 121 String objectName = (String )handlerCtx.getViewDescriptor().getParameter("objectName"); 122 String methodName = (String )handlerCtx.getViewDescriptor().getParameter("methodName"); 123 String msg = Util.getMessage("serverinst.notEnabled"); 124 try { 125 Object debugPort = MBeanUtil.getAttribute( 126 new ObjectName (objectName), methodName); 127 128 if (debugPort != null) { 129 String port = debugPort.toString(); 130 if (port.equals("0") == false) { 131 msg = Util.getMessage("serverinst.debugEnabled") + 132 debugPort.toString(); 133 } 134 } 135 } catch (Exception ex) { 136 if (Util.isLoggableINFO()) { 137 Util.logINFO("Exception thrown in getting debug port.", ex); 138 } 139 } 140 return msg; 141 } 142 143 144 147 public String endHostNameDisplay(RequestContext ctx, HandlerContext handlerCtx) { 148 View bean = handlerCtx.getView(); 149 DescriptorContainerView view = (DescriptorContainerView)bean.getParent(); 150 return ctx.getRequest().getServerName(); 151 } 152 153 154 166 public static String endInstallVersionDisplay(RequestContext ctx, HandlerContext handlerCtx) { 167 String objectName = (String )handlerCtx.getViewDescriptor().getParameter("objectName"); 168 String methodName = (String )handlerCtx.getViewDescriptor().getParameter("methodName"); 169 String version = ""; 170 try { 171 Object domainVersion = MBeanUtil.getAttribute( 172 new ObjectName (objectName), methodName); 173 version += domainVersion.toString(); 174 } catch (Exception ex) { 175 if (Util.isLoggableINFO()) { 176 Util.logINFO("Exception thrown in getting domain version.", ex); 177 } 178 } 179 return version; 180 } 181 182 public void isServerRunning(RequestContext ctx, HandlerContext handlerCtx) { 183 boolean isRunning = false; 184 Object sts = (Object ) handlerCtx.getInputValue("statusObject"); 185 if (sts instanceof RuntimeStatus) { 186 Status s = ((RuntimeStatus)sts).getStatus(); 187 int code = s.getStatusCode(); 188 switch (code) { 189 case Status.kInstanceRunningCode: 190 case Status.kInstanceStartingCode: 191 isRunning = true; 192 break; 193 case Status.kInstanceNotRunningCode: 194 case Status.kInstanceStoppingCode: 195 isRunning = false; 196 break; 197 case Status.kEntityEnabledCode: 198 case Status.kEntityDisabledCode: 199 return; } 202 } 203 handlerCtx.setOutputValue("value", (isRunning)?("true"):("false")); 204 } 205 206 public void loadInstanceAndNodeAgent(RequestContext ctx, HandlerContext handlerCtx) { 207 try { 208 CCActionTableModelInterface model = 209 (CCActionTableModelInterface)handlerCtx.getInputValue("propertiesModel"); 210 ObjectName [] objs = (ObjectName [] )handlerCtx.getInputValue("instanceList"); 211 model.beforeFirst(); 212 if (objs == null || objs.length < 1 ) 213 return; 214 for(int i=0; i< objs.length; i++){ 215 String name = (String ) MBeanUtil.getAttribute(objs[i], "name"); 216 String nodeAgent = (String ) MBeanUtil.getAttribute(objs[i], "node-agent-ref"); 217 model.appendRow(); 218 model.setValue(PropertiesHandlers.PROPERTY_NAME, name); 219 model.setValue(PropertiesHandlers.PROPERTY_VALUE ,nodeAgent); 220 model.setRowSelected(false); 221 } 222 223 } catch (Exception ex) { 224 throw new FrameworkException("loadProperties: Loading error. ", ex); 225 } 226 } 227 228 private String resolveToken(String pn, String serverName) 229 { 230 if (Util.isEmpty(serverName)){ 231 throw new IllegalArgumentException ("The parameter map did not contain serverName"); 232 } 233 String objectName = "com.sun.appserv:type=server,category=config,name=" + serverName; 234 String methodName = "listSystemProperties"; 235 Object [] params = new Object []{ new Boolean ("true")}; 236 String [] types = new String []{"boolean"}; 237 try { 238 Properties sysProp = (Properties ) MBeanUtil.invoke(new ObjectName (objectName), methodName, params, types); 239 String value = sysProp.getProperty(pn); 240 return value; 241 }catch (Exception ex){ 242 throw new FrameworkException("EndPortDisplay: ", ex); 243 } 244 } 245 246 247 } 248 | Popular Tags |