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 static final Logger LOGGER = LoggerFactory.getLogger(AbstractAuthLogicHandler.class);
42
43
44
45
46 protected ProxyRequest request;
47
48
49
50
51 protected ProxyIoSession proxyIoSession;
52
53
54
55
56 protected int step = 0;
57
58
59
60
61
62
63
64 protected AbstractAuthLogicHandler(final ProxyIoSession proxyIoSession) throws ProxyAuthException {
65 this.proxyIoSession = proxyIoSession;
66 this.request = proxyIoSession.getRequest();
67
68 if (this.request == null || !(this.request instanceof HttpProxyRequest)) {
69 throw new IllegalArgumentException("request parameter should be a non null HttpProxyRequest instance");
70 }
71 }
72
73
74
75
76
77
78
79 public abstract void doHandshake(final NextFilter nextFilter) throws ProxyAuthException;
80
81
82
83
84
85
86
87 public abstract void handleResponse(final HttpProxyResponse response) throws ProxyAuthException;
88
89
90
91
92
93
94
95
96 protected void writeRequest(final NextFilter nextFilter, final HttpProxyRequest request) throws ProxyAuthException {
97 if (LOGGER.isDebugEnabled()) {
98 LOGGER.debug(" sending HTTP request");
99 }
100
101 ((AbstractHttpLogicHandler) proxyIoSession.getHandler()).writeRequest(nextFilter, request);
102 }
103
104
105
106
107
108
109 public static void addKeepAliveHeaders(Map<String, List<String>> headers) {
110 StringUtilities.addValueToHeader(headers, "Keep-Alive", HttpProxyConstants.DEFAULT_KEEP_ALIVE_TIME, true);
111 StringUtilities.addValueToHeader(headers, "Proxy-Connection", "keep-Alive", true);
112 }
113
114 }