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.wadi;
17:
18: import java.io.IOException;
19:
20: import javax.servlet.FilterChain;
21: import javax.servlet.ServletException;
22: import javax.servlet.ServletRequest;
23: import javax.servlet.ServletResponse;
24: import javax.servlet.http.HttpServletRequest;
25: import javax.servlet.http.HttpServletResponse;
26:
27: import org.apache.geronimo.clustering.ClusteredInvocation;
28: import org.apache.geronimo.clustering.ClusteredInvocationException;
29: import org.apache.geronimo.jetty6.cluster.AbstractClusteredPreHandler;
30: import org.codehaus.wadi.core.contextualiser.InvocationException;
31: import org.codehaus.wadi.core.manager.Manager;
32: import org.codehaus.wadi.web.impl.WebInvocation;
33:
34: /**
35: *
36: * @version $Rev$ $Date$
37: */
38: public class WADIClusteredPreHandler extends
39: AbstractClusteredPreHandler {
40: private final Manager wadiManager;
41:
42: public WADIClusteredPreHandler(Manager wadiManager) {
43: this .wadiManager = wadiManager;
44: }
45:
46: protected ClusteredInvocation newClusteredInvocation(String target,
47: HttpServletRequest request, HttpServletResponse response,
48: int dispatch) {
49: return new WADIWebClusteredInvocation(target, request,
50: response, dispatch);
51: }
52:
53: protected class WADIWebClusteredInvocation extends
54: WebClusteredInvocation {
55:
56: public WADIWebClusteredInvocation(String target,
57: HttpServletRequest request,
58: HttpServletResponse response, int dispatch) {
59: super (target, request, response, dispatch);
60: }
61:
62: public void invoke() throws ClusteredInvocationException {
63: WebInvocation invocation = new WebInvocation(5000);
64: FilterChain chainAdapter = new FilterChain() {
65: public void doFilter(ServletRequest request,
66: ServletResponse response) throws IOException,
67: ServletException {
68: try {
69: invokeLocally();
70: } catch (ClusteredInvocationException e) {
71: throw (IOException) new IOException()
72: .initCause(e);
73: }
74: }
75: };
76: invocation.init(request, response, chainAdapter);
77: try {
78: wadiManager.contextualise(invocation);
79: } catch (InvocationException e) {
80: Throwable throwable = e.getCause();
81: if (throwable instanceof IOException) {
82: throw new ClusteredInvocationException(throwable);
83: } else if (throwable instanceof ServletException) {
84: throw new ClusteredInvocationException(throwable);
85: } else {
86: throw new ClusteredInvocationException(e);
87: }
88: }
89: }
90: }
91:
92: }
|