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.handlers.http;
21
22 import java.util.List;
23 import java.util.Map;
24
25 import org.apache.mina.core.filterchain.IoFilter.NextFilter;
26 import org.apache.mina.proxy.ProxyAuthException;
27 import org.apache.mina.proxy.handlers.ProxyRequest;
28 import org.apache.mina.proxy.session.ProxyIoSession;
29 import org.apache.mina.proxy.utils.StringUtilities;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33
34
35
36
37
38
39
40 public abstract class AbstractAuthLogicHandler {
41 private final static Logger logger = LoggerFactory
42 .getLogger(AbstractAuthLogicHandler.class);
43
44
45
46
47 protected ProxyRequest request;
48
49
50
51
52 protected ProxyIoSession proxyIoSession;
53
54
55
56
57 protected int step = 0;
58
59
60
61
62
63
64
65 protected AbstractAuthLogicHandler(final ProxyIoSession proxyIoSession)
66 throws ProxyAuthException {
67 this.proxyIoSession = proxyIoSession;
68 this.request = proxyIoSession.getRequest();
69
70 if (this.request == null || !(this.request instanceof HttpProxyRequest)) {
71 throw new IllegalArgumentException(
72 "request parameter should be a non null HttpProxyRequest instance");
73 }
74 }
75
76
77
78
79
80
81
82 public abstract void doHandshake(final NextFilter nextFilter)
83 throws ProxyAuthException;
84
85
86
87
88
89
90
91 public abstract void handleResponse(final HttpProxyResponse response)
92 throws ProxyAuthException;
93
94
95
96
97
98
99
100
101 protected void writeRequest(final NextFilter nextFilter,
102 final HttpProxyRequest request) throws ProxyAuthException {
103 logger.debug(" sending HTTP request");
104
105 ((AbstractHttpLogicHandler) proxyIoSession.getHandler()).writeRequest(
106 nextFilter, request);
107 }
108
109
110
111
112
113
114 public static void addKeepAliveHeaders(Map<String, List<String>> headers) {
115 StringUtilities.addValueToHeader(headers, "Keep-Alive",
116 HttpProxyConstants.DEFAULT_KEEP_ALIVE_TIME, true);
117 StringUtilities.addValueToHeader(headers, "Proxy-Connection",
118 "keep-Alive", true);
119 }
120
121 }