01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.jetty6.cluster;
17:
18: import java.io.IOException;
19:
20: import javax.servlet.ServletException;
21: import javax.servlet.http.HttpServletRequest;
22: import javax.servlet.http.HttpServletResponse;
23:
24: import org.apache.geronimo.clustering.ClusteredInvocation;
25: import org.apache.geronimo.clustering.ClusteredInvocationException;
26: import org.apache.geronimo.jetty6.AbstractPreHandler;
27: import org.mortbay.jetty.HttpException;
28:
29: /**
30: * @version $Rev$ $Date$
31: */
32: public abstract class AbstractClusteredPreHandler extends
33: AbstractPreHandler {
34:
35: public void handle(String target, HttpServletRequest request,
36: HttpServletResponse response, int dispatch)
37: throws IOException, ServletException {
38: ClusteredInvocation invocation = newClusteredInvocation(target,
39: request, response, dispatch);
40: try {
41: invocation.invoke();
42: } catch (ClusteredInvocationException e) {
43: Throwable cause = e.getCause();
44: if (cause instanceof HttpException) {
45: throw (HttpException) cause;
46: } else if (cause instanceof IOException) {
47: throw (IOException) cause;
48: } else {
49: throw (IOException) new IOException().initCause(cause);
50: }
51: }
52: }
53:
54: protected abstract ClusteredInvocation newClusteredInvocation(
55: String target, HttpServletRequest request,
56: HttpServletResponse response, int dispatch);
57:
58: protected abstract class WebClusteredInvocation implements
59: ClusteredInvocation {
60: protected final String target;
61: protected final HttpServletRequest request;
62: protected final HttpServletResponse response;
63: protected final int dispatch;
64:
65: protected WebClusteredInvocation(String target,
66: HttpServletRequest request,
67: HttpServletResponse response, int dispatch) {
68: this .target = target;
69: this .request = request;
70: this .response = response;
71: this .dispatch = dispatch;
72: }
73:
74: protected void invokeLocally()
75: throws ClusteredInvocationException {
76: try {
77: next.handle(target, request, response, dispatch);
78: } catch (IOException e) {
79: throw new ClusteredInvocationException(e);
80: } catch (ServletException e) {
81: //WHAT DO I DO HERE???
82: throw new ClusteredInvocationException(e);
83: }
84: }
85:
86: public String getRequestedSessionId() {
87: return request.getRequestedSessionId();
88: }
89: }
90:
91: }
|