KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > jetty6 > cluster > wadi > WADIClusteredPreHandler


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.wadi;
18
19 import java.io.IOException JavaDoc;
20
21 import javax.servlet.FilterChain JavaDoc;
22 import javax.servlet.ServletException JavaDoc;
23 import javax.servlet.ServletRequest JavaDoc;
24 import javax.servlet.ServletResponse JavaDoc;
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.http.HttpServletResponse JavaDoc;
27
28 import org.apache.geronimo.clustering.ClusteredInvocation;
29 import org.apache.geronimo.clustering.ClusteredInvocationException;
30 import org.apache.geronimo.jetty6.cluster.AbstractClusteredPreHandler;
31 import org.codehaus.wadi.InvocationException;
32 import org.codehaus.wadi.InvocationProxy;
33 import org.codehaus.wadi.impl.ClusteredManager;
34 import org.codehaus.wadi.web.impl.WebInvocation;
35
36
37 /**
38  *
39  * @version $Rev$ $Date$
40  */

41 public class WADIClusteredPreHandler extends AbstractClusteredPreHandler {
42     private final ClusteredManager wadiManager;
43
44     public WADIClusteredPreHandler(ClusteredManager wadiManager) {
45         this.wadiManager = wadiManager;
46     }
47     
48     protected ClusteredInvocation newClusteredInvocation(String JavaDoc target, HttpServletRequest JavaDoc request,
49             HttpServletResponse JavaDoc response, int dispatch) {
50         return new WADIWebClusteredInvocation(target, request, response, dispatch);
51     }
52     
53     protected class WADIWebClusteredInvocation extends WebClusteredInvocation {
54         
55         public WADIWebClusteredInvocation(String JavaDoc target, HttpServletRequest JavaDoc request,
56                 HttpServletResponse JavaDoc response, int dispatch) {
57             super(target, request, response, dispatch);
58         }
59
60         public void invoke() throws ClusteredInvocationException {
61             WebInvocation invocation = new WebInvocation();
62             FilterChain JavaDoc chainAdapter = new FilterChain JavaDoc() {
63                 public void doFilter(ServletRequest JavaDoc request, ServletResponse JavaDoc response) throws IOException JavaDoc, ServletException JavaDoc {
64                     try {
65                         invokeLocally();
66                     } catch (ClusteredInvocationException e) {
67                         throw (IOException JavaDoc) new IOException JavaDoc().initCause(e);
68                     }
69                 }
70             };
71             InvocationProxy invocationProxy = wadiManager.getInvocationProxy();
72             invocation.init(request, response, chainAdapter, invocationProxy);
73             try {
74                 wadiManager.contextualise(invocation);
75             } catch (InvocationException e) {
76                 Throwable JavaDoc throwable = e.getCause();
77                 if (throwable instanceof IOException JavaDoc) {
78                     throw new ClusteredInvocationException(throwable);
79                 } else if (throwable instanceof ServletException JavaDoc) {
80                     throw new ClusteredInvocationException(throwable);
81                 } else {
82                     throw new ClusteredInvocationException(e);
83                 }
84             }
85         }
86     }
87     
88 }
89
Popular Tags