KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > jetty > interceptor > RequestWrappingBeforeAfter


1 /**
2  *
3  * Copyright 2003-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * 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.geronimo.jetty.interceptor;
18
19 import org.mortbay.http.HttpRequest;
20 import org.mortbay.http.HttpResponse;
21 import org.mortbay.jetty.servlet.ServletHandler;
22 import org.mortbay.jetty.servlet.ServletHttpRequest;
23 import org.mortbay.jetty.servlet.ServletHttpResponse;
24
25 /**
26  * @version $Rev: $ $Date: $
27  */

28 public class RequestWrappingBeforeAfter implements BeforeAfter {
29     private final BeforeAfter next;
30     private final ServletHandler handler;
31
32     public RequestWrappingBeforeAfter(BeforeAfter next, ServletHandler handler) {
33         this.next = next;
34         this.handler = handler;
35     }
36     
37     public void before(Object JavaDoc[] context, HttpRequest httpRequest, HttpResponse httpResponse) {
38         if (httpRequest != null) {
39             ServletHttpRequest request = (ServletHttpRequest) httpRequest.getWrapper();
40             if (request == null)
41             {
42                 // Build the request and response.
43
request = new ServletHttpRequest(handler, null, httpRequest);
44                 ServletHttpResponse response = new ServletHttpResponse(request, httpResponse);
45                 httpRequest.setWrapper(request);
46                 httpResponse.setWrapper(response);
47             }
48         }
49         next.before(context, httpRequest, httpResponse);
50     }
51
52     public void after(Object JavaDoc[] context, HttpRequest httpRequest, HttpResponse httpResponse) {
53         next.after(context, httpRequest, httpResponse);
54     }
55 }
56
Popular Tags