KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > jetty6 > cluster > AbstractClusteredPreHandler


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.geronimo.jetty6.cluster;
18
19 import java.io.IOException JavaDoc;
20
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import javax.servlet.http.HttpServletResponse JavaDoc;
23 import javax.servlet.ServletException JavaDoc;
24
25 import org.apache.geronimo.clustering.ClusteredInvocation;
26 import org.apache.geronimo.clustering.ClusteredInvocationException;
27 import org.apache.geronimo.jetty6.AbstractPreHandler;
28 import org.mortbay.jetty.Handler;
29 import org.mortbay.jetty.HttpException;
30
31 /**
32  * @version $Rev$ $Date$
33  */

34 public abstract class AbstractClusteredPreHandler extends AbstractPreHandler {
35
36     public void handle(String JavaDoc target, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, int dispatch)
37             throws IOException JavaDoc, ServletException JavaDoc {
38 // if (dispatch != Handler.REQUEST) {
39
// next.handle(target, request, response, dispatch);
40
// return;
41
// }
42
//
43
ClusteredInvocation invocation = newClusteredInvocation(target, request, response, dispatch);
44         try {
45             invocation.invoke();
46         } catch (ClusteredInvocationException e) {
47             Throwable JavaDoc cause = e.getCause();
48             if (cause instanceof HttpException) {
49                 throw (HttpException) cause;
50             } else if (cause instanceof IOException JavaDoc) {
51                 throw (IOException JavaDoc) cause;
52             } else {
53                 throw (IOException JavaDoc) new IOException JavaDoc().initCause(cause);
54             }
55         }
56     }
57
58     protected abstract ClusteredInvocation newClusteredInvocation(String JavaDoc target,
59             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, int dispatch);
60
61
62     protected abstract class WebClusteredInvocation implements ClusteredInvocation {
63         protected final String JavaDoc target;
64         protected final HttpServletRequest JavaDoc request;
65         protected final HttpServletResponse JavaDoc response;
66         protected final int dispatch;
67
68         protected WebClusteredInvocation(String JavaDoc target, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, int dispatch) {
69             this.target = target;
70             this.request = request;
71             this.response = response;
72             this.dispatch = dispatch;
73             //TODO figure out if the normal SessionHandler will set the requestedSessionId correctly.
74
//My (djencks) guess is yes it will.
75
// GeronimoServletHttpRequest servletHttpRequest = (GeronimoServletHttpRequest) request.getWrapper();
76
// servletHttpRequest.setRequestedSessionId(pathParams);
77
}
78
79         protected void invokeLocally() throws ClusteredInvocationException {
80             try {
81                 next.handle(target, request, response, dispatch);
82             } catch (IOException JavaDoc e) {
83                 throw new ClusteredInvocationException(e);
84             } catch (ServletException JavaDoc e) {
85                 //WHAT DO I DO HERE???
86
throw new ClusteredInvocationException(e);
87             }
88         }
89
90         public String JavaDoc getRequestedSessionId() {
91             return request.getRequestedSessionId();
92         }
93     }
94     
95 }
96
Popular Tags