1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.catalina.core;
18
19 import java.io.IOException;
20
21 import javax.servlet.ServletException;
22
23 import org.apache.catalina.Host;
24 import org.apache.catalina.connector.Request;
25 import org.apache.catalina.connector.Response;
26 import org.apache.catalina.valves.ValveBase;
27
28 /**
29  * Valve that implements the default basic behavior for the
30  * <code>StandardEngine</code> container implementation.
31  * <p>
32  * <b>USAGE CONSTRAINT</b>:  This implementation is likely to be useful only
33  * when processing HTTP requests.
34  *
35  * @author Craig R. McClanahan
36  */

37 final class StandardEngineValve extends ValveBase {
38
39     //------------------------------------------------------ Constructor
40     public StandardEngineValve() {
41         super(true);
42     }
43
44
45     // --------------------------------------------------------- Public Methods
46
47     /**
48      * Select the appropriate child Host to process this request,
49      * based on the requested server name.  If no matching Host can
50      * be found, return an appropriate HTTP error.
51      *
52      * @param request Request to be processed
53      * @param response Response to be produced
54      *
55      * @exception IOException if an input/output error occurred
56      * @exception ServletException if a servlet error occurred
57      */

58     @Override
59     public final void invoke(Request request, Response response)
60         throws IOException, ServletException {
61
62         // Select the Host to be used for this Request
63         Host host = request.getHost();
64         if (host == null) {
65             // HTTP 0.9 or HTTP 1.0 request without a host when no default host
66             // is defined. This is handled by the CoyoteAdapter.
67             return;
68         }
69         if (request.isAsyncSupported()) {
70             request.setAsyncSupported(host.getPipeline().isAsyncSupported());
71         }
72
73         // Ask this Host to process this request
74         host.getPipeline().getFirst().invoke(request, response);
75     }
76 }
77