1 16 package org.apache.webapp.balancer.rules; 17 18 import javax.servlet.http.HttpServletRequest ; 19 20 21 28 public class RemoteAddressRule extends BaseRule { 29 32 private String remoteAddress; 33 34 39 public void setRemoteAddress(String theAddress) { 40 if (theAddress == null) { 41 throw new IllegalArgumentException ("The address cannot be null."); 42 } else { 43 remoteAddress = theAddress; 44 } 45 } 46 47 52 protected String getRemoteAddress() { 53 return remoteAddress; 54 } 55 56 61 public boolean matches(HttpServletRequest request) { 62 String requestAddr = request.getRemoteAddr(); 63 64 return (requestAddr.compareTo(getRemoteAddress()) == 0); 65 } 66 67 72 public String toString() { 73 StringBuffer buffer = new StringBuffer (); 74 75 buffer.append("["); 76 buffer.append(getClass().getName()); 77 buffer.append(": "); 78 79 buffer.append("Target remote address: "); 80 buffer.append(getRemoteAddress()); 81 buffer.append(" / "); 82 83 buffer.append("Redirect URL: "); 84 buffer.append(getRedirectUrl()); 85 86 buffer.append("]"); 87 88 return buffer.toString(); 89 } 90 } 91 92 93 | Popular Tags |