1 package org.eclipse.jetty.server.handler;
2
3 import java.io.IOException;
4
5 import javax.servlet.ServletException;
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8
9 import org.eclipse.jetty.server.Request;
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 public abstract class ScopedHandler extends HandlerWrapper
79 {
80 private static ThreadLocal<ScopedHandler> __outerScope= new ThreadLocal<ScopedHandler>();
81 protected ScopedHandler _outerScope;
82 protected ScopedHandler _nextScope;
83
84
85
86
87
88 @Override
89 protected void doStart() throws Exception
90 {
91 try
92 {
93 _outerScope=__outerScope.get();
94 if (_outerScope==null)
95 __outerScope.set(this);
96
97 super.doStart();
98
99 _nextScope= (ScopedHandler)getChildHandlerByClass(ScopedHandler.class);
100
101 }
102 finally
103 {
104 if (_outerScope==null)
105 __outerScope.set(null);
106 }
107 }
108
109
110
111
112
113 public final void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
114 {
115 if (_outerScope==null)
116 doScope(target,baseRequest,request, response);
117 else
118 doHandle(target,baseRequest,request, response);
119 }
120
121
122
123
124
125 public abstract void doScope(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
126 throws IOException, ServletException;
127
128
129
130
131
132 public final void nextScope(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
133 throws IOException, ServletException
134 {
135 if (_nextScope!=null)
136 _nextScope.doScope(target,baseRequest,request, response);
137 else if (_outerScope!=null)
138 _outerScope.doHandle(target,baseRequest,request, response);
139 else
140 doHandle(target,baseRequest,request, response);
141 }
142
143
144
145
146
147 public abstract void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
148 throws IOException, ServletException;
149
150
151
152
153
154 public final void nextHandle(String target, final Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
155 {
156 if (_nextScope!=null && _nextScope==_handler)
157 _nextScope.doHandle(target,baseRequest,request, response);
158 else if (_handler!=null)
159 _handler.handle(target,baseRequest, request, response);
160 }
161
162 }