1 17 package org.apache.geronimo.jetty6.cluster.wadi; 18 19 import java.io.IOException ; 20 21 import javax.servlet.FilterChain ; 22 import javax.servlet.ServletException ; 23 import javax.servlet.ServletRequest ; 24 import javax.servlet.ServletResponse ; 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.http.HttpServletResponse ; 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 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 target, HttpServletRequest request, 49 HttpServletResponse response, int dispatch) { 50 return new WADIWebClusteredInvocation(target, request, response, dispatch); 51 } 52 53 protected class WADIWebClusteredInvocation extends WebClusteredInvocation { 54 55 public WADIWebClusteredInvocation(String target, HttpServletRequest request, 56 HttpServletResponse response, int dispatch) { 57 super(target, request, response, dispatch); 58 } 59 60 public void invoke() throws ClusteredInvocationException { 61 WebInvocation invocation = new WebInvocation(); 62 FilterChain chainAdapter = new FilterChain () { 63 public void doFilter(ServletRequest request, ServletResponse response) throws IOException , ServletException { 64 try { 65 invokeLocally(); 66 } catch (ClusteredInvocationException e) { 67 throw (IOException ) new IOException ().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 throwable = e.getCause(); 77 if (throwable instanceof IOException ) { 78 throw new ClusteredInvocationException(throwable); 79 } else if (throwable instanceof ServletException ) { 80 throw new ClusteredInvocationException(throwable); 81 } else { 82 throw new ClusteredInvocationException(e); 83 } 84 } 85 } 86 } 87 88 } 89 | Popular Tags |