01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19:
20: package org.apache.geronimo.tomcat.cluster;
21:
22: import java.io.IOException;
23:
24: import javax.servlet.ServletException;
25:
26: import org.apache.catalina.connector.Request;
27: import org.apache.catalina.connector.Response;
28: import org.apache.catalina.valves.ValveBase;
29: import org.apache.geronimo.clustering.ClusteredInvocation;
30: import org.apache.geronimo.clustering.ClusteredInvocationException;
31:
32: /**
33: *
34: * @version $Rev:$ $Date:$
35: */
36: public abstract class AbstractClusteredValve extends ValveBase {
37:
38: @Override
39: public void invoke(Request request, Response response)
40: throws IOException, ServletException {
41: ClusteredInvocation invocation = newClusteredInvocation(
42: request, response);
43: try {
44: invocation.invoke();
45: } catch (ClusteredInvocationException e) {
46: Throwable cause = e.getCause();
47: if (cause instanceof ServletException) {
48: throw (ServletException) cause;
49: } else if (cause instanceof IOException) {
50: throw (IOException) cause;
51: } else {
52: throw (IOException) new IOException().initCause(e);
53: }
54: }
55: }
56:
57: protected abstract ClusteredInvocation newClusteredInvocation(
58: Request request, Response response);
59:
60: protected abstract class WebClusteredInvocation implements
61: ClusteredInvocation {
62: protected final Request request;
63: protected final Response response;
64:
65: protected WebClusteredInvocation(Request request,
66: Response response) {
67: this .request = request;
68: this .response = response;
69: }
70:
71: protected void invokeLocally()
72: throws ClusteredInvocationException {
73: try {
74: next.invoke(request, response);
75: } catch (IOException e) {
76: throw new ClusteredInvocationException(e);
77: } catch (ServletException e) {
78: throw new ClusteredInvocationException(e);
79: }
80: }
81:
82: public String getRequestedSessionId() {
83: if (null == request) {
84: return null;
85: }
86: return request.getRequestedSessionId();
87: }
88: }
89:
90: }
|