1 16 package org.apache.webapp.balancer.rules; 17 18 import javax.servlet.http.HttpServletRequest ; 19 20 21 27 public class URLStringMatchRule extends BaseRule { 28 32 private String targetString; 33 34 40 public void setTargetString(String theTargetString) { 41 if (theTargetString == null) { 42 throw new IllegalArgumentException ( 43 "The target string cannot be null."); 44 } else { 45 targetString = theTargetString; 46 } 47 } 48 49 55 protected String getTargetString() { 56 return targetString; 57 } 58 59 64 public boolean matches(HttpServletRequest request) { 65 String requestUrl = request.getRequestURL().toString(); 66 int index = requestUrl.indexOf(getTargetString()); 67 68 return (index > -1); 69 } 70 71 76 public String toString() { 77 StringBuffer buffer = new StringBuffer (); 78 79 buffer.append("["); 80 buffer.append(getClass().getName()); 81 buffer.append(": "); 82 83 buffer.append("Target string: "); 84 buffer.append(getTargetString()); 85 buffer.append(" / "); 86 87 buffer.append("Redirect URL: "); 88 buffer.append(getRedirectUrl()); 89 90 buffer.append("]"); 91 92 return buffer.toString(); 93 } 94 } 95 96 97 | Popular Tags |