VirtualServerPipelinepublic class VirtualServerPipeline extends org.apache.catalina.core.StandardPipeline Pipeline associated with a virtual server.
This pipeline inherits the state (off/disabled) of its associated
virtual server, and will abort execution and return an appropriate response
error code if its associated virtual server is off or disabled. |
Fields Summary |
---|
private static final org.apache.catalina.util.StringManager | sm | private static final Logger | logger | private VirtualServer | vs | private boolean | isOff | private boolean | isDisabled | private ArrayList | redirects | private ConcurrentLinkedQueue | locations | private ConcurrentLinkedQueue | urlEncoders |
Constructors Summary |
---|
public VirtualServerPipeline(VirtualServer vs)Constructor.
super(vs);
this.vs = vs;
locations = new ConcurrentLinkedQueue<CharChunk>();
urlEncoders = new ConcurrentLinkedQueue<UEncoder>();
|
Methods Summary |
---|
void | addRedirect(java.lang.String from, java.lang.String url, java.lang.String urlPrefix, boolean escape)Adds the given redirect instruction to this VirtualServerPipeline.
if (redirects == null) {
redirects = new ArrayList<RedirectParameters>();
}
redirects.add(new RedirectParameters(from, url, urlPrefix, escape));
| void | clearRedirects()Clears all redirects.
if (redirects != null) {
redirects.clear();
}
| boolean | hasRedirects()
return ((redirects != null) && (redirects.size() > 0));
| public void | invoke(org.apache.catalina.Request request, org.apache.catalina.Response response)Processes the specified request, and produces the appropriate
response, by invoking the first valve (if any) of this pipeline, or
the pipeline's basic valve.
if (isOff) {
String msg = sm.getString("virtualServerValve.vsOff",
vs.getName());
if (logger.isLoggable(Level.FINE)) {
logger.fine(msg);
}
((HttpServletResponse) response.getResponse()).sendError(
HttpServletResponse.SC_NOT_FOUND,
msg);
} else if (isDisabled) {
String msg = sm.getString("virtualServerValve.vsDisabled",
vs.getName());
if (logger.isLoggable(Level.FINE)) {
logger.fine(msg);
}
((HttpServletResponse) response.getResponse()).sendError(
HttpServletResponse.SC_FORBIDDEN,
msg);
} else {
boolean redirect = false;
if (redirects != null) {
redirect = redirectIfNecessary(request, response);
}
if (!redirect) {
doInvoke(request, response);
}
}
| private boolean | redirectIfNecessary(org.apache.catalina.Request request, org.apache.catalina.Response response)Checks to see if the given request needs to be redirected.
if (redirects == null) {
return false;
}
HttpServletRequest hreq = (HttpServletRequest) request.getRequest();
HttpServletResponse hres = (HttpServletResponse) request.getResponse();
String requestURI = hreq.getRequestURI();
RedirectParameters redirectMatch = null;
// Determine the longest 'from' URI prefix match
int size = redirects.size();
for (int i=0; i<size; i++) {
RedirectParameters elem = redirects.get(i);
if (requestURI.startsWith(elem.from)) {
if (redirectMatch != null) {
if (elem.from.length() > redirectMatch.from.length()) {
redirectMatch = elem;
}
} else {
redirectMatch = elem;
}
}
}
if (redirectMatch != null) {
// Redirect prefix match found, need to redirect
String location = null;
String uriSuffix = requestURI.substring(
redirectMatch.from.length());
if ("/".equals(redirectMatch.from)) {
uriSuffix = "/" + uriSuffix;
}
if (redirectMatch.urlPrefix != null) {
// Replace 'from' URI prefix with URL prefix
location = redirectMatch.urlPrefix + uriSuffix;
} else {
// Replace 'from' URI prefix with complete URL
location = redirectMatch.url;
}
String queryString = hreq.getQueryString();
if (queryString != null) {
location += queryString;
}
CharChunk locationCC = null;
UEncoder urlEncoder = null;
if (redirectMatch.isEscape) {
try {
URL url = new URL(location);
locationCC = locations.poll();
if (locationCC == null) {
locationCC = new CharChunk();
}
locationCC.append(url.getProtocol());
locationCC.append("://");
locationCC.append(url.getHost());
if (url.getPort() != -1) {
locationCC.append(":");
locationCC.append(String.valueOf(url.getPort()));
}
urlEncoder = urlEncoders.poll();
if (urlEncoder == null){
urlEncoder = new UEncoder();
urlEncoder.addSafeCharacter('/");
}
locationCC.append(urlEncoder.encodeURL(url.getPath()));
location = locationCC.toString();
} catch (MalformedURLException mue) {
logger.log(Level.WARNING,
"virtualServerPipeline.invalidRedirectLocation",
location);
} finally {
if (urlEncoder != null) {
urlEncoders.offer(urlEncoder);
}
if (locationCC != null) {
locationCC.recycle();
locations.offer(locationCC);
}
}
}
hres.sendRedirect(location);
return true;
}
return false;
| void | setIsDisabled(boolean isDisabled)Sets the disabled state of this VirtualServerPipeline.
this.isDisabled = isDisabled;
| void | setIsOff(boolean isOff)Sets the off state of this VirtualServerPipeline.
this.isOff = isOff;
|
|