001: /*
002: * Copyright 1999-2001,2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.catalina.core;
018:
019: import java.io.IOException;
020:
021: import javax.servlet.ServletException;
022: import javax.servlet.http.HttpServletResponse;
023:
024: import org.apache.catalina.Host;
025: import org.apache.catalina.Request;
026: import org.apache.catalina.Response;
027: import org.apache.catalina.ValveContext;
028: import org.apache.catalina.util.StringManager;
029: import org.apache.catalina.valves.ValveBase;
030:
031: /**
032: * Valve that implements the default basic behavior for the
033: * <code>StandardEngine</code> container implementation.
034: * <p>
035: * <b>USAGE CONSTRAINT</b>: This implementation is likely to be useful only
036: * when processing HTTP requests.
037: *
038: * @author Craig R. McClanahan
039: * @version $Revision: 1.7 $ $Date: 2004/02/27 14:58:42 $
040: */
041:
042: final class StandardEngineValve extends ValveBase {
043:
044: // ----------------------------------------------------- Instance Variables
045:
046: /**
047: * The descriptive information related to this implementation.
048: */
049: private static final String info = "org.apache.catalina.core.StandardEngineValve/1.0";
050:
051: /**
052: * The string manager for this package.
053: */
054: private static final StringManager sm = StringManager
055: .getManager(Constants.Package);
056:
057: // ------------------------------------------------------------- Properties
058:
059: /**
060: * Return descriptive information about this Valve implementation.
061: */
062: public String getInfo() {
063:
064: return (info);
065:
066: }
067:
068: // --------------------------------------------------------- Public Methods
069:
070: /**
071: * Select the appropriate child Host to process this request,
072: * based on the requested server name. If no matching Host can
073: * be found, return an appropriate HTTP error.
074: *
075: * @param request Request to be processed
076: * @param response Response to be produced
077: * @param valveContext Valve context used to forward to the next Valve
078: *
079: * @exception IOException if an input/output error occurred
080: * @exception ServletException if a servlet error occurred
081: */
082: public final void invoke(Request request, Response response,
083: ValveContext valveContext) throws IOException,
084: ServletException {
085:
086: // Select the Host to be used for this Request
087: Host host = request.getHost();
088: if (host == null) {
089: ((HttpServletResponse) response.getResponse()).sendError(
090: HttpServletResponse.SC_BAD_REQUEST, sm.getString(
091: "standardEngine.noHost", request
092: .getRequest().getServerName()));
093: return;
094: }
095:
096: // Ask this Host to process this request
097: host.getPipeline().invoke(request, response);
098:
099: }
100:
101: }
|