1 16 package org.apache.webapp.balancer.rules; 17 18 import javax.servlet.http.HttpServletRequest ; 19 20 21 29 public class RequestHeaderRule extends BaseRule { 30 33 private String headerName; 34 35 39 private String headerValue; 40 41 46 public void setHeaderName(String theName) { 47 if (theName == null) { 48 throw new IllegalArgumentException ( 49 "The header name cannot be null."); 50 } else { 51 headerName = theName; 52 } 53 } 54 55 60 protected String getHeaderName() { 61 return headerName; 62 } 63 64 69 public void setHeaderValue(String theValue) { 70 headerValue = theValue; 71 } 72 73 79 protected String getHeaderValue() { 80 return headerValue; 81 } 82 83 86 public boolean matches(HttpServletRequest request) { 87 String actualHeaderValue = request.getHeader(getHeaderName()); 88 89 if (actualHeaderValue == null) { 90 return (getHeaderValue() == null); 91 } else { 92 return (actualHeaderValue.compareTo(getHeaderValue()) == 0); 93 } 94 } 95 96 101 public String toString() { 102 StringBuffer buffer = new StringBuffer (); 103 104 buffer.append("["); 105 buffer.append(getClass().getName()); 106 buffer.append(": "); 107 108 buffer.append("Header name: "); 109 buffer.append(getHeaderName()); 110 buffer.append(" / "); 111 112 buffer.append("Header value: "); 113 buffer.append(getHeaderValue()); 114 buffer.append(" / "); 115 116 buffer.append("Redirect URL: "); 117 buffer.append(getRedirectUrl()); 118 119 buffer.append("]"); 120 121 return buffer.toString(); 122 } 123 } 124 125 126 | Popular Tags |