1 17 18 19 package org.apache.catalina.valves; 20 21 22 import java.io.IOException ; 23 24 import javax.management.MBeanRegistration ; 25 import javax.management.MBeanServer ; 26 import javax.management.MalformedObjectNameException ; 27 import javax.management.ObjectName ; 28 import javax.servlet.ServletException ; 29 30 import org.apache.catalina.CometEvent; 31 import org.apache.catalina.Contained; 32 import org.apache.catalina.Container; 33 import org.apache.catalina.Context; 34 import org.apache.catalina.Engine; 35 import org.apache.catalina.Host; 36 import org.apache.catalina.Pipeline; 37 import org.apache.catalina.Valve; 38 import org.apache.catalina.Wrapper; 39 import org.apache.catalina.connector.Request; 40 import org.apache.catalina.connector.Response; 41 import org.apache.catalina.core.ContainerBase; 42 import org.apache.catalina.util.StringManager; 43 import org.apache.commons.logging.Log; 44 import org.apache.commons.logging.LogFactory; 45 46 47 57 58 public abstract class ValveBase 59 implements Contained, Valve, MBeanRegistration { 60 private static Log log = LogFactory.getLog(ValveBase.class); 61 62 64 65 68 protected Container container = null; 69 70 71 74 protected Log containerLog = null; 75 76 77 81 protected static String info = 82 "org.apache.catalina.core.ValveBase/1.0"; 83 84 85 88 protected Valve next = null; 89 90 91 94 protected final static StringManager sm = 95 StringManager.getManager(Constants.Package); 96 97 98 100 101 104 public Container getContainer() { 105 106 return (container); 107 108 } 109 110 111 116 public void setContainer(Container container) { 117 118 this.container = container; 119 120 } 121 122 123 126 public String getInfo() { 127 128 return (info); 129 130 } 131 132 133 137 public Valve getNext() { 138 139 return (next); 140 141 } 142 143 144 149 public void setNext(Valve valve) { 150 151 this.next = valve; 152 153 } 154 155 156 158 159 164 public void backgroundProcess() { 165 } 166 167 168 180 public abstract void invoke(Request request, Response response) 181 throws IOException , ServletException ; 182 183 184 197 public void event(Request request, Response response, CometEvent event) 198 throws IOException , ServletException { 199 getNext().event(request, response, event); 201 } 202 203 204 207 public String toString() { 208 StringBuffer sb = new StringBuffer (this.getClass().getName()); 209 sb.append("["); 210 if (container != null) 211 sb.append(container.getName()); 212 sb.append("]"); 213 return (sb.toString()); 214 } 215 216 217 protected String domain; 219 protected ObjectName oname; 220 protected MBeanServer mserver; 221 protected ObjectName controller; 222 223 public ObjectName getObjectName() { 224 return oname; 225 } 226 227 public void setObjectName(ObjectName oname) { 228 this.oname = oname; 229 } 230 231 public String getDomain() { 232 return domain; 233 } 234 235 public ObjectName preRegister(MBeanServer server, 236 ObjectName name) throws Exception { 237 oname=name; 238 mserver=server; 239 domain=name.getDomain(); 240 241 242 return name; 243 } 244 245 public void postRegister(Boolean registrationDone) { 246 } 247 248 public void preDeregister() throws Exception { 249 } 250 251 public void postDeregister() { 252 } 253 254 public ObjectName getController() { 255 return controller; 256 } 257 258 public void setController(ObjectName controller) { 259 this.controller = controller; 260 } 261 262 267 public ObjectName getParentName( ObjectName valveName ) { 268 269 return null; 270 } 271 272 public ObjectName createObjectName(String domain, ObjectName parent) 273 throws MalformedObjectNameException 274 { 275 Container container=this.getContainer(); 276 if( container == null || ! (container instanceof ContainerBase) ) 277 return null; 278 this.containerLog = container.getLogger(); 279 ContainerBase containerBase=(ContainerBase)container; 280 Pipeline pipe=containerBase.getPipeline(); 281 Valve valves[]=pipe.getValves(); 282 283 284 String parentName=""; 285 if (container instanceof Engine) { 286 } else if (container instanceof Host) { 287 parentName=",host=" +container.getName(); 288 } else if (container instanceof Context) { 289 String path = ((Context)container).getPath(); 290 if (path.length() < 1) { 291 path = "/"; 292 } 293 Host host = (Host) container.getParent(); 294 parentName=",path=" + path + ",host=" + 295 host.getName(); 296 } else if (container instanceof Wrapper) { 297 Context ctx = (Context) container.getParent(); 298 String path = ctx.getPath(); 299 if (path.length() < 1) { 300 path = "/"; 301 } 302 Host host = (Host) ctx.getParent(); 303 parentName=",servlet=" + container.getName() + 304 ",path=" + path + ",host=" + host.getName(); 305 } 306 log.debug("valve parent=" + parentName + " " + parent); 307 308 String className=this.getClass().getName(); 309 int period = className.lastIndexOf('.'); 310 if (period >= 0) 311 className = className.substring(period + 1); 312 313 int seq=0; 314 for( int i=0; i<valves.length; i++ ) { 315 if (valves[i] == this) { 317 break; 318 } 319 if( valves[i]!=null && 320 valves[i].getClass() == this.getClass() ) { 321 log.debug("Duplicate " + valves[i] + " " + this + " " + container); 322 seq++; 323 } 324 } 325 String ext=""; 326 if( seq > 0 ) { 327 ext=",seq=" + seq; 328 } 329 330 ObjectName objectName = 331 new ObjectName ( domain + ":type=Valve,name=" + className + ext + parentName); 332 log.debug("valve objectname = "+objectName); 333 return objectName; 334 } 335 336 338 public ObjectName getContainerName() { 339 if( container== null) return null; 340 return ((ContainerBase)container).getJmxName(); 341 } 342 } 343 | Popular Tags |