1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.proxy.session;
21
22 import java.net.InetSocketAddress;
23 import java.nio.charset.Charset;
24 import java.util.List;
25
26 import org.apache.mina.core.session.IoSession;
27 import org.apache.mina.proxy.ProxyConnector;
28 import org.apache.mina.proxy.ProxyLogicHandler;
29 import org.apache.mina.proxy.event.IoSessionEventQueue;
30 import org.apache.mina.proxy.filter.ProxyFilter;
31 import org.apache.mina.proxy.handlers.ProxyRequest;
32 import org.apache.mina.proxy.handlers.http.HttpAuthenticationMethods;
33 import org.apache.mina.proxy.handlers.http.HttpSmartProxyHandler;
34
35
36
37
38
39
40
41
42 public class ProxyIoSession {
43
44 public final static String PROXY_SESSION = ProxyConnector.class.getName()
45 + ".ProxySession";
46
47 private final static String DEFAULT_ENCODING = "ISO-8859-1";
48
49
50
51
52
53
54 private List<HttpAuthenticationMethods> preferedOrder;
55
56
57
58
59 private ProxyRequest request;
60
61
62
63
64 private ProxyLogicHandler handler;
65
66
67
68
69 private ProxyFilter proxyFilter;
70
71
72
73
74 private IoSession session;
75
76
77
78
79 private ProxyConnector connector;
80
81
82
83
84 private InetSocketAddress proxyAddress = null;
85
86
87
88
89
90
91 private boolean reconnectionNeeded = false;
92
93
94
95
96 private String charsetName;
97
98
99
100
101 private IoSessionEventQueue eventQueue = new IoSessionEventQueue(this);
102
103
104
105
106 private boolean authenticationFailed;
107
108
109
110
111
112
113
114 public ProxyIoSession(InetSocketAddress proxyAddress, ProxyRequest request) {
115 setProxyAddress(proxyAddress);
116 setRequest(request);
117 }
118
119
120
121
122 public IoSessionEventQueue getEventQueue() {
123 return eventQueue;
124 }
125
126
127
128
129
130
131
132 public List<HttpAuthenticationMethods> getPreferedOrder() {
133 return preferedOrder;
134 }
135
136
137
138
139
140
141 public void setPreferedOrder(List<HttpAuthenticationMethods> preferedOrder) {
142 this.preferedOrder = preferedOrder;
143 }
144
145
146
147
148 public ProxyLogicHandler getHandler() {
149 return handler;
150 }
151
152
153
154
155
156
157 public void setHandler(ProxyLogicHandler handler) {
158 this.handler = handler;
159 }
160
161
162
163
164 public ProxyFilter getProxyFilter() {
165 return proxyFilter;
166 }
167
168
169
170
171
172
173
174
175 public void setProxyFilter(ProxyFilter proxyFilter) {
176 this.proxyFilter = proxyFilter;
177 }
178
179
180
181
182 public ProxyRequest getRequest() {
183 return request;
184 }
185
186
187
188
189
190
191 private void setRequest(ProxyRequest request) {
192 if (request == null) {
193 throw new NullPointerException("request cannot be null");
194 }
195
196 this.request = request;
197 }
198
199
200
201
202 public IoSession getSession() {
203 return session;
204 }
205
206
207
208
209
210
211
212
213 public void setSession(IoSession session) {
214 this.session = session;
215 }
216
217
218
219
220 public ProxyConnector getConnector() {
221 return connector;
222 }
223
224
225
226
227
228
229
230
231 public void setConnector(ProxyConnector connector) {
232 this.connector = connector;
233 }
234
235
236
237
238 public InetSocketAddress getProxyAddress() {
239 return proxyAddress;
240 }
241
242
243
244
245
246
247 private void setProxyAddress(InetSocketAddress proxyAddress) {
248 if (proxyAddress == null) {
249 throw new IllegalArgumentException("proxyAddress object cannot be null");
250 }
251
252 this.proxyAddress = proxyAddress;
253 }
254
255
256
257
258
259 public boolean isReconnectionNeeded() {
260 return reconnectionNeeded;
261 }
262
263
264
265
266
267
268
269
270
271
272
273 public void setReconnectionNeeded(boolean reconnectionNeeded) {
274 this.reconnectionNeeded = reconnectionNeeded;
275 }
276
277
278
279
280 public Charset getCharset() {
281 return Charset.forName(getCharsetName());
282 }
283
284
285
286
287 public String getCharsetName() {
288 if (charsetName == null) {
289 charsetName = DEFAULT_ENCODING;
290 }
291
292 return charsetName;
293 }
294
295
296
297
298
299
300 public void setCharsetName(String charsetName) {
301 this.charsetName = charsetName;
302 }
303
304
305
306
307 public boolean isAuthenticationFailed() {
308 return authenticationFailed;
309 }
310
311
312
313
314
315
316 public void setAuthenticationFailed(boolean authenticationFailed) {
317 this.authenticationFailed = authenticationFailed;
318 }
319 }