1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.channel.socket.http;
17
18 import org.jboss.netty.buffer.ChannelBufferFactory;
19 import org.jboss.netty.channel.ChannelConfig;
20 import org.jboss.netty.channel.ChannelPipelineFactory;
21 import org.jboss.netty.channel.socket.SocketChannel;
22 import org.jboss.netty.channel.socket.SocketChannelConfig;
23 import org.jboss.netty.util.internal.ConversionUtil;
24
25 import javax.net.ssl.SSLContext;
26 import javax.net.ssl.SSLEngine;
27 import javax.net.ssl.SSLSession;
28 import java.util.Map;
29 import java.util.Map.Entry;
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 public final class HttpTunnelingSocketChannelConfig implements SocketChannelConfig {
59
60 private final HttpTunnelingClientSocketChannel channel;
61 private volatile String serverName;
62 private volatile String serverPath = "/netty-tunnel";
63 private volatile SSLContext sslContext;
64 private volatile String[] enabledSslCipherSuites;
65 private volatile String[] enabledSslProtocols;
66 private volatile boolean enableSslSessionCreation = true;
67
68
69
70
71 HttpTunnelingSocketChannelConfig(HttpTunnelingClientSocketChannel channel) {
72 this.channel = channel;
73 }
74
75
76
77
78
79 public String getServerName() {
80 return serverName;
81 }
82
83
84
85
86
87 public void setServerName(String serverName) {
88 this.serverName = serverName;
89 }
90
91
92
93
94
95 public String getServerPath() {
96 return serverPath;
97 }
98
99
100
101
102
103 public void setServerPath(String serverPath) {
104 if (serverPath == null) {
105 throw new NullPointerException("serverPath");
106 }
107 this.serverPath = serverPath;
108 }
109
110
111
112
113
114 public SSLContext getSslContext() {
115 return sslContext;
116 }
117
118
119
120
121
122 public void setSslContext(SSLContext sslContext) {
123 this.sslContext = sslContext;
124 }
125
126
127
128
129
130
131
132 public String[] getEnabledSslCipherSuites() {
133 String[] suites = enabledSslCipherSuites;
134 if (suites == null) {
135 return null;
136 } else {
137 return suites.clone();
138 }
139 }
140
141
142
143
144
145
146
147 public void setEnabledSslCipherSuites(String[] suites) {
148 if (suites == null) {
149 enabledSslCipherSuites = null;
150 } else {
151 enabledSslCipherSuites = suites.clone();
152 }
153 }
154
155
156
157
158
159
160 public String[] getEnabledSslProtocols() {
161 String[] protocols = enabledSslProtocols;
162 if (protocols == null) {
163 return null;
164 } else {
165 return protocols.clone();
166 }
167 }
168
169
170
171
172
173
174 public void setEnabledSslProtocols(String[] protocols) {
175 if (protocols == null) {
176 enabledSslProtocols = null;
177 } else {
178 enabledSslProtocols = protocols.clone();
179 }
180 }
181
182
183
184
185
186
187
188 public boolean isEnableSslSessionCreation() {
189 return enableSslSessionCreation;
190 }
191
192
193
194
195
196
197
198 public void setEnableSslSessionCreation(boolean flag) {
199 enableSslSessionCreation = flag;
200 }
201
202 public void setOptions(Map<String, Object> options) {
203 for (Entry<String, Object> e: options.entrySet()) {
204 setOption(e.getKey(), e.getValue());
205 }
206 }
207
208 public boolean setOption(String key, Object value) {
209 if (channel.realChannel.getConfig().setOption(key, value)) {
210 return true;
211 }
212
213 if ("serverName".equals(key)) {
214 setServerName(String.valueOf(value));
215 } else if ("serverPath".equals(key)) {
216 setServerPath(String.valueOf(value));
217 } else if ("sslContext".equals(key)) {
218 setSslContext((SSLContext) value);
219 } else if ("enabledSslCipherSuites".equals(key)) {
220 setEnabledSslCipherSuites(ConversionUtil.toStringArray(value));
221 } else if ("enabledSslProtocols".equals(key)) {
222 setEnabledSslProtocols(ConversionUtil.toStringArray(value));
223 } else if ("enableSslSessionCreation".equals(key)) {
224 setEnableSslSessionCreation(ConversionUtil.toBoolean(value));
225 } else {
226 return false;
227 }
228
229 return true;
230 }
231
232 public int getReceiveBufferSize() {
233 return channel.realChannel.getConfig().getReceiveBufferSize();
234 }
235
236 public int getSendBufferSize() {
237 return channel.realChannel.getConfig().getSendBufferSize();
238 }
239
240 public int getSoLinger() {
241 return channel.realChannel.getConfig().getSoLinger();
242 }
243
244 public int getTrafficClass() {
245 return channel.realChannel.getConfig().getTrafficClass();
246 }
247
248 public boolean isKeepAlive() {
249 return channel.realChannel.getConfig().isKeepAlive();
250 }
251
252 public boolean isReuseAddress() {
253 return channel.realChannel.getConfig().isReuseAddress();
254 }
255
256 public boolean isTcpNoDelay() {
257 return channel.realChannel.getConfig().isTcpNoDelay();
258 }
259
260 public void setKeepAlive(boolean keepAlive) {
261 channel.realChannel.getConfig().setKeepAlive(keepAlive);
262 }
263
264 public void setPerformancePreferences(
265 int connectionTime, int latency, int bandwidth) {
266 channel.realChannel.getConfig().setPerformancePreferences(connectionTime, latency, bandwidth);
267 }
268
269 public void setReceiveBufferSize(int receiveBufferSize) {
270 channel.realChannel.getConfig().setReceiveBufferSize(receiveBufferSize);
271 }
272
273 public void setReuseAddress(boolean reuseAddress) {
274 channel.realChannel.getConfig().setReuseAddress(reuseAddress);
275 }
276
277 public void setSendBufferSize(int sendBufferSize) {
278 channel.realChannel.getConfig().setSendBufferSize(sendBufferSize);
279 }
280
281 public void setSoLinger(int soLinger) {
282 channel.realChannel.getConfig().setSoLinger(soLinger);
283 }
284
285 public void setTcpNoDelay(boolean tcpNoDelay) {
286 channel.realChannel.getConfig().setTcpNoDelay(tcpNoDelay);
287 }
288
289 public void setTrafficClass(int trafficClass) {
290 channel.realChannel.getConfig().setTrafficClass(trafficClass);
291 }
292
293 public ChannelBufferFactory getBufferFactory() {
294 return channel.realChannel.getConfig().getBufferFactory();
295 }
296
297 public int getConnectTimeoutMillis() {
298 return channel.realChannel.getConfig().getConnectTimeoutMillis();
299 }
300
301 public ChannelPipelineFactory getPipelineFactory() {
302 return channel.realChannel.getConfig().getPipelineFactory();
303 }
304
305 public void setBufferFactory(ChannelBufferFactory bufferFactory) {
306 channel.realChannel.getConfig().setBufferFactory(bufferFactory);
307 }
308
309 public void setConnectTimeoutMillis(int connectTimeoutMillis) {
310 channel.realChannel.getConfig().setConnectTimeoutMillis(connectTimeoutMillis);
311 }
312
313 public void setPipelineFactory(ChannelPipelineFactory pipelineFactory) {
314 channel.realChannel.getConfig().setPipelineFactory(pipelineFactory);
315 }
316 }