Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.tomcat.cluster.wadi » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements.  See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership.  The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License.  You may obtain a copy of the License at
    9    *
   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.wadi;
   21   
   22   import java.io.IOException;
   23   
   24   import javax.servlet.FilterChain;
   25   import javax.servlet.ServletException;
   26   import javax.servlet.ServletRequest;
   27   import javax.servlet.ServletResponse;
   28   
   29   import org.apache.catalina.connector.Request;
   30   import org.apache.catalina.connector.Response;
   31   import org.apache.geronimo.clustering.ClusteredInvocation;
   32   import org.apache.geronimo.clustering.ClusteredInvocationException;
   33   import org.apache.geronimo.clustering.wadi.WADISessionManager;
   34   import org.apache.geronimo.tomcat.cluster.AbstractClusteredValve;
   35   import org.codehaus.wadi.core.contextualiser.InvocationException;
   36   import org.codehaus.wadi.core.manager.Manager;
   37   import org.codehaus.wadi.web.impl.WebInvocation;
   38   
   39   
   40   /**
   41    * 
   42    * @version $Rev$ $Date$
   43    */
   44   public class WADIClusteredValve extends AbstractClusteredValve {
   45       private final Manager wadiManager;
   46   
   47       public WADIClusteredValve(WADISessionManager sessionManager) {
   48           super(sessionManager.getNode().getName());
   49           this.wadiManager = sessionManager.getManager();
   50       }
   51       
   52       protected ClusteredInvocation newClusteredInvocation(Request request, Response response) {
   53           return new WADIWebClusteredInvocation(request, response);
   54       }
   55       
   56       protected class WADIWebClusteredInvocation extends WebClusteredInvocation {
   57           
   58           public WADIWebClusteredInvocation(Request request, Response response) {
   59               super(request, response);
   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, ServletResponse response) throws IOException, ServletException {
   66                       try {
   67                           invokeLocally();
   68                       } catch (ClusteredInvocationException e) {
   69                           throw (IOException) new IOException().initCause(e);
   70                       }
   71                   }
   72               };
   73               invocation.init(request, response, chainAdapter);
   74               try {
   75                   wadiManager.contextualise(invocation);
   76               } catch (InvocationException e) {
   77                   Throwable throwable = e.getCause();
   78                   if (throwable instanceof IOException) {
   79                       throw new ClusteredInvocationException(throwable);
   80                   } else if (throwable instanceof ServletException) {
   81                       throw new ClusteredInvocationException(throwable);
   82                   } else {
   83                       throw new ClusteredInvocationException(e);
   84                   }
   85               }
   86           }
   87       }
   88       
   89   }

Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.tomcat.cluster.wadi » [javadoc | source]