KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > coyote > tomcat3 > Tomcat3Adapter


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

16
17 package org.apache.coyote.tomcat3;
18
19 import org.apache.coyote.Adapter;
20 import org.apache.tomcat.core.ContextManager;
21 import org.apache.tomcat.core.BaseInterceptor;
22
23 /** Adapter between Coyote and Tomcat.
24  *
25  * This class handles the task of passing of an individual request to
26  * Tomcat to handle. Also some of the connection-specific methods are
27  * delegated to here.
28  *
29  * @author Bill Barker
30  */

31 public class Tomcat3Adapter implements Adapter {
32     ContextManager cm;
33     BaseInterceptor connector;
34     
35     Tomcat3Adapter(ContextManager ctxman, CoyoteInterceptor2 conn) {
36     cm = ctxman;
37     connector = conn;
38     }
39
40     static int containerRequestNOTE=1; // XXX Implement a NoteManager, namespaces.
41

42     /** Pass off an individual request to Tomcat.
43      */

44     public void service(org.apache.coyote.Request request,
45             org.apache.coyote.Response response)
46         throws Exception JavaDoc
47     {
48         Tomcat3Request reqA;
49         Tomcat3Response resA;
50
51         reqA=(Tomcat3Request)request.getNote( containerRequestNOTE );
52         if( reqA==null ) {
53             reqA=new Tomcat3Request();
54             resA=new Tomcat3Response();
55             cm.initRequest( reqA, resA );
56
57             reqA.setCoyoteRequest(request);
58             resA.setCoyoteResponse(response);
59         reqA.setConnector(connector);
60             request.setNote( containerRequestNOTE, reqA );
61         } else {
62             resA=(Tomcat3Response)reqA.getResponse();
63         }
64         
65         if( reqA.scheme().isNull() ) {
66         reqA.scheme().setString("http");
67     }
68     try {
69         cm.service( reqA, resA );
70     } finally {
71         reqA.recycle();
72         resA.recycle();
73     }
74     }
75 }
76
Popular Tags