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;
17:
18: import java.io.IOException;
19:
20: import javax.servlet.ServletException;
21: import javax.servlet.http.HttpServletRequest;
22: import javax.servlet.http.HttpServletResponse;
23:
24: import org.apache.geronimo.jetty6.AbstractPreHandler;
25: import org.apache.geronimo.jetty6.PreHandler;
26: import org.mortbay.jetty.servlet.SessionHandler;
27:
28: /**
29: *
30: * @version $Rev$ $Date$
31: */
32: public class ClusteredSessionHandler extends SessionHandler {
33: private final PreHandler chainedHandler;
34:
35: public ClusteredSessionHandler(
36: ClusteredSessionManager sessionManager,
37: PreHandler chainedHandler) {
38: if (null == chainedHandler) {
39: throw new IllegalArgumentException(
40: "chainedHandler is required");
41: }
42: this .chainedHandler = chainedHandler;
43: chainedHandler.setNextHandler(new ActualHandler());
44:
45: setSessionManager(sessionManager);
46: }
47:
48: @Override
49: public void handle(String target, HttpServletRequest request,
50: HttpServletResponse response, int dispatch)
51: throws IOException, ServletException {
52: setRequestedId(request, dispatch);
53: try {
54: chainedHandler.handle(target, request, response, dispatch);
55: } catch (ServletException e) {
56: throw (IOException) new IOException().initCause(e);
57: }
58: }
59:
60: protected void doHandle(String target, HttpServletRequest request,
61: HttpServletResponse response, int dispatch)
62: throws IOException, ServletException {
63: super .handle(target, request, response, dispatch);
64: }
65:
66: private class ActualHandler extends AbstractPreHandler {
67:
68: public void handle(String target, HttpServletRequest request,
69: HttpServletResponse response, int dispatch)
70: throws IOException, ServletException {
71: doHandle(target, request, response, dispatch);
72: }
73: }
74:
75: }
|