1 17 package org.apache.geronimo.jetty6.cluster; 18 19 import java.io.IOException ; 20 21 import javax.servlet.http.HttpServletRequest ; 22 import javax.servlet.http.HttpServletResponse ; 23 import javax.servlet.ServletException ; 24 25 import org.apache.geronimo.clustering.ClusteredInvocation; 26 import org.apache.geronimo.clustering.ClusteredInvocationException; 27 import org.apache.geronimo.jetty6.AbstractPreHandler; 28 import org.mortbay.jetty.Handler; 29 import org.mortbay.jetty.HttpException; 30 31 34 public abstract class AbstractClusteredPreHandler extends AbstractPreHandler { 35 36 public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) 37 throws IOException , ServletException { 38 ClusteredInvocation invocation = newClusteredInvocation(target, request, response, dispatch); 44 try { 45 invocation.invoke(); 46 } catch (ClusteredInvocationException e) { 47 Throwable cause = e.getCause(); 48 if (cause instanceof HttpException) { 49 throw (HttpException) cause; 50 } else if (cause instanceof IOException ) { 51 throw (IOException ) cause; 52 } else { 53 throw (IOException ) new IOException ().initCause(cause); 54 } 55 } 56 } 57 58 protected abstract ClusteredInvocation newClusteredInvocation(String target, 59 HttpServletRequest request, HttpServletResponse response, int dispatch); 60 61 62 protected abstract class WebClusteredInvocation implements ClusteredInvocation { 63 protected final String target; 64 protected final HttpServletRequest request; 65 protected final HttpServletResponse response; 66 protected final int dispatch; 67 68 protected WebClusteredInvocation(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) { 69 this.target = target; 70 this.request = request; 71 this.response = response; 72 this.dispatch = dispatch; 73 } 78 79 protected void invokeLocally() throws ClusteredInvocationException { 80 try { 81 next.handle(target, request, response, dispatch); 82 } catch (IOException e) { 83 throw new ClusteredInvocationException(e); 84 } catch (ServletException e) { 85 throw new ClusteredInvocationException(e); 87 } 88 } 89 90 public String getRequestedSessionId() { 91 return request.getRequestedSessionId(); 92 } 93 } 94 95 } 96 | Popular Tags |